Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
why c = 5.99999999999998E-02
Note: Excel XP SP Sub test( Dim a As Doubl Dim b As Doubl Dim c As Doubl a = 1.4 b = 1.3 c = a - Debug.Print End Su |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Because of this:
Any value less than the result from this program is read as zero on your machine. Machine Epsilon. Double precision used in this program Sub MachineEpsilon() Dim g, ex, eps As Double Dim i As Long g = 1 i = 0 Do i = i + 1 g = g / 2 ex = g * 0.98 + 1 ex = ex - 1 If ex 0 Then eps = ex Loop While ex 0 MsgBox ("No. of Iterations " & i) MsgBox ("Machine Epsilon is " & eps) End Sub -----Original Message----- tennin, Floating point calculations are not guarenteed to give answer you may expect. Depending on your needs, either Format the answer or c=(CLng(a*100)-CLng(b*100)) /100 NickHK "Tennin" wrote in message ... why c = 5.99999999999998E-02 ? Note: Excel XP SP3 Sub test() Dim a As Double Dim b As Double Dim c As Double a = 1.42 b = 1.36 c = a - b Debug.Print c End Sub . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Kenny...I gave a program like this an attempt in the past, but had no
luck. Thanks for the code. :) Looks like one could change this line of code and get the same results: ex = g * 0.999 + 1 Even this worked ok. ex = g * 1 + 1 The result I get is: Machine Epsilon is 2.22044604925031E-16 Which I think is the value of the last bit (Excel works with 15) =2^(-52) 2.22044604925031E-16 Which agrees with mma on my system: :) $MachineEpsilon 2.220446049250313*^-16 Any value less than the result from this program is read as zero on your machine. Machine Epsilon. I am not an expert, but do you think it would be more correct to say that Excel can store and work with numbers less than this. For example =3*1.1E-20 is ok. It is only during certain math operations that such a small number is treated as zero. It is so confusing! :) Just to share an idea, here is mma's definition ?$MachineEpsilon $MachineEpsilon gives the smallest machine-precision number which can be added to 1.0 to give a result that is distinguishable from 1.0 (They are careful to say 1.0, as 1.0 is a machine number.) Fun subject, but so confusing. :) -- Dana DeLouis Using Windows XP & Office XP = = = = = = = = = = = = = = = = = "Kenny" wrote in message ... Because of this: Any value less than the result from this program is read as zero on your machine. Machine Epsilon. Double precision used in this program Sub MachineEpsilon() Dim g, ex, eps As Double Dim i As Long g = 1 i = 0 Do i = i + 1 g = g / 2 ex = g * 0.98 + 1 ex = ex - 1 If ex 0 Then eps = ex Loop While ex 0 MsgBox ("No. of Iterations " & i) MsgBox ("Machine Epsilon is " & eps) End Sub -----Original Message----- tennin, Floating point calculations are not guarenteed to give answer you may expect. Depending on your needs, either Format the answer or c=(CLng(a*100)-CLng(b*100)) /100 NickHK "Tennin" wrote in message ... why c = 5.99999999999998E-02 ? Note: Excel XP SP3 Sub test() Dim a As Double Dim b As Double Dim c As Double a = 1.42 b = 1.36 c = a - b Debug.Print c End Sub . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
THe programme is only for Double Precision numbers. Using
numbers outside double precision range using something different. (I'm not an expert either, so I'm nt exactly sure what). But for VBA programming, you just have to be careful when using iterations with small numbers. You may possibly get unexpected errors when the code seems fine. see for examples http://www5.in.tum.de/~huckle/bugse.html -----Original Message----- Thanks Kenny...I gave a program like this an attempt in the past, but had no luck. Thanks for the code. :) Looks like one could change this line of code and get the same results: ex = g * 0.999 + 1 Even this worked ok. ex = g * 1 + 1 The result I get is: Machine Epsilon is 2.22044604925031E-16 Which I think is the value of the last bit (Excel works with 15) =2^(-52) 2.22044604925031E-16 Which agrees with mma on my system: :) $MachineEpsilon 2.220446049250313*^-16 Any value less than the result from this program is read as zero on your machine. Machine Epsilon. I am not an expert, but do you think it would be more correct to say that Excel can store and work with numbers less than this. For example =3*1.1E-20 is ok. It is only during certain math operations that such a small number is treated as zero. It is so confusing! :) Just to share an idea, here is mma's definition ?$MachineEpsilon $MachineEpsilon gives the smallest machine-precision number which can be added to 1.0 to give a result that is distinguishable from 1.0 (They are careful to say 1.0, as 1.0 is a machine number.) Fun subject, but so confusing. :) -- Dana DeLouis Using Windows XP & Office XP = = = = = = = = = = = = = = = = = "Kenny" wrote in message ... Because of this: Any value less than the result from this program is read as zero on your machine. Machine Epsilon. Double precision used in this program Sub MachineEpsilon() Dim g, ex, eps As Double Dim i As Long g = 1 i = 0 Do i = i + 1 g = g / 2 ex = g * 0.98 + 1 ex = ex - 1 If ex 0 Then eps = ex Loop While ex 0 MsgBox ("No. of Iterations " & i) MsgBox ("Machine Epsilon is " & eps) End Sub -----Original Message----- tennin, Floating point calculations are not guarenteed to give answer you may expect. Depending on your needs, either Format the answer or c=(CLng(a*100)-CLng(b*100)) /100 NickHK "Tennin" wrote in message news:32C116F6-3D80-4C60-B162- ... why c = 5.99999999999998E-02 ? Note: Excel XP SP3 Sub test() Dim a As Double Dim b As Double Dim c As Double a = 1.42 b = 1.36 c = a - b Debug.Print c End Sub . . |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
tennin,
Floating point calculations are not guarenteed to give answer you may expect. Depending on your needs, either Format the answer or c=(CLng(a*100)-CLng(b*100)) /100 NickHK "Tennin" wrote in message ... why c = 5.99999999999998E-02 ? Note: Excel XP SP3 Sub test() Dim a As Double Dim b As Double Dim c As Double a = 1.42 b = 1.36 c = a - b Debug.Print c End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|