Topic: 关于平方的问题!

  Print this page

1.关于平方的问题! Copy to clipboard
Posted by: wsfree
Posted on: 2006-09-17 22:13

需要求直线(10,10)-(100000,200000)的距离,用
Math.sqrt((100000-10)*(100000-10)+(200000-10)*(200000-10)),但
输出一直不正确(在Excel中验算),请问能用什么办法解决?

2.Re:关于平方的问题! [Re: wsfree] Copy to clipboard
Posted by: why
Posted on: 2006-09-17 22:25

Tell us what's wrong (the values).

Show us your code.

Thanks.

 
(100000-10)*(100000-10)+(200000-10)*(200000-10) may be a negative integer if it overflows, use double values!
Math.sqrt((100000.0-10.0)*(100000.0-10.0)+(200000.0-10.0)*(200000.0-10.0));

這句"输出一直不正确(在Excel中验算)"實在不知所謂
Math.sqrt({negative value})回一個NaN(Not a Number),閣下驗算甚麼呢?

3.Re:关于平方的问题! [Re: wsfree] Copy to clipboard
Posted by: wsfree
Posted on: 2006-09-18 07:43

我想问的是:
对于Math.sqrt的溢出应如何解决?

4.Re:关于平方的问题! [Re: wsfree] Copy to clipboard
Posted by: why
Posted on: 2006-09-18 09:34

wsfree wrote:
我想问的是:
对于Math.sqrt的溢出应如何解决?

溢出?
甚麼溢出?
哪有溢出? 溢出的是那些int 或 long,

make sure that the input argument is not negative!
sqrt(-1) is the complex number 0 + 1i

as I wrote above, use double values!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923