8000 added comments for clarity · srcarroll/flexfloat@0293d36 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0293d36

Browse files
authored
added comments for clarity
1 parent 6bd8feb commit 0293d36

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

include/flexfloat.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ extern "C" {
5656

5757
#ifdef FLEXFLOAT_ON_SINGLE
5858
#define UINT_C UINT32_C
59-
#define MASK_FRAC (UINT32_C(0x007FFFFF))
60-
#define MASK_FRAC_MSB (UINT32_C(0x00800000))
61-
#define MASK_FRAC_EXCEPT_MSB (UINT32_C(0x003FFFFF))
59+
#define MASK_FRAC (UINT32_C(0x007FFFFF)) //biggest denormal (subnormal) value (23 ones)
60+
#define MASK_FRAC_MSB (UINT32_C(0x00800000)) //smallest normal value? (MSB of 24 bit value) (1 followed by 23 zeros)
61+
#define MASK_FRAC_EXCEPT_MSB (UINT32_C(0x003FFFFF)) //sign bit? (22 ones)
6262
#define SMALLEST_NORM_POS (0x00800000)
6363
#define SMALLEST_NORM_NEG (0x80800000)
64-
#define INF_EXP (0xFF)
65-
#define BIAS (127)
64+
#define INF_EXP (0xFF) //integer value of 255 (8 ones)
65+
#define BIAS (127) //bias for exponent
6666
#define NUM_BITS (32)
6767
#define NUM_BITS_EXP (8)
6868
#define NUM_BITS_FRAC (23)
@@ -136,7 +136,14 @@ typedef __float128 fp_t;
136136
// Helper macros
137137

138138
#define SIGN( a ) ((bool) ((uint_t) (a)>>(NUM_BITS-1)))
139-
#define EXPONENT( a ) ((int_fast16_t) ((uint_t) (a)>>NUM_BITS_FRAC) & INF_EXP)
139+
140+
// (a) >> NUM_BITS_FRAC shifts bits to the right by number of fractional bits to obtain the bits in the sign and exponent.
141+
// ( ) & INF_EXP zeros out everything except for the bits corresponding to the exponent.
142+
// Thus the final result is the exponent value.
143+
#define EXPONENT( a ) ((int_fast16_t) ((uint_t) (a)>>NUM_BITS_FRAC) & INF_EXP)
144+
145+
// shifts bits of sign and exp values so that they are in their appropriate bit precisions.
146+
// then adds everything to get binary representation of number with corresponding sign, exp, and significant
140147
#define PACK( sign, exp, sig ) ((uint_t) (((uint_t) (sign)<<(NUM_BITS-1)) + ((uint_t) (exp)<<NUM_BITS_FRAC) + (sig)))
141148

142149
#define CAST_TO_INT(d) (*((int_t *)(&(d))))
@@ -154,6 +161,7 @@ struct _flexfloat_t;
154161
typedef struct _flexfloat_t flexfloat_t;
155162
typedef void (*ff_function_p)(flexfloat_t *, void *);
156163

164+
// probably need to come back to this to understand other things
157165
typedef struct _flexfloat_desc_t {
158166
uint8_t exp_bits;
159167
uint8_t frac_bits;

0 commit comments

Comments
 (0)
0