The basic input form for floating-point numbers?

随声附和 提交于 2019-12-24 10:00:24

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4939616/the-basic-input-form-for-floating-point-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!