浮点数的基本输入形式? [英] The basic input form for floating-point numbers?
问题描述
我刚刚发现了两种浮点数输入形式之间的根本区别:
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?
推荐答案
关于时间和内存消耗——这些是评估的结果,与不同的形式无关.当 10
显式存在时,您对 10
的幂使用整数算法,因此时间/内存效率低下.当我们从一开始就使用机器精度时,效果就消失了:
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
when 10
is present explicitly, thus the time/memory inefficiency. When we use machine precision from the start, the effect disappears:
In[1]:= MaxMemoryUsed[]
1.5*^-33432242 // Timing
MaxMemoryUsed[]
1.5*10.^-33432242 // Timing
MaxMemoryUsed[]
Out[1]= 17417696
Out[2]= {0., 1.500000000000000*10^-33432242}
Out[3]= 17417696
Out[4]= {0., 1.500000000043239*10^-33432242}
Out[5]= 17417696
HTH
这篇关于浮点数的基本输入形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!