Given a normalized floating point number f what is the next normalized floating point number after/before f.
With bit twiddling, extracting mantissa and exponent I have:
next_normalized(double&){
if mantissa is not all ones
maximally denormalize while maintaining equality
add 1 to mantissa
normalize
else
check overflow
set mantissa to 1
add (mantissa size in bits) to exponent.
endif
}
But rather than do that can it be done with floating point operations?
As
std::numeric_limits<double>::epsilon()
is only an error difference in a "neighborhood" of 1. - e.g.:
normalized(d+=std::numeric_limits<double>::epsilon()) = d for d large
it seems more an error ratio than an error difference, thus my naive intuition is
(1.+std::numeric_limits<double>::epsilon())*f //should be the next.
And
(1.-std::numeric_limits<double>::epsilon())*f //should be the previous.
In particular I have 3 questions has anyone done any of the following (for IEEE754):
1)done the error analysis on this issue?
2)proved (or can prove) that for any normalized double d
(1.+std::numeric_limits<double>::epsilon())*d != d ?
3)proved that for any normalized double number d no double f exists such that
d < f < (1.+std::numeric_limits<double>::epsilon())*d ?
A floating-point number is normalized if its mantissa is within the range defined by the following relation: 1/radix <= mantissa < 1. A normalized radix 10 floating-point number has its decimal point just to the left of the first non-zero digit in the mantissa.
To do so, floating-point uses a biased exponent, which is the original exponent plus a constant bias. 32-bit floating-point uses a bias of 127. For example, for the exponent 7, the biased exponent is 7 + 127 = 134 = 100001102. For the exponent −4, the biased exponent is: −4 + 127 = 123 = 011110112.
For any given value of the exponent, there are [latex] 2^{24} = 16777216[/latex] possible numbers that can be represented. However, the exponent decides how big that number will be. With a single bit reserved for sign of the exponent, 7 bits are available.
I’m not sure what you mean by “normalized double number”, but getting the next representable double number is done with the nextafter()
function in most C standard math libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With