Output of file : FP16.C contained in archive : FP16.ZIP
//**************************************************************************
//
// Date: 10/22/92
// Name: Fp16.c
// Author: Michael J. Steiner
// CompuServe: [ 70304,3452 ]
//
// Description: Demonstrats the advantage in time, of using fixed point
// mathematics in place of floating point matematics. And
// the disadvantage of loss of precision.
//
// Note: Storage: Fraction
// Integer ³
// Sign ³ ³
// ³ ³ ³
// 0 ³ ³
// 000000000000000 ³
// 0000000000000000
//
//**************************************************************************

#include
#include

#define BITSHIFT 16 //significant to 4 places
#define BITS ( 1L << BITSHIFT ) //could use a constant here for
//greater speed

#define LONG2DBL( a ) (double)a / BITS //these two macros are the heart of
#define DBL2LONG( a ) (long)( a * BITS ) //the conversion double => integer

#define ADD( a, b ) LONG2DBL( ( DBL2LONG( a ) + DBL2LONG( b ) ) )
#define SUB( a, b ) LONG2DBL( ( DBL2LONG( a ) - DBL2LONG( b ) ) )
#define MUL( a, b ) LONG2DBL( ( ( DBL2LONG( a ) * \
DBL2LONG( b ) ) >> BITSHIFT ) )

#define DIV( a, b ) LONG2DBL( ( ( DBL2LONG( a ) / \
DBL2LONG( b ) ) << BITSHIFT ) )

extern long Add( long, long );
extern long Sub( long, long );

void main( void )
{
clock_t End, Start;
int x;
double inc;
double Value;
double Result0, Result1, Result2;
long INC,VALUE;

printf( "\n" );
printf( " Using the Macros\n" );
printf( " ----------------\n" );
printf( " (long) .11: %ld\n", DBL2LONG( .11 ) );
printf( " (long) .22: %ld\n", DBL2LONG( .22 ) );
printf( " .22 + .11: %2.4lf\n", ADD( .22, .11 ) );
printf( " .22 - .11: %2.4lf\n", SUB( .22, .11 ) );
printf( " .22 * .11: %2.4lf\n", MUL( .22, .11 ) );
printf( " .22 / .11: %2.4lf\n", DIV( .22, .11 ) );

inc = 1.11;
Value = 0.22;

INC = DBL2LONG( 1.11 );
VALUE = DBL2LONG( 0.22 );

Start = clock();

for( x=0; x<20000; x++ )
{
inc += Value;
inc -= Value;
}

End = clock();
AddTime1 = (double)( End - Start ) / CLK_TCK;

Start = clock();

for( x=0; x<20000; x++ )
{
INC += VALUE;
INC -= VALUE;
}

End = clock();
AddTime2 = (double)( End - Start ) / CLK_TCK;

printf( "\n" );
printf( " Timed Addition/Subtraction Test\n" );
printf( "ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n" );
printf( " FLOATING POINT ³ FIXED 16 POINT\n" );
printf( " ³\n" );
printf( " Total: %4.4lf ³ Total: %4.4lf\n", inc, LONG2DBL( INC ) );
printf( "Speed increase: %2.2f [%]\n", ( AddTime1 / AddTime2 ) * 100 );

}

### 3 Responses to “Category : Assembly Language Source CodeArchive   : FP16.ZIPFilename : FP16.C”

1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/