浮点数的基本输入形式?
我刚刚发现浮点数的两种输入形式之间的根本区别:
In[8]:= 1.5*^-334355//Hold//FullForm
1.5*10^-334355//Hold//FullForm
Out[8]//FullForm= Hold[1.5000000000000000000000000000000001`15.954589770191005*^-334355]
Out[9]//FullForm= Hold[Times[1.5`,Power[10,-334355]]]
这两种形式在内存和时间消耗方面差异很大:
In[7]:= start = MaxMemoryUsed[];
1.5*^-33432242 // Timing
start = MaxMemoryUsed[] - start
1.5*10^-33432242 // Timing
MaxMemoryUsed[] - start
Out[8]= {1.67401*10^-16, 1.500000000000000*10^-33432242}
Out[9]= 0
Out[10]= {7.741, 1.500000000000000*10^-33432242}
Out[11]= 34274192
但我找不到形式 *^
的文档记录。它是真正的浮点数基本输入形式吗?其他基地的数字怎么样?
为什么第二种形式这么贵?
I just have discovered the fundamental difference between two input forms for floating-point numbers:
In[8]:= 1.5*^-334355//Hold//FullForm
1.5*10^-334355//Hold//FullForm
Out[8]//FullForm= Hold[1.5000000000000000000000000000000001`15.954589770191005*^-334355]
Out[9]//FullForm= Hold[Times[1.5`,Power[10,-334355]]]
These two forms differ very much in memory and time consumption:
In[7]:= start = MaxMemoryUsed[];
1.5*^-33432242 // Timing
start = MaxMemoryUsed[] - start
1.5*10^-33432242 // Timing
MaxMemoryUsed[] - start
Out[8]= {1.67401*10^-16, 1.500000000000000*10^-33432242}
Out[9]= 0
Out[10]= {7.741, 1.500000000000000*10^-33432242}
Out[11]= 34274192
But I cannot find out where the form *^
is documented. Is it a real basic input form for floating-point numbers? How is about numbers in other bases?
And why the second form is so much expensive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于时间和内存消耗 - 这些是评估的结果,与不同的形式无关。当显式存在
10
时,您可以使用整数算术来计算10
的幂,从而导致时间/内存效率低下。当我们从一开始就使用机器精度时,效果就会消失:HTH
Regarding the time and memory consumption - these are the consequences of evaluation, have nothing to do with different forms. You use integer arithmetic for the power of
10
when10
is present explicitly, thus the time/memory inefficiency. When we use machine precision from the start, the effect disappears:HTH