Joe Wright wrote:
Arin Chaudhuri wrote:
Joe Wright wrote:
What is nextafterf()? I do see it declared in my math.h in a non-posix
and non-ansi context (djgpp gcc 3.0) but it doesn't seem to be in my
info system.
After removing the /*x you left around, the code did compile but with
the -Wall -ansi switches we see nextafterf not explicitly declared and
the program not 'working'.
I apologize for the trouble caused by the /*.
nextafterf is a part of the C99 standard library, please have a look at
section 7.12.11.3 of the standard. The prototype of nextafterf should be
defined in math.h, I have copypasted the relevant portion of the
standard at the end of the post.
I reasoned as follows (assuming the radix to be 2) :
If, b = b0.b1 b2 b3 ... bp x 2^{e}
is a positive normalized float value, (b0=1)
then the next normalized value that can be represented can be obtained
by adding
0. 0 0 0 ... 1 x 2^{e}= 1. 0 0 0 ... 2^{e-p} = 2^eFLT_EPSILON
to the above, i.e, we increment the last possible "digit".
Hence, for float values of the form, f x 2^{e} with 1<=f<2 the next
normalized number that can be represented is obtained by adding 2^e
FLT_EPSILON
This will not work when we enter the zone of denormalized numbers, (when
b0 is 0 and e is the smallest value possible).
****
7.12.11.3 The nextafter functions
Synopsis
1 #include <math.h>
double nextafter(double x, double y);
float nextafterf(float x, float y);
long double nextafterl(long double x, long double y);
Description
The nextafter functions determine the next representable value, in the
type of the function, after x in the direction of y, where x and y are
first converted to the type of the function. The nextafter functions
return y if x equals y. A range error may occur if the magnitude of x is
the largest finite value representable in the type and the result is
infinite or not representable in the type.
Returns
The nextafter functions return the next representable value in the
specified format after x in the direction of y.