Skip to main content
added a link
Source Link
Leo B.
  • 20.7k
  • 5
  • 50
  • 157

You may want to look at the PARANOIA floating point test suite, which tests for quite a few characteristics of the floating point format and implementation (range, bits of precision, rounding, guard bits, etc.).

It is said that it was originally written in BASIC, but I could not find the BASIC version (EDIT: hat tip to @scruss, here it is). The C variant, as follows from the comments, is a rewrite of the Pascal version, which is a rewrite of the original BASIC version.

The coding style, though, is very easy to follow to re-convert back to BASIC. For example, the numerical radix of the f. p. representation is calculated as follows (note that literal constants are replaced with variables to inhibit optimization, but it should not be a problem in BASIC, you could write 1.0 instead of One, etc.):

printf ( "Searching for Radix and Precision.\n" );
W = One;

do {
    W = W + W;
    Y = W + One;
    Z = Y - W;
    Y = Z - One;
} while (MinusOne + FABS(Y) < Zero);

/*
  Now W is just big enough that |((W+1)-W)-1| >= 1.
*/
Precision = Zero;
Y = One;
do {
    Radix = W + Y;
    Y = Y + Y;
    Radix = Radix - W;
} while ( Radix == Zero);

if ( Radix < Two ) {
    Radix = One;
}

printf ( "Radix = %f\n", Radix );

In the pre-IEEE854 formats, radix was not necessarily 2. For example, it was 16 in the IBM floating point.

Other specific tests are equally short and lucid.

You may want to look at the PARANOIA floating point test suite, which tests for quite a few characteristics of the floating point format and implementation (range, bits of precision, rounding, guard bits, etc.).

It is said that it was originally written in BASIC, but I could not find the BASIC version. The C variant, as follows from the comments, is a rewrite of the Pascal version, which is a rewrite of the original BASIC version.

The coding style, though, is very easy to follow to re-convert back to BASIC. For example, the numerical radix of the f. p. representation is calculated as follows (note that literal constants are replaced with variables to inhibit optimization, but it should not be a problem in BASIC, you could write 1.0 instead of One, etc.):

printf ( "Searching for Radix and Precision.\n" );
W = One;

do {
    W = W + W;
    Y = W + One;
    Z = Y - W;
    Y = Z - One;
} while (MinusOne + FABS(Y) < Zero);

/*
  Now W is just big enough that |((W+1)-W)-1| >= 1.
*/
Precision = Zero;
Y = One;
do {
    Radix = W + Y;
    Y = Y + Y;
    Radix = Radix - W;
} while ( Radix == Zero);

if ( Radix < Two ) {
    Radix = One;
}

printf ( "Radix = %f\n", Radix );

In the pre-IEEE854 formats, radix was not necessarily 2. For example, it was 16 in the IBM floating point.

Other specific tests are equally short and lucid.

You may want to look at the PARANOIA floating point test suite, which tests for quite a few characteristics of the floating point format and implementation (range, bits of precision, rounding, guard bits, etc.).

It is said that it was originally written in BASIC, but I could not find the BASIC version (EDIT: hat tip to @scruss, here it is). The C variant, as follows from the comments, is a rewrite of the Pascal version, which is a rewrite of the original BASIC version.

The coding style, though, is very easy to follow to re-convert back to BASIC. For example, the numerical radix of the f. p. representation is calculated as follows (note that literal constants are replaced with variables to inhibit optimization, but it should not be a problem in BASIC, you could write 1.0 instead of One, etc.):

printf ( "Searching for Radix and Precision.\n" );
W = One;

do {
    W = W + W;
    Y = W + One;
    Z = Y - W;
    Y = Z - One;
} while (MinusOne + FABS(Y) < Zero);

/*
  Now W is just big enough that |((W+1)-W)-1| >= 1.
*/
Precision = Zero;
Y = One;
do {
    Radix = W + Y;
    Y = Y + Y;
    Radix = Radix - W;
} while ( Radix == Zero);

if ( Radix < Two ) {
    Radix = One;
}

printf ( "Radix = %f\n", Radix );

In the pre-IEEE854 formats, radix was not necessarily 2. For example, it was 16 in the IBM floating point.

Other specific tests are equally short and lucid.

Source Link
Leo B.
  • 20.7k
  • 5
  • 50
  • 157

You may want to look at the PARANOIA floating point test suite, which tests for quite a few characteristics of the floating point format and implementation (range, bits of precision, rounding, guard bits, etc.).

It is said that it was originally written in BASIC, but I could not find the BASIC version. The C variant, as follows from the comments, is a rewrite of the Pascal version, which is a rewrite of the original BASIC version.

The coding style, though, is very easy to follow to re-convert back to BASIC. For example, the numerical radix of the f. p. representation is calculated as follows (note that literal constants are replaced with variables to inhibit optimization, but it should not be a problem in BASIC, you could write 1.0 instead of One, etc.):

printf ( "Searching for Radix and Precision.\n" );
W = One;

do {
    W = W + W;
    Y = W + One;
    Z = Y - W;
    Y = Z - One;
} while (MinusOne + FABS(Y) < Zero);

/*
  Now W is just big enough that |((W+1)-W)-1| >= 1.
*/
Precision = Zero;
Y = One;
do {
    Radix = W + Y;
    Y = Y + Y;
    Radix = Radix - W;
} while ( Radix == Zero);

if ( Radix < Two ) {
    Radix = One;
}

printf ( "Radix = %f\n", Radix );

In the pre-IEEE854 formats, radix was not necessarily 2. For example, it was 16 in the IBM floating point.

Other specific tests are equally short and lucid.