JavaScript Math与Excel [英] JavaScript Math vs Excel

查看:91
本文介绍了JavaScript Math与Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在为自行车车轮制造商编写一个网络应用程序

来计算各种各样的集线器的轮辐长度

和轮辋。


我已经从Excel电子表格和

JavaScript中翻译了公式,它看起来像这样: />

var sll = Math.sqrt(Math.pow(((fdl / 2 * Math.sin((2 * Math.PI * cross)))/

(辐条/ 2)),2)+ Math.pow((erd / 2 - ((fdl / 2)* Math.cos(2 * Math.PI * cross /

(辐条/ 2)))),2)+ Math.pow((c2l + osb),2)-shd / 2);


问题是我得到的结果略有不同使用

JavaScript比使用Open Office Calc时。它不是很多,不到几百毫米,这对你建造一个

车轮来说并不重要,但它让我有点担心。 br />

我的问题是,JavaScript Math对象可能不像Excel或OpenOffice那样强大,而且只有轻微的

舍入导致这种差异的错误?或者重新解释

问题,我可以一遍又一遍地检查公式吗

错误?


谢谢

Lenni

解决方案

Lenni -


非常有趣的项目。我喜欢数学而且我是一名工程师...你确定

你的algorythm是准确的吗?您在该公式中使用的变量的详细描述以及您如何得出计算的每一步

将是您可能希望获得第二意见的内容?我不是一个

中心专家......但是轮辐的轴向旋转量,轮毂宽度,以及到轴中心线的距离肯定是感兴趣的变量。 Rim

直径和偏移量也需要考虑。


当你将一个值提升到一个幂...时,通常会有大量的/>
灵敏度,精度为指数。而且你经常在你的

公式中这样做。我建议在电子表格中打印出15位以上的数字,以确定其精度,并在其他程序中执行相同操作。

将最精确的精确度限制在最低精度之前你

获得完全匹配。在高性能的b $ b性能情况下,不能接受一毫米。


将您的公式分解为多个分组,并在每个一对一的比较中进行比较/>
每个平台......而不仅仅是查看最终结果。一个真正的错误

分析并不是一项简单的任务。


我刚学习JavaScript,但我已经做了很多C和C ++
编程,其中精度非常重要,任何差异都要完全探索



深入挖掘是我的建议。我希望我能够很好地了解JavaScript,因为
会更有帮助。祝你好运!


- tom


Lenni< Le ****** @ googlemail.com写新闻:834f2e95-9331 -46a5-a2c4-
43**********@b1g2000hsg.googlegroups .com





我正在为自行车车轮制造商编写一个Web应用程序

计算各种轮毂变化的轮辐长度

和轮辋。


我已经翻译了公式Excel电子表格和

JavaScript看起来像这样:


var sll = Math.sqrt(Math.pow(((fdl / 2 * Math.sin) ((2 * Math.PI * cross)))/

(辐条/ 2)),2)+ Math.pow((erd / 2 - ((fdl / 2)* Math.cos (2 * Math.PI * cross /

(辐条/ 2)))),2)+ Math.pow((c2l + osb),2)-shd / 2);


问题是当我使用

JavaScript时比使用Open Office Calc时得到的结果略有不同。它不是很多,不到几百毫米,这对你建造一个

车轮来说并不重要,但它让我有点担心。 br />

我的问题是,JavaScript Math对象可能不像Excel或OpenOffice那样强大,而且只有轻微的

舍入导致这种差异的错误?或者重新解释

问题,我可以一遍又一遍地检查公式吗

错误?


谢谢

Lenni


Le 10/26/08 10:04 PM,Lenniaécrit:
< JavaScript中的blockquote class =post_quotes>
>

看起来像这样:


var sll = Math.sqrt(Math.pow (((fdl / 2 * Math.sin((2 * Math.PI * cross)))/

(辐条/ 2)),2)+ Math.pow((错误/ 2-) ((fdl / 2)* Math.cos(2 * Math.PI * cross /

(辐条/ 2)))),2)+ Math.pow((c2l + osb),2 )-shd / 2);


问题是当我使用

JavaScript时比使用Open Office Calc时得到的结果略有不同。它不是很多,不到每毫米b $ b bb,这对你建造一个

车轮来说并不重要,但这让我有点担心。



Javascript计算基数64(我认为,或类似的东西)和

有时它不能给出确切数字这样的数字as:

1.0000000009

而不是1


您可以尝试使用变量乘以1000或100000

并最终得到结果的圆度除以相同的

系数


也许这可行?

-

sm


SAM< st *************** ******@wanadoo.fr.invalidwrite s:


Javascript计算基数64(我想,或类似的东西)



这是完全废话。 ecmascript规范很清楚JS

数字是如何表示的:IEEE 754浮点数。它还声明所有

数值运算都符合IEEE 754规则。大多数语言

没有明确的规则在实践中遵循这些(因为大多数CPU

)。


有时它不能给出确切的数字,如:1.0000000009

而不是1



任何语言都在浮动二进制计算将在某些情况下(b)常见的情况下进行。浮点的二进制表示不能

表示十进制表示的所有数字。


参见 http://docs.sun.com/source/806-3568/ncg_goldberg.html


-

Joost Diepenmaat |博客: http://joost.zeekat.nl/ |工作: http://zeekat.nl/

Hi,

I''m currently writing a web application for bicycle wheel builders
that calculate the spoke length for all sorts of variations of hubs
and rims.

I have translated the formula from an Excel spreadsheet and in
JavaScript it looks like this:

var sll=Math.sqrt(Math.pow(((fdl/2*Math.sin((2*Math.PI*cross)))/
(spokes/2)),2)+Math.pow((erd/2-((fdl/2)*Math.cos(2*Math.PI*cross/
(spokes/2)))),2)+Math.pow((c2l+osb),2)-shd/2);

The problem is that I get slightly different results when I use
JavaScript than when I use Open Office Calc. It isn''t much, less than
a millimeter, which shouldn''t really matter when you''re building a
wheel but it is slightly worrying me.

My question, is it possible that the JavaScript Math object is not as
powerful as the Excel or OpenOffice one and that there are just slight
rounding errors that are causing this disparity? Or to rephrase the
question, can I stop checking the formula over and over again for
errors?

Thanks
Lenni

解决方案

Lenni --

Very interesting project. I love math and am an engineer ... are you sure
your algorythm is accurate? A detailed description of the variables you
use within that formula and how you derived each step of the calculation
would be something you might want to get a second opinion on? I am not a
hub expert ... but the amount a spoke rotates axially, the hub width, and
the distance to axle centerline are certainly variables of interest. Rim
diameter and offset need to be considered too.

When you raise a value to a power ... there is usually a great amount of
sensitivety with precision of the exponent. And you do this often in your
formula. I suggest printing out 15+ digits within your spreadsheet to
determine its precision and doing the same within other programs.
Restrict the most precise to the accuracy of the least precise until you
get an exact match. Off by a millimeter is not acceptable in high
performance situations.

Break up your formula into many groupings and compare each one-to-one on
each platform ... instead of just looking at the end result. A true error
analysis is not a trivial task.

I am just now learning JavaScript, but I have done a lot of C and C++
programming where precision was very important and any discreptancy had
to be explored fully.

Dig in deeper is my suggestion. I wish I knew JavaScript well enough to
be more helpful. Good luck!

-- tom

Lenni <Le******@googlemail.comwrote in news:834f2e95-9331-46a5-a2c4-
43**********@b1g2000hsg.googlegroups.com:

Hi,

I''m currently writing a web application for bicycle wheel builders
that calculate the spoke length for all sorts of variations of hubs
and rims.

I have translated the formula from an Excel spreadsheet and in
JavaScript it looks like this:

var sll=Math.sqrt(Math.pow(((fdl/2*Math.sin((2*Math.PI*cross)))/
(spokes/2)),2)+Math.pow((erd/2-((fdl/2)*Math.cos(2*Math.PI*cross/
(spokes/2)))),2)+Math.pow((c2l+osb),2)-shd/2);

The problem is that I get slightly different results when I use
JavaScript than when I use Open Office Calc. It isn''t much, less than
a millimeter, which shouldn''t really matter when you''re building a
wheel but it is slightly worrying me.

My question, is it possible that the JavaScript Math object is not as
powerful as the Excel or OpenOffice one and that there are just slight
rounding errors that are causing this disparity? Or to rephrase the
question, can I stop checking the formula over and over again for
errors?

Thanks
Lenni


Le 10/26/08 10:04 PM, Lenni a écrit :

>
in JavaScript it looks like this:

var sll=Math.sqrt(Math.pow(((fdl/2*Math.sin((2*Math.PI*cross)))/
(spokes/2)),2)+Math.pow((erd/2-((fdl/2)*Math.cos(2*Math.PI*cross/
(spokes/2)))),2)+Math.pow((c2l+osb),2)-shd/2);

The problem is that I get slightly different results when I use
JavaScript than when I use Open Office Calc. It isn''t much, less than
a millimeter, which shouldn''t really matter when you''re building a
wheel but it is slightly worrying me.

Javascript calculate on base 64 (I think, or something like that) and
sometimes it can''t give the exactly number such as :
1.0000000009
instead of 1

You could try by using your variables multiplied by 1000 or 100000
and finally get back the roundness of the result divided by the same
coefficient

Perhaps that could work ?

--
sm


SAM <st*********************@wanadoo.fr.invalidwrite s:

Javascript calculate on base 64 (I think, or something like that)

That is complete crap. The ecmascript specs are quite clear about how JS
numbers are represented: as IEEE 754 floats. It also states that all
numeric operations are according to the IEEE 754 rules. Most languages
that don''t have explicit rules follow these in practice (since most CPUs
do).

and sometimes it can''t give the exactly number such as : 1.0000000009
instead of 1

And any language doing floating binary calculations will, under certain
(common) circumstances. Binary representation of floating points can not
represent all numbers exactly that decimal representation can.

See http://docs.sun.com/source/806-3568/ncg_goldberg.html

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


这篇关于JavaScript Math与Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆