Skip to content

Commit

Permalink
Version 0.1.1 - Added comparison function
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychoCod3r committed Oct 5, 2020
1 parent ae29e5c commit 2055cac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion dfloat.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************
* libdfloat, version 0.1 Alpha *
* libdfloat, version 0.1.1 Alpha *
* Description: Implements floating point numbers *
* with exact decimal representations *
* Current file: All libdfloat function definitions *
Expand Down Expand Up @@ -185,6 +185,26 @@ dfloatN_div( 16, 32 )
dfloatN_div( 32, 64 )
dfloatN_div( 64, 128 )

// Returns 1 if Arg1 > Arg2, -1 if Arg1 < Arg2, 0 if Arg1 == Arg2
#define dfloatN_cmp( small, big )\
int dfloat ## big ## _cmp( dfloat ## big ## _t *df1, dfloat ## big ## _t *df2 ){\
dfloat ## big ## _t *cpy;\
int result;\
cpy = (dfloat ## big ## _t *) malloc( sizeof( dfloat ## big ## _t ) );\
dfloat ## big ## _cpy( cpy, df1 );\
dfloat ## big ## _sub( cpy, df2 );\
if( cpy->mantissa > 0 )\
return 1;\
if( cpy->mantissa < 0 )\
return -1;\
return 0;\
}

dfloatN_cmp( 8, 16 )
dfloatN_cmp( 16, 32 )
dfloatN_cmp( 32, 64 )
dfloatN_cmp( 64, 128 )

// Reads a dfloat value from a string
#define dfloatN_atof( small, big )\
dfloat ## big ## _t *dfloat ## big ## _atof( char *src ){\
Expand Down
6 changes: 5 additions & 1 deletion dfloat.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************
* libdfloat, version 0.1 Alpha *
* libdfloat, version 0.1.1 Alpha *
* Description: Implements floating point numbers *
* with exact decimal representations *
* Current file: Header file for entire project *
Expand Down Expand Up @@ -38,6 +38,7 @@ void dfloat16_add( dfloat16_t *, dfloat16_t * );
void dfloat16_sub( dfloat16_t *, dfloat16_t * );
void dfloat16_mul( dfloat16_t *, dfloat16_t * );
void dfloat16_div( dfloat16_t *, dfloat16_t *, int );
int dfloat16_cmp( dfloat16_t *, dfloat16_t * );
void dfloat16_cpy( dfloat16_t *, dfloat16_t * );
dfloat32_t *dfloat16_cast32( dfloat16_t * );
dfloat64_t *dfloat16_cast64( dfloat16_t * );
Expand All @@ -48,6 +49,7 @@ void dfloat32_add( dfloat32_t *, dfloat32_t * );
void dfloat32_sub( dfloat32_t *, dfloat32_t * );
void dfloat32_mul( dfloat32_t *, dfloat32_t * );
void dfloat32_div( dfloat32_t *, dfloat32_t *, int );
int dfloat32_cmp( dfloat32_t *, dfloat32_t * );
void dfloat32_cpy( dfloat32_t *, dfloat32_t * );
dfloat16_t *dfloat32_cast16( dfloat32_t * );
dfloat64_t *dfloat32_cast64( dfloat32_t * );
Expand All @@ -58,6 +60,7 @@ void dfloat64_add( dfloat64_t *, dfloat64_t * );
void dfloat64_sub( dfloat64_t *, dfloat64_t * );
void dfloat64_mul( dfloat64_t *, dfloat64_t * );
void dfloat64_div( dfloat64_t *, dfloat64_t *, int );
int dfloat64_cmp( dfloat64_t *, dfloat64_t * );
void dfloat64_cpy( dfloat64_t *, dfloat64_t * );
dfloat16_t *dfloat64_cast16( dfloat64_t * );
dfloat32_t *dfloat64_cast32( dfloat64_t * );
Expand All @@ -68,6 +71,7 @@ void dfloat128_add( dfloat128_t *, dfloat128_t * );
void dfloat128_sub( dfloat128_t *, dfloat128_t * );
void dfloat128_mul( dfloat128_t *, dfloat128_t * );
void dfloat128_div( dfloat128_t *, dfloat128_t *, int );
int dfloat128_cmp( dfloat128_t *, dfloat128_t * );
void dfloat128_cpy( dfloat128_t *, dfloat128_t * );
dfloat16_t *dfloat128_cast16( dfloat128_t * );
dfloat32_t *dfloat128_cast32( dfloat128_t * );
Expand Down

0 comments on commit 2055cac

Please sign in to comment.