Search
lxdream.org :: lxdream/test/testmath.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/testmath.c
changeset 192:580d6c4d7802
prev185:6755a04c447f
author nkeynes
date Fri May 29 18:47:05 2015 +1000 (8 years ago)
permissions -rw-r--r--
last change Fix test case
file annotate diff log raw
1.1 --- a/test/testmath.c Tue Jul 11 01:35:27 2006 +0000
1.2 +++ b/test/testmath.c Fri May 29 18:47:05 2015 +1000
1.3 @@ -17,16 +17,40 @@
1.4
1.5 #define MAX_FLOAT_DIFF 0.00001
1.6
1.7 +static inline float inttof( unsigned int i )
1.8 +{
1.9 + return *((float *)&i);
1.10 +}
1.11 +
1.12 +static inline double longtod( unsigned long long l )
1.13 +{
1.14 + return *((double *)&l);
1.15 +}
1.16 +
1.17 +static inline unsigned int ftoint( float f )
1.18 +{
1.19 + return *((unsigned int *)&f);
1.20 +}
1.21 +
1.22 +static inline unsigned long long dtolong( double d )
1.23 +{
1.24 + return *((unsigned long long *)&d);
1.25 +}
1.26 +
1.27 +#define QNANF inttof(0x7FBFFFFF)
1.28 +#define QNAND longtod(0x7FF7FFFFFFFFFFFFLL)
1.29
1.30 int compare_float( float a, float b )
1.31 {
1.32 - if( a == b )
1.33 + if( ftoint(a) == ftoint(b) ) /* Exact bit-pattern match */
1.34 return 1;
1.35 float diff = (a>b?(a-b):(b-a));
1.36 return diff < MAX_FLOAT_DIFF;
1.37 }
1.38
1.39 -#define TEST_FEQUALS( a, b ) if( !compare_float(a,b) ) { printf( "Assertion failed at %s.%d: expected %.8f but was %.8f\n", __FILE__, __LINE__, a, b ); return 1; }
1.40 +#define FTOINT(a) (*((unsigned int *)&a))
1.41 +
1.42 +#define TEST_FEQUALS( a, b ) if( !compare_float(a,b) ) { printf( "Assertion failed at %s.%d: expected %.8f (%08X) but was %.8f (%08X)\n", __FILE__, __LINE__, a, FTOINT(a), b, FTOINT(b) ); return 1; }
1.43
1.44 int test_fsca( int angle, float expect_a, float expect_b )
1.45 {
1.46 @@ -138,22 +162,23 @@
1.47
1.48 int main()
1.49 {
1.50 - write_int( get_fpscr() );
1.51 - write_string( "\n" );
1.52 - test_fsca( 0x00000000, 0, 1 );
1.53 - test_fsca( 0x00011234, 0.43205646, 0.90184659 );
1.54 - test_fsca( 0xFEDCBA98, -0.99121743, -0.13224234 );
1.55 - test_fsrra( 25.0, 0.2 );
1.56 - test_fsrra( 0.05, 4.4721361 );
1.57 - test_fsrra( -12.345, nanf() );
1.58 - test_coercion( -3.1415926 );
1.59 - test_coercion( 123456789012346567.890 );
1.60 - test_coercion( -2147483648.0 );
1.61 - test_coercion( 5234.1234 );
1.62 - test_doublearr( 5 );
1.63 - test_floatarr( 5 );
1.64 - test_fipr();
1.65 - test_ftrv();
1.66 - return 1;
1.67 + fprintf( stderr, "LL: %d\n", sizeof(unsigned long long) );
1.68 + write_int( get_fpscr() );
1.69 + write_string( "\n" );
1.70 + test_fsca( 0x00000000, 0, 1 );
1.71 + test_fsca( 0x00011234, 0.43205646, 0.90184659 );
1.72 + test_fsca( 0xFEDCBA98, -0.99121743, -0.13224234 );
1.73 + test_fsrra( 25.0, 0.2 );
1.74 + test_fsrra( 0.05, 4.4721361 );
1.75 + test_fsrra( -12.345, QNANF );
1.76 + test_coercion( -3.1415926 );
1.77 + test_coercion( 123456789012346567.890 );
1.78 + test_coercion( -2147483648.0 );
1.79 + test_coercion( 5234.1234 );
1.80 + test_doublearr( 5 );
1.81 + test_floatarr( 5 );
1.82 + test_fipr();
1.83 + test_ftrv();
1.84 + return 1;
1.85 }
1.86 -
1.87 +
.