Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the next normalised floating point number after(before) a normalised floating point number f?

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 ? 
like image 956
pgast Avatar asked Aug 26 '09 18:08

pgast


People also ask

What is normalized floating-point number?

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.

How are floating-point numbers calculated?

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.

How many float numbers are there?

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.


1 Answers

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.

like image 80
Robert Kern Avatar answered Nov 03 '22 00:11

Robert Kern