Determining the minimum representable increment/decrement possible?by BrowserUk (Pope)
|on Jun 15, 2016 at 14:14 UTC||Need Help??|
BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
Given an arbitrary floating point value (eg. 1.9041105342991877e+258 or -8.2727285363069939e-293) how can I determine the smallest representable value that can be added or subtracted from that FP value and cause it to actually change?
To demonstrate the problem:
So a restatement of the problem might be: Given 1.9041105342991877e+258 find the smallest number that can be both added to and subtracted from that number and will cause it to change value. Ie. 2.1337646185215534e+242
But the problem gets more interesting.
Now I try to work with the second value in the (eg.) above: -8.2727285363069939e-293
Please note: that number (-8.2727285363069939e-293) was output from a perl program. Though it is hard to reproduce, as there were random numbers involved.
My only explanation for why it comes out differently to what was entered is that -8.2727285363069939e-293 must be a "denormal number which can be produced as a result of calculations, and will be displayed, but when you initialise a variable with that value, it will normalise it; hence what comes out is different to what goes in.
All of which makes the problem I'm looking for a solution to -- that of finding the minimal representable change -- more complicated.
At this point someone is going to point me at this. Please don't, I've read it.
And someone is going to ask what is this for, which I could answer, but it would take us way off topic and doesn't change the posed problem.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.