Blame gl/float+.h

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