diff options
Diffstat (limited to 'ext/fputils/include/fputils/fp80.h')
-rw-r--r-- | ext/fputils/include/fputils/fp80.h | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/ext/fputils/include/fputils/fp80.h b/ext/fputils/include/fputils/fp80.h index 70acb6cb1..c824baa1c 100644 --- a/ext/fputils/include/fputils/fp80.h +++ b/ext/fputils/include/fputils/fp80.h @@ -30,10 +30,12 @@ #ifndef _FP80_H #define _FP80_H 1 -#include <math.h> -#include <stdint.h> +#include <math.h> /* FP_NAN et al. */ #include <stdio.h> +#include <fputils/fptypes.h> + + #ifdef __cplusplus extern "C" { #endif @@ -45,15 +47,6 @@ extern "C" { * @{ */ -/** Internal representation of an 80-bit float. */ -typedef union { - char bits[10]; - struct { - uint64_t fi; - uint16_t se; - } repr; -} fp80_t; - /** Constant representing +inf */ extern const fp80_t fp80_pinf; /** Constant representing -inf */ @@ -190,6 +183,21 @@ int fp80_iszero(fp80_t fp80); */ int fp80_issubnormal(fp80_t fp80); + +/** + * Convert an 80-bit float to a 64-bit double. + * + * Convenience wrapper around fp80_cvtfp64() that returns a double + * instead of the internal fp64_t representation. + * + * Note that this conversion is lossy, see fp80_cvtfp64() for details + * of the conversion. + * + * @param fp80 Source value to convert. + * @return value represented as double. + */ +double fp80_cvtd(fp80_t fp80); + /** * Convert an 80-bit float to a 64-bit double. * @@ -214,24 +222,36 @@ int fp80_issubnormal(fp80_t fp80); * @param fp80 Source value to convert. * @return 64-bit version of the float. */ -double fp80_cvtd(fp80_t fp80); +fp64_t fp80_cvtfp64(fp80_t fp80); /** - * Convert an 64-bit double to an 80-bit float. - * - * This function converts a standard 64-bit double into an 80-bit - * float. This conversion is completely lossless since the 80-bit - * float represents a superset of what a 64-bit double can - * represent. + * Convert a double to an 80-bit float. * - * @note Denormals will be converted to normalized values. + * This is a convenience wrapper around fp80_cvffp64() and provides a + * convenient way of using the native double type instead of the + * internal fp64_t representation. * * @param fpd Source value to convert. - * @return 64-bit version of the float. + * @return 80-bit version of the float. */ fp80_t fp80_cvfd(double fpd); /** + * Convert a 64-bit float to an 80-bit float. + * + * This function converts the internal representation of a 64-bit + * float into an 80-bit float. This conversion is completely lossless + * since the 80-bit float represents a superset of what a 64-bit + * float can represent. + * + * @note Denormals will be converted to normalized values. + * + * @param fp64 64-bit float to convert. + * @return 80-bit version of the float. + */ +fp80_t fp80_cvffp64(fp64_t fp64); + +/** * Dump the components of an 80-bit float to a file. * * @warning This function is intended for debugging and the format of |