|
| 1 | +Note: This is a temporary file designed to serve as documentation of the |
| 2 | +libdfloat library until I write some actual man pages. |
| 3 | + |
| 4 | + |
| 5 | +libdfloat defines the following data types: |
| 6 | + |
| 7 | +dfloat16_t: 16-bit decimal float with 8-bit mantissa and exponent |
| 8 | +dfloat32_t: 32-bit decimal float with 16-bit mantissa and exponent |
| 9 | +dfloat64_t: 64-bit decimal float with 32-bit mantissa and exponent |
| 10 | +dfloat128_t: 128-bit decimal float with 64-bit mantissa and exponent |
| 11 | + |
| 12 | +The proper way to declare a dfloat is to specify a decimal literal in |
| 13 | +string format and convert it to a dfloat using one of the dfloatN_atof() |
| 14 | +functions. |
| 15 | + |
| 16 | + |
| 17 | +In the following function definitions, the capital letters M and N stand |
| 18 | +for integers, either 16, 32, 64, or 128. These numbers can be substituted |
| 19 | +as desired, as there are macros that generate the corresponding functions. |
| 20 | +(Example: dfloat64_add(), no spaces) |
| 21 | + |
| 22 | +libdfloat defines the following groups of functions: |
| 23 | + |
| 24 | +void dfloatN_add( dfloatN_t *dst, dfloatN_t *src ) |
| 25 | +Add N-bit src and dst operands together and store the result in dst. |
| 26 | + |
| 27 | +void dfloatN_sub( dfloatN_t *dst, dfloatN_t *src ) |
| 28 | +Subtract N-bit src from N-bit dst and store the result in dst. |
| 29 | + |
| 30 | +void dfloatN_mul( dfloatN_t *dst, dfloatN_t *src ) |
| 31 | +Multiply N-bit src and dst operands together and store the result in dst. |
| 32 | + |
| 33 | +void dfloatN_div( dfloatN_t *dst, dfloatN_t *src, int precision ) |
| 34 | +Divide N-bit dst by src and store the result in src, with up to precision |
| 35 | +digits past the decimal point. |
| 36 | + |
| 37 | +int dfloatN_cmp( dfloatN_t *df1, dfloatN_t *df2 ) |
| 38 | +Compares N-bit operands df1 and df2. |
| 39 | +Returns: |
| 40 | +1 if df1 > df2 |
| 41 | +-1 if df1 < df2 |
| 42 | +0 if df1 == df2 |
| 43 | + |
| 44 | +dfloatN_t *dfloatN_atof( char *str ) |
| 45 | +Reads an N-bit dfloat from input string str. |
| 46 | +Input string must be in the following format (BNF): |
| 47 | +[-]<digit><digit>*[.<digit><digits>*] |
| 48 | + |
| 49 | +char *dfloatN_ftoa( dfloatN_t *df ) |
| 50 | +Generates a string representation of N-bit dfloat value df. |
| 51 | + |
| 52 | +void dfloatN_cpy( dfloatN_t *dst, dfloatN_t *src ) |
| 53 | +Copies the mantissa and exponent from src to dst. |
| 54 | + |
| 55 | +dfloatN_t *dfloatM_castN( dfloatM *src ) |
| 56 | +Takes a dfloat of size M and typecasts it, returning a dfloat of size N. |
| 57 | +Note: Does not work if M == N. |
| 58 | + |
| 59 | + |
| 60 | +Overflow errors may occur if the result of an operation is too large to |
| 61 | +fit into the designated space. These will not be reported by the compiler |
| 62 | +and will simply result in incorrect values. It is up to the programmer to |
| 63 | +account for these overflows. |
| 64 | + |
| 65 | + |
| 66 | +Any questions or problems? Feel free to contact me at the following: |
| 67 | +Github: github.com/PsychoCod3r |
| 68 | + |
| 69 | +Submit issues at github.com/PsychoCod3r/libdfloat |
0 commit comments