Blame lib/float+.h

Packit Service fdd496
/* Supplemental information about the floating-point formats.
Packit Service fdd496
   Copyright (C) 2007, 2009-2017 Free Software Foundation, Inc.
Packit Service fdd496
   Written by Bruno Haible <bruno@clisp.org>, 2007.
Packit Service fdd496
Packit Service fdd496
   This program is free software; you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3, or (at your option)
Packit Service fdd496
   any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
#ifndef _FLOATPLUS_H
Packit Service fdd496
#define _FLOATPLUS_H
Packit Service fdd496
Packit Service fdd496
#include <float.h>
Packit Service fdd496
#include <limits.h>
Packit Service fdd496
Packit Service fdd496
/* Number of bits in the mantissa of a floating-point number, including the
Packit Service fdd496
   "hidden bit".  */
Packit Service fdd496
#if FLT_RADIX == 2
Packit Service fdd496
# define FLT_MANT_BIT FLT_MANT_DIG
Packit Service fdd496
# define DBL_MANT_BIT DBL_MANT_DIG
Packit Service fdd496
# define LDBL_MANT_BIT LDBL_MANT_DIG
Packit Service fdd496
#elif FLT_RADIX == 4
Packit Service fdd496
# define FLT_MANT_BIT (FLT_MANT_DIG * 2)
Packit Service fdd496
# define DBL_MANT_BIT (DBL_MANT_DIG * 2)
Packit Service fdd496
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2)
Packit Service fdd496
#elif FLT_RADIX == 16
Packit Service fdd496
# define FLT_MANT_BIT (FLT_MANT_DIG * 4)
Packit Service fdd496
# define DBL_MANT_BIT (DBL_MANT_DIG * 4)
Packit Service fdd496
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4)
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* Bit mask that can be used to mask the exponent, as an unsigned number.  */
Packit Service fdd496
#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7)
Packit Service fdd496
#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
Packit Service fdd496
#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7)
Packit Service fdd496
Packit Service fdd496
/* Number of bits used for the exponent of a floating-point number, including
Packit Service fdd496
   the exponent's sign.  */
Packit Service fdd496
#define FLT_EXP_BIT \
Packit Service fdd496
  (FLT_EXP_MASK < 0x100 ? 8 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x200 ? 9 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x400 ? 10 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x800 ? 11 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x1000 ? 12 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x2000 ? 13 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x4000 ? 14 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x8000 ? 15 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x10000 ? 16 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x20000 ? 17 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x40000 ? 18 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x80000 ? 19 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x100000 ? 20 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x200000 ? 21 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x400000 ? 22 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x800000 ? 23 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x1000000 ? 24 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x2000000 ? 25 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x4000000 ? 26 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x8000000 ? 27 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x10000000 ? 28 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x20000000 ? 29 : \
Packit Service fdd496
   FLT_EXP_MASK < 0x40000000 ? 30 : \
Packit Service fdd496
   FLT_EXP_MASK <= 0x7fffffff ? 31 : \
Packit Service fdd496
   32)
Packit Service fdd496
#define DBL_EXP_BIT \
Packit Service fdd496
  (DBL_EXP_MASK < 0x100 ? 8 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x200 ? 9 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x400 ? 10 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x800 ? 11 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x1000 ? 12 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x2000 ? 13 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x4000 ? 14 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x8000 ? 15 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x10000 ? 16 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x20000 ? 17 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x40000 ? 18 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x80000 ? 19 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x100000 ? 20 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x200000 ? 21 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x400000 ? 22 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x800000 ? 23 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x1000000 ? 24 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x2000000 ? 25 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x4000000 ? 26 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x8000000 ? 27 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x10000000 ? 28 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x20000000 ? 29 : \
Packit Service fdd496
   DBL_EXP_MASK < 0x40000000 ? 30 : \
Packit Service fdd496
   DBL_EXP_MASK <= 0x7fffffff ? 31 : \
Packit Service fdd496
   32)
Packit Service fdd496
#define LDBL_EXP_BIT \
Packit Service fdd496
  (LDBL_EXP_MASK < 0x100 ? 8 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x200 ? 9 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x400 ? 10 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x800 ? 11 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x1000 ? 12 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x2000 ? 13 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x4000 ? 14 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x8000 ? 15 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x10000 ? 16 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x20000 ? 17 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x40000 ? 18 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x80000 ? 19 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x100000 ? 20 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x200000 ? 21 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x400000 ? 22 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x800000 ? 23 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x1000000 ? 24 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x2000000 ? 25 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x4000000 ? 26 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x8000000 ? 27 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x10000000 ? 28 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x20000000 ? 29 : \
Packit Service fdd496
   LDBL_EXP_MASK < 0x40000000 ? 30 : \
Packit Service fdd496
   LDBL_EXP_MASK <= 0x7fffffff ? 31 : \
Packit Service fdd496
   32)
Packit Service fdd496
Packit Service fdd496
/* Number of bits used for a floating-point number: the mantissa (not
Packit Service fdd496
   counting the "hidden bit", since it may or may not be explicit), the
Packit Service fdd496
   exponent, and the sign.  */
Packit Service fdd496
#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1)
Packit Service fdd496
#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1)
Packit Service fdd496
#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1)
Packit Service fdd496
Packit Service fdd496
/* Number of bytes used for a floating-point number.
Packit Service fdd496
   This can be smaller than the 'sizeof'.  For example, on i386 systems,
Packit Service fdd496
   'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence
Packit Service fdd496
   LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but
Packit Service fdd496
   sizeof (long double) = 12 or = 16.  */
Packit Service fdd496
#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
Packit Service fdd496
#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
Packit Service fdd496
#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
Packit Service fdd496
Packit Service fdd496
/* Verify that SIZEOF_FLT <= sizeof (float) etc.  */
Packit Service fdd496
typedef int verify_sizeof_flt[SIZEOF_FLT <= sizeof (float) ? 1 : -1];
Packit Service fdd496
typedef int verify_sizeof_dbl[SIZEOF_DBL <= sizeof (double) ? 1 : - 1];
Packit Service fdd496
typedef int verify_sizeof_ldbl[SIZEOF_LDBL <= sizeof (long double) ? 1 : - 1];
Packit Service fdd496
Packit Service fdd496
#endif /* _FLOATPLUS_H */