Code: Select all
n=1
q=n/3
Debug Pow(10,q) ; 1.0
Debug Pow(10,(n/3)) ; 2.1544346900318838
Code: Select all
n=1
q=n/3
Debug Pow(10,q) ; 1.0
Debug Pow(10,(n/3)) ; 2.1544346900318838
Because the compiler will promote the expression in the second one to a float or double you will get 10^0.3333.... You have already performed the n/3 calculation and stored it in the long variable in the first case and x^0=1.Mistrel wrote:I don't understand this at all.
Code: Select all
n=1 q=n/3 Debug Pow(10,q) ; 1.0 Debug Pow(10,(n/3)) ; 2.1544346900318838
I get:n=1
q.f=n/3
Debug Pow(10,q) ; 1.0
Debug Pow(10,(n/3)) ; 2.1544346900318838
Is it simply truncated in q.f or ???2.1544347393126988
2.1544346900318838
Code: Select all
n=1
q.d=n/3
debug q
Debug Pow(10,q) ; 2.1544346900318838
Debug Pow(10,(n/3)) ; 2.1544346900318838
Code: Select all
n=1
q.d=n/3
Debug q
Debug Pow(10,q) ; 1.0
Debug Pow(10,(n/3)) ; 2.1544346900318838
Prof.Kahan wrote:13 Prevalent Misconceptions about Floating-Point Arithmetic :
1• Floating–point numbers are all at least slightly uncertain.
2• In floating–point arithmetic, every number is a “ Stand–In ” for all numbers that differ from it in
digits beyond the last digit stored, so “ 3 ” and “ 3.0 E0 ” and “ 3.0 D0 ” are all slightly different.
3• Arithmetic much more precise than the data it operates upon is needless, and wasteful.
4• In floating–point arithmetic nothing is ever exactly 0 ; but if it is, no useful purpose is served by
distinguishing +0 from -0 . ( We have already seen on pp. 13 - 15 why this might be wrong.)
5• Subtractive cancellation always causes numerical inaccuracy, or is the only cause of it.
6• A singularity always degrades accuracy when data approach it, so “ Ill–Conditioned ” data or problems
deserve inaccurate results.
7• Classical formulas taught in school and found in handbooks and software must have passed the
Test of Time, not merely withstood it.
8• Progress is inevitable: When better formulas are found, they supplant the worse.
9• Modern “ Backward Error-Analysis ” explains all error, or excuses it.
10• Algorithms known to be “ Numerically Unstable ” should never be used.
11• Bad results are the fault of bad data or bad programmers, never bad programming language design.
12• Most features of IEEE Floating-Point Standard 754 are too arcane to matter to most programmers.
13• “ ‘ Beauty is truth, truth beauty.’ — that is all ye know on earth, and all ye need to know.” ... from
Keats’ Ode on a Grecian Urn . ( In other words, you needn’t sweat over ugly details.)