Re: Phix, numbers, printf, log10

new topic     » goto parent     » topic index » view thread      » older message » newer message

I briefly glanced at this last night, decided I needed to sleep on it, it didn't help.
Historically these sort of printf() issues have required fairly lengthy debug sessions...
The 0.5 rounding does seem to disagree with the docs and explicit use of round()/bankers_rounding(),
I think I should probably start with that before the first three. (see #3)

But I think the logarithm thing is the first thing to get out the way.
A debug session to remind myself precisely what %e does is probably in order...
Though I'm not getting the same results: I get 3 for all three, on 64 and 32 bit.
I get the expected results (323) for +/-1e12 on 64 bit and +/-1e11 on both 32 and 64bit...
In particular, I am not getting "2 badly wrong" under any circumstances.... So:

? {11,log10(1000 - 1e-11)-3,log10(1000 + 1e-11)-3} 
? {12,log10(1000 - 1e-12)-3,log10(1000 + 1e-12)-3} 
? {13,log10(1000 - 1e-13)-3,log10(1000 + 1e-13)-3} 
? {14,log10(1000 - 1e-14)-3,log10(1000 + 1e-14)-3} 
? {15,log10(1000 - 1e-15)-3,log10(1000 + 1e-15)-3} 
? {16,log10(1000 - 1e-16)-3,log10(1000 + 1e-16)-3} 
--64-bit: 
--{11,-4.035400486e-15,4.650576799e-15} 
--{12,-1.268516541e-16,7.418111264e-16} 
--{13,2.641116492e-16,3.510646634e-16} 
--{14,3.031429274e-16,3.118165449e-16} 
--{15,3.070460552e-16,3.07913417e-16} 
--{16,3.072628957e-16,3.074797361e-16} 
--32-bit: 
--{11,-3.996802889e-15,4.884981309e-15} 
--{12,0,4.440892099e-16} 
--{13,0,0} 
--{14,0,0} 
--{15,0,0} 
--{16,0,0} 
-- ie only getting a different SIGN at the +/- 1e11/12 mark. 

One thing I will say is that logarithms are inherently an approximation, and I have found a few
posts that confirm my initial suspicion that a test against power(10,res) is needed to be sure.

PS Can you explain what you are using the magnitude for? Exact may not match what %e delivers.
(for instance that willmay start printing "9.99999999" then round up to 1.0 and bump the exponent)
Do you need the magnitude of negative numbers? Is 0.01 ==> -2 ok/wanted?
What are the largest(/smallest) numbers you need a magnitude for?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu