123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #ifndef _GL_FTOASTR_H
- #include "intprops.h"
- #include <float.h>
- #include <stddef.h>
- int ftoastr (char *buf, size_t bufsize, int flags, int width, float x);
- int dtoastr (char *buf, size_t bufsize, int flags, int width, double x);
- int ldtoastr (char *buf, size_t bufsize, int flags, int width, long double x);
- enum
- {
-
- FTOASTR_LEFT_JUSTIFY = 1,
-
- FTOASTR_ALWAYS_SIGNED = 2,
-
- FTOASTR_SPACE_POSITIVE = 4,
-
- FTOASTR_ZERO_PAD = 8,
-
- FTOASTR_UPPER_E = 16
- };
- #if FLT_RADIX == 10 /* decimal floating point */
- enum { _GL_FLT_PREC_BOUND = FLT_MANT_DIG };
- enum { _GL_DBL_PREC_BOUND = DBL_MANT_DIG };
- enum { _GL_LDBL_PREC_BOUND = LDBL_MANT_DIG };
- #else
- # if FLT_RADIX == 2 /* IEEE 754 floating point, VAX floating point, etc. */
- # define _GL_FLOAT_DIG_BITS_BOUND 1
- # elif FLT_RADIX <= 16 /* IBM hex floating point has FLT_RADIX == 16. */
- # define _GL_FLOAT_DIG_BITS_BOUND 4
- # else /* no machine is this bad, but let's be complete */
- # define _GL_FLOAT_DIG_BITS_BOUND (CHAR_BIT * (int) sizeof (int) - 1)
- # endif
- # define _GL_FLOAT_PREC_BOUND(dig) \
- (INT_BITS_STRLEN_BOUND ((dig) * _GL_FLOAT_DIG_BITS_BOUND) + 1)
- enum { _GL_FLT_PREC_BOUND = _GL_FLOAT_PREC_BOUND ( FLT_MANT_DIG) };
- enum { _GL_DBL_PREC_BOUND = _GL_FLOAT_PREC_BOUND ( DBL_MANT_DIG) };
- enum { _GL_LDBL_PREC_BOUND = _GL_FLOAT_PREC_BOUND (LDBL_MANT_DIG) };
- #endif
- #define _GL_FLOAT_EXPONENT_STRLEN_BOUND(min, max) \
- ( -100 < (min) && (max) < 100 ? 3 \
- : -1000 < (min) && (max) < 1000 ? 4 \
- : -10000 < (min) && (max) < 10000 ? 5 \
- : -100000 < (min) && (max) < 100000 ? 6 \
- : -1000000 < (min) && (max) < 1000000 ? 7 \
- : INT_STRLEN_BOUND (int) )
- #define _GL_FLOAT_STRLEN_BOUND_L(t, pointlen) \
- (1 + _GL_##t##_PREC_BOUND + pointlen + 1 \
- + _GL_FLOAT_EXPONENT_STRLEN_BOUND (t##_MIN_10_EXP, t##_MAX_10_EXP))
- #define FLT_STRLEN_BOUND_L(pointlen) _GL_FLOAT_STRLEN_BOUND_L ( FLT, pointlen)
- #define DBL_STRLEN_BOUND_L(pointlen) _GL_FLOAT_STRLEN_BOUND_L ( DBL, pointlen)
- #define LDBL_STRLEN_BOUND_L(pointlen) _GL_FLOAT_STRLEN_BOUND_L (LDBL, pointlen)
- #define FLT_STRLEN_BOUND FLT_STRLEN_BOUND_L (MB_LEN_MAX)
- #define DBL_STRLEN_BOUND DBL_STRLEN_BOUND_L (MB_LEN_MAX)
- #define LDBL_STRLEN_BOUND LDBL_STRLEN_BOUND_L (MB_LEN_MAX)
- #define FLT_BUFSIZE_BOUND ( FLT_STRLEN_BOUND + 1)
- #define DBL_BUFSIZE_BOUND ( DBL_STRLEN_BOUND + 1)
- #define LDBL_BUFSIZE_BOUND (LDBL_STRLEN_BOUND + 1)
- #endif /* _GL_FTOASTR_H */
|