几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 三维空间:产品设计或CAX软件使用 » CAD设计 » 产品功能分析
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-09-16, 07:02 PM   #1
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 warning1 excel order of operations problem

warning! excel order of operations problem...
the order of operations that excel uses in its formulas is incorrect for numbers raised to a power with a negative sign in front. examples:
excel: -5^2 = 25, but it should equal -25.
what's funny is when you type it like this:
-5^2 + 5^2 --> excel outputs 50 when it should be 0.
common sense tells you that it should be the same as:
5^2 - 5^2 which obviously equals 0 and excel agrees, here.
i discovered this problem with excel when creating a large spreadsheet and it took me two hours to find out why my formulas weren't working. microsoft even admits that it did it on purpose in its knowledge base.
my advice: use parentheses like it's going out of style!
check out our whitepaper library.
hmm..i guess i always understood excel's order was that they first did the power function and then the * and / functions and then the + and - last.
so -5^2 should be 5 x 5 first....then the negative = -25, which is what you asserted. perhaps the "naked" negative in front of a number is explicitly attached to the number in excels twisted logic.
i believe what it was is that most folks, when typing that negative, mean for the whole thing to be negative. i guess microsoft thought they'd help out by subverting the order of operations.
from a computer programming perspective, i think it's clear that this had to be intentional. setting the order of operations would hold place in the program no matter where the negative was. in the example i gave, it clearly changes when the problem is reordered.
never ever trust order of operations. ever.
also (in reference to another thread) don't try to use arithmetic operators for boolean operations.
hg
p.s. if i were using pencil & paper, -5^2 would indeed be 25. but i couldn't see programming that special into excel...
this is a subtle point, and the advice about using parentheses to make things unabiguously clear is excellent advice.
the subtlety is that the symbol "-" has two possible meanings in mathematics: one as the subtractionfff"> operator, and the other as the negationfff"> operator (aka the "unary minus"). excel's help system, in an item titled "about calculation operators", quite clearly states that negation operations are evaluated first, before even percent operations and exponentiation operations.
unfortunately, it does not explain how excel determines whether the "-" symbol will be interpreted as denoting subtraction or negation. commencing a formula with "-" is a dangerous move in any computer language.
enter =0-5^2 and note the difference.
thus my term "naked" negative sign...nothing in front of it.
also reminds me of a line from donald sutherland in "kelly's heroes" : quit givin' me all those negative waves, man!
mathematically speaking, -5^2 = -25 as a consensus worldwide. the accepted order of operations has you perform the power first. re
a negative number times a negative number should be positive.
-5^2 is 25... as we were taught you might want to include the (-5^2) to prevent confusion... programming languages, basic, c, c++, delphi, fortran, etc. treat a negative number squared as being positive.
dik
dik
as it turns out, (-5^2) = -25 as well when following the order of operations. i think you're referring to (-5)^2, which does indeed equal 25.
again, if you check the mathematics sites, you'll find that a negative is treated as multiplying by (-1) which means it falls in line where multiplication would after powers. to illustrate:
-5^2 = (-1)x5^2 = -25
(-5)^2 = ((-1)x5)^2 = 25
thank you for pointing this out swearingeng. i was unaware of it.
these links explain what is going on:
so why do various online references list "exponentiation" first, leaving out all the stuff above it in the list (negation, percentage, etc.)?
hg
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
second-order analysis huangyhg 产品功能分析 0 2009-09-15 08:24 PM
【转帖】哪位高手指点一下下边lisp的怎么用 yang686526 数据库ObjectDBX 0 2009-04-28 12:13 PM
哪位高手指点一下下边lisp的怎么用 yang686526 ObjectARX(AutoLISP) 0 2009-04-26 06:19 PM
【转帖】在autocad中利用excel实现结构设计的参数化绘图 yang686526 数据库ObjectDBX 0 2009-04-19 06:18 PM
【转帖】excel question yang686526 SolidWorks二次开发 0 2009-04-12 08:52 PM


所有的时间均为北京时间。 现在的时间是 10:55 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多