Skip to content

Commit 2055cac

Browse files
authored
Version 0.1.1 - Added comparison function
1 parent ae29e5c commit 2055cac

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

dfloat.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************
2-
* libdfloat, version 0.1 Alpha *
2+
* libdfloat, version 0.1.1 Alpha *
33
* Description: Implements floating point numbers *
44
* with exact decimal representations *
55
* Current file: All libdfloat function definitions *
@@ -185,6 +185,26 @@ dfloatN_div( 16, 32 )
185185
dfloatN_div( 32, 64 )
186186
dfloatN_div( 64, 128 )
187187

188+
// Returns 1 if Arg1 > Arg2, -1 if Arg1 < Arg2, 0 if Arg1 == Arg2
189+
#define dfloatN_cmp( small, big )\
190+
int dfloat ## big ## _cmp( dfloat ## big ## _t *df1, dfloat ## big ## _t *df2 ){\
191+
dfloat ## big ## _t *cpy;\
192+
int result;\
193+
cpy = (dfloat ## big ## _t *) malloc( sizeof( dfloat ## big ## _t ) );\
194+
dfloat ## big ## _cpy( cpy, df1 );\
195+
dfloat ## big ## _sub( cpy, df2 );\
196+
if( cpy->mantissa > 0 )\
197+
return 1;\
198+
if( cpy->mantissa < 0 )\
199+
return -1;\
200+
return 0;\
201+
}
202+
203+
dfloatN_cmp( 8, 16 )
204+
dfloatN_cmp( 16, 32 )
205+
dfloatN_cmp( 32, 64 )
206+
dfloatN_cmp( 64, 128 )
207+
188208
// Reads a dfloat value from a string
189209
#define dfloatN_atof( small, big )\
190210
dfloat ## big ## _t *dfloat ## big ## _atof( char *src ){\

dfloat.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************
2-
* libdfloat, version 0.1 Alpha *
2+
* libdfloat, version 0.1.1 Alpha *
33
* Description: Implements floating point numbers *
44
* with exact decimal representations *
55
* Current file: Header file for entire project *
@@ -38,6 +38,7 @@ void dfloat16_add( dfloat16_t *, dfloat16_t * );
3838
void dfloat16_sub( dfloat16_t *, dfloat16_t * );
3939
void dfloat16_mul( dfloat16_t *, dfloat16_t * );
4040
void dfloat16_div( dfloat16_t *, dfloat16_t *, int );
41+
int dfloat16_cmp( dfloat16_t *, dfloat16_t * );
4142
void dfloat16_cpy( dfloat16_t *, dfloat16_t * );
4243
dfloat32_t *dfloat16_cast32( dfloat16_t * );
4344
dfloat64_t *dfloat16_cast64( dfloat16_t * );
@@ -48,6 +49,7 @@ void dfloat32_add( dfloat32_t *, dfloat32_t * );
4849
void dfloat32_sub( dfloat32_t *, dfloat32_t * );
4950
void dfloat32_mul( dfloat32_t *, dfloat32_t * );
5051
void dfloat32_div( dfloat32_t *, dfloat32_t *, int );
52+
int dfloat32_cmp( dfloat32_t *, dfloat32_t * );
5153
void dfloat32_cpy( dfloat32_t *, dfloat32_t * );
5254
dfloat16_t *dfloat32_cast16( dfloat32_t * );
5355
dfloat64_t *dfloat32_cast64( dfloat32_t * );
@@ -58,6 +60,7 @@ void dfloat64_add( dfloat64_t *, dfloat64_t * );
5860
void dfloat64_sub( dfloat64_t *, dfloat64_t * );
5961
void dfloat64_mul( dfloat64_t *, dfloat64_t * );
6062
void dfloat64_div( dfloat64_t *, dfloat64_t *, int );
63+
int dfloat64_cmp( dfloat64_t *, dfloat64_t * );
6164
void dfloat64_cpy( dfloat64_t *, dfloat64_t * );
6265
dfloat16_t *dfloat64_cast16( dfloat64_t * );
6366
dfloat32_t *dfloat64_cast32( dfloat64_t * );
@@ -68,6 +71,7 @@ void dfloat128_add( dfloat128_t *, dfloat128_t * );
6871
void dfloat128_sub( dfloat128_t *, dfloat128_t * );
6972
void dfloat128_mul( dfloat128_t *, dfloat128_t * );
7073
void dfloat128_div( dfloat128_t *, dfloat128_t *, int );
74+
int dfloat128_cmp( dfloat128_t *, dfloat128_t * );
7175
void dfloat128_cpy( dfloat128_t *, dfloat128_t * );
7276
dfloat16_t *dfloat128_cast16( dfloat128_t * );
7377
dfloat32_t *dfloat128_cast32( dfloat128_t * );

0 commit comments

Comments
 (0)