Adding upstream version 1:10.0.2+ds.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
This commit is contained in:
parent
bf2768bd0f
commit
ea34ddeea6
37998 changed files with 9510514 additions and 0 deletions
39
include/libdecnumber/dconfig.h
Normal file
39
include/libdecnumber/dconfig.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* Configure decNumber for either host or target.
|
||||
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
|
||||
#if HOST_BIG_ENDIAN
|
||||
#define WORDS_BIGENDIAN 1
|
||||
#else
|
||||
#define WORDS_BIGENDIAN 0
|
||||
#endif
|
||||
|
||||
#ifndef DECDPUN
|
||||
#define DECDPUN 3
|
||||
#endif
|
255
include/libdecnumber/decContext.h
Normal file
255
include/libdecnumber/decContext.h
Normal file
|
@ -0,0 +1,255 @@
|
|||
/* Decimal context header module for the decNumber C Library.
|
||||
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
|
||||
Contributed by IBM Corporation. Author Mike Cowlishaw.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Decimal Context module header */
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* */
|
||||
/* Context variables must always have valid values: */
|
||||
/* */
|
||||
/* status -- [any bits may be cleared, but not set, by user] */
|
||||
/* round -- must be one of the enumerated rounding modes */
|
||||
/* */
|
||||
/* The following variables are implied for fixed size formats (i.e., */
|
||||
/* they are ignored) but should still be set correctly in case used */
|
||||
/* with decNumber functions: */
|
||||
/* */
|
||||
/* clamp -- must be either 0 or 1 */
|
||||
/* digits -- must be in the range 1 through 999999999 */
|
||||
/* emax -- must be in the range 0 through 999999999 */
|
||||
/* emin -- must be in the range 0 through -999999999 */
|
||||
/* extended -- must be either 0 or 1 [present only if DECSUBSET] */
|
||||
/* traps -- only defined bits may be set */
|
||||
/* */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#ifndef DECCONTEXT_H
|
||||
#define DECCONTEXT_H
|
||||
|
||||
#define DECCNAME "decContext" /* Short name */
|
||||
#define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
|
||||
#define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
|
||||
|
||||
|
||||
/* Extended flags setting -- set this to 0 to use only IEEE flags */
|
||||
#define DECEXTFLAG 1 /* 1=enable extended flags */
|
||||
|
||||
/* Conditional code flag -- set this to 0 for best performance */
|
||||
#define DECSUBSET 0 /* 1=enable subset arithmetic */
|
||||
|
||||
/* Context for operations, with associated constants */
|
||||
enum rounding {
|
||||
DEC_ROUND_CEILING, /* round towards +infinity */
|
||||
DEC_ROUND_UP, /* round away from 0 */
|
||||
DEC_ROUND_HALF_UP, /* 0.5 rounds up */
|
||||
DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */
|
||||
DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */
|
||||
DEC_ROUND_DOWN, /* round towards 0 (truncate) */
|
||||
DEC_ROUND_FLOOR, /* round towards -infinity */
|
||||
DEC_ROUND_05UP, /* round for reround */
|
||||
DEC_ROUND_MAX /* enum must be less than this */
|
||||
};
|
||||
#define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
|
||||
|
||||
typedef struct {
|
||||
int32_t digits; /* working precision */
|
||||
int32_t emax; /* maximum positive exponent */
|
||||
int32_t emin; /* minimum negative exponent */
|
||||
enum rounding round; /* rounding mode */
|
||||
uint32_t traps; /* trap-enabler flags */
|
||||
uint32_t status; /* status flags */
|
||||
uint8_t clamp; /* flag: apply IEEE exponent clamp */
|
||||
#if DECSUBSET
|
||||
uint8_t extended; /* flag: special-values allowed */
|
||||
#endif
|
||||
} decContext;
|
||||
|
||||
/* Maxima and Minima for context settings */
|
||||
#define DEC_MAX_DIGITS 999999999
|
||||
#define DEC_MIN_DIGITS 1
|
||||
#define DEC_MAX_EMAX 999999999
|
||||
#define DEC_MIN_EMAX 0
|
||||
#define DEC_MAX_EMIN 0
|
||||
#define DEC_MIN_EMIN -999999999
|
||||
#define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */
|
||||
|
||||
/* Classifications for decimal numbers, aligned with 754r (note */
|
||||
/* that 'normal' and 'subnormal' are meaningful only with a */
|
||||
/* decContext or a fixed size format). */
|
||||
enum decClass {
|
||||
DEC_CLASS_SNAN,
|
||||
DEC_CLASS_QNAN,
|
||||
DEC_CLASS_NEG_INF,
|
||||
DEC_CLASS_NEG_NORMAL,
|
||||
DEC_CLASS_NEG_SUBNORMAL,
|
||||
DEC_CLASS_NEG_ZERO,
|
||||
DEC_CLASS_POS_ZERO,
|
||||
DEC_CLASS_POS_SUBNORMAL,
|
||||
DEC_CLASS_POS_NORMAL,
|
||||
DEC_CLASS_POS_INF
|
||||
};
|
||||
/* Strings for the decClasses */
|
||||
#define DEC_ClassString_SN "sNaN"
|
||||
#define DEC_ClassString_QN "NaN"
|
||||
#define DEC_ClassString_NI "-Infinity"
|
||||
#define DEC_ClassString_NN "-Normal"
|
||||
#define DEC_ClassString_NS "-Subnormal"
|
||||
#define DEC_ClassString_NZ "-Zero"
|
||||
#define DEC_ClassString_PZ "+Zero"
|
||||
#define DEC_ClassString_PS "+Subnormal"
|
||||
#define DEC_ClassString_PN "+Normal"
|
||||
#define DEC_ClassString_PI "+Infinity"
|
||||
#define DEC_ClassString_UN "Invalid"
|
||||
|
||||
/* Trap-enabler and Status flags (exceptional conditions), and */
|
||||
/* their names. The top byte is reserved for internal use */
|
||||
#if DECEXTFLAG
|
||||
/* Extended flags */
|
||||
#define DEC_Conversion_syntax 0x00000001
|
||||
#define DEC_Division_by_zero 0x00000002
|
||||
#define DEC_Division_impossible 0x00000004
|
||||
#define DEC_Division_undefined 0x00000008
|
||||
#define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
|
||||
#define DEC_Inexact 0x00000020
|
||||
#define DEC_Invalid_context 0x00000040
|
||||
#define DEC_Invalid_operation 0x00000080
|
||||
#if DECSUBSET
|
||||
#define DEC_Lost_digits 0x00000100
|
||||
#endif
|
||||
#define DEC_Overflow 0x00000200
|
||||
#define DEC_Clamped 0x00000400
|
||||
#define DEC_Rounded 0x00000800
|
||||
#define DEC_Subnormal 0x00001000
|
||||
#define DEC_Underflow 0x00002000
|
||||
#else
|
||||
/* IEEE flags only */
|
||||
#define DEC_Conversion_syntax 0x00000010
|
||||
#define DEC_Division_by_zero 0x00000002
|
||||
#define DEC_Division_impossible 0x00000010
|
||||
#define DEC_Division_undefined 0x00000010
|
||||
#define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
|
||||
#define DEC_Inexact 0x00000001
|
||||
#define DEC_Invalid_context 0x00000010
|
||||
#define DEC_Invalid_operation 0x00000010
|
||||
#if DECSUBSET
|
||||
#define DEC_Lost_digits 0x00000000
|
||||
#endif
|
||||
#define DEC_Overflow 0x00000008
|
||||
#define DEC_Clamped 0x00000000
|
||||
#define DEC_Rounded 0x00000000
|
||||
#define DEC_Subnormal 0x00000000
|
||||
#define DEC_Underflow 0x00000004
|
||||
#endif
|
||||
|
||||
/* IEEE 854 groupings for the flags */
|
||||
/* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */
|
||||
/* are not in IEEE 854] */
|
||||
#define DEC_IEEE_854_Division_by_zero (DEC_Division_by_zero)
|
||||
#if DECSUBSET
|
||||
#define DEC_IEEE_854_Inexact (DEC_Inexact | DEC_Lost_digits)
|
||||
#else
|
||||
#define DEC_IEEE_854_Inexact (DEC_Inexact)
|
||||
#endif
|
||||
#define DEC_IEEE_854_Invalid_operation (DEC_Conversion_syntax | \
|
||||
DEC_Division_impossible | \
|
||||
DEC_Division_undefined | \
|
||||
DEC_Insufficient_storage | \
|
||||
DEC_Invalid_context | \
|
||||
DEC_Invalid_operation)
|
||||
#define DEC_IEEE_854_Overflow (DEC_Overflow)
|
||||
#define DEC_IEEE_854_Underflow (DEC_Underflow)
|
||||
|
||||
/* flags which are normally errors (result is qNaN, infinite, or 0) */
|
||||
#define DEC_Errors (DEC_IEEE_854_Division_by_zero | \
|
||||
DEC_IEEE_854_Invalid_operation | \
|
||||
DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow)
|
||||
/* flags which cause a result to become qNaN */
|
||||
#define DEC_NaNs DEC_IEEE_854_Invalid_operation
|
||||
|
||||
/* flags which are normally for information only (finite results) */
|
||||
#if DECSUBSET
|
||||
#define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
|
||||
| DEC_Lost_digits)
|
||||
#else
|
||||
#define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
|
||||
#endif
|
||||
|
||||
/* Name strings for the exceptional conditions */
|
||||
#define DEC_Condition_CS "Conversion syntax"
|
||||
#define DEC_Condition_DZ "Division by zero"
|
||||
#define DEC_Condition_DI "Division impossible"
|
||||
#define DEC_Condition_DU "Division undefined"
|
||||
#define DEC_Condition_IE "Inexact"
|
||||
#define DEC_Condition_IS "Insufficient storage"
|
||||
#define DEC_Condition_IC "Invalid context"
|
||||
#define DEC_Condition_IO "Invalid operation"
|
||||
#if DECSUBSET
|
||||
#define DEC_Condition_LD "Lost digits"
|
||||
#endif
|
||||
#define DEC_Condition_OV "Overflow"
|
||||
#define DEC_Condition_PA "Clamped"
|
||||
#define DEC_Condition_RO "Rounded"
|
||||
#define DEC_Condition_SU "Subnormal"
|
||||
#define DEC_Condition_UN "Underflow"
|
||||
#define DEC_Condition_ZE "No status"
|
||||
#define DEC_Condition_MU "Multiple status"
|
||||
#define DEC_Condition_Length 21 /* length of the longest string, */
|
||||
/* including terminator */
|
||||
|
||||
/* Initialization descriptors, used by decContextDefault */
|
||||
#define DEC_INIT_BASE 0
|
||||
#define DEC_INIT_DECIMAL32 32
|
||||
#define DEC_INIT_DECIMAL64 64
|
||||
#define DEC_INIT_DECIMAL128 128
|
||||
/* Synonyms */
|
||||
#define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
|
||||
#define DEC_INIT_DECDOUBLE DEC_INIT_DECIMAL64
|
||||
#define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
|
||||
|
||||
/* decContext routines */
|
||||
|
||||
|
||||
extern decContext * decContextClearStatus(decContext *, uint32_t);
|
||||
extern decContext * decContextDefault(decContext *, int32_t);
|
||||
extern enum rounding decContextGetRounding(decContext *);
|
||||
extern uint32_t decContextGetStatus(decContext *);
|
||||
extern decContext * decContextRestoreStatus(decContext *, uint32_t, uint32_t);
|
||||
extern uint32_t decContextSaveStatus(decContext *, uint32_t);
|
||||
extern decContext * decContextSetRounding(decContext *, enum rounding);
|
||||
extern decContext * decContextSetStatus(decContext *, uint32_t);
|
||||
extern decContext * decContextSetStatusFromString(decContext *, const char *);
|
||||
extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *);
|
||||
extern decContext * decContextSetStatusQuiet(decContext *, uint32_t);
|
||||
extern const char * decContextStatusToString(const decContext *);
|
||||
extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
|
||||
extern uint32_t decContextTestStatus(decContext *, uint32_t);
|
||||
extern decContext * decContextZeroStatus(decContext *);
|
||||
|
||||
#endif
|
1214
include/libdecnumber/decDPD.h
Normal file
1214
include/libdecnumber/decDPD.h
Normal file
File diff suppressed because it is too large
Load diff
205
include/libdecnumber/decNumber.h
Normal file
205
include/libdecnumber/decNumber.h
Normal file
|
@ -0,0 +1,205 @@
|
|||
/* Decimal number arithmetic module header for the decNumber C Library.
|
||||
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
|
||||
Contributed by IBM Corporation. Author Mike Cowlishaw.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Decimal Number arithmetic module header */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#ifndef DECNUMBER_H
|
||||
#define DECNUMBER_H
|
||||
|
||||
#define DECNAME "decNumber" /* Short name */
|
||||
#define DECFULLNAME "Decimal Number Module" /* Verbose name */
|
||||
#define DECAUTHOR "Mike Cowlishaw" /* Who to blame */
|
||||
|
||||
#include "libdecnumber/decContext.h"
|
||||
|
||||
/* Bit settings for decNumber.bits */
|
||||
#define DECNEG 0x80 /* Sign; 1=negative, 0=positive or zero */
|
||||
#define DECINF 0x40 /* 1=Infinity */
|
||||
#define DECNAN 0x20 /* 1=NaN */
|
||||
#define DECSNAN 0x10 /* 1=sNaN */
|
||||
/* The remaining bits are reserved; they must be 0 */
|
||||
#define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value */
|
||||
|
||||
/* Define the decNumber data structure. The size and shape of the */
|
||||
/* units array in the structure is determined by the following */
|
||||
/* constant. This must not be changed without recompiling the */
|
||||
/* decNumber library modules. */
|
||||
|
||||
#define DECDPUN 3 /* DECimal Digits Per UNit [must be >0 */
|
||||
/* and <10; 3 or powers of 2 are best]. */
|
||||
|
||||
/* DECNUMDIGITS is the default number of digits that can be held in */
|
||||
/* the structure. If undefined, 1 is assumed and it is assumed */
|
||||
/* that the structure will be immediately followed by extra space, */
|
||||
/* as required. DECNUMDIGITS is always >0. */
|
||||
#if !defined(DECNUMDIGITS)
|
||||
#define DECNUMDIGITS 1
|
||||
#endif
|
||||
|
||||
/* The size (integer data type) of each unit is determined by the */
|
||||
/* number of digits it will hold. */
|
||||
#if DECDPUN<=2
|
||||
#define decNumberUnit uint8_t
|
||||
#elif DECDPUN<=4
|
||||
#define decNumberUnit uint16_t
|
||||
#else
|
||||
#define decNumberUnit uint32_t
|
||||
#endif
|
||||
/* The number of units needed is ceil(DECNUMDIGITS/DECDPUN) */
|
||||
#define DECNUMUNITS ((DECNUMDIGITS+DECDPUN-1)/DECDPUN)
|
||||
|
||||
/* The data structure... */
|
||||
typedef struct {
|
||||
int32_t digits; /* Count of digits in the coefficient; >0 */
|
||||
int32_t exponent; /* Unadjusted exponent, unbiased, in */
|
||||
/* range: -1999999997 through 999999999 */
|
||||
uint8_t bits; /* Indicator bits (see above) */
|
||||
/* Coefficient, from least significant unit */
|
||||
decNumberUnit lsu[DECNUMUNITS];
|
||||
} decNumber;
|
||||
|
||||
/* Notes: */
|
||||
/* 1. If digits is > DECDPUN then there will one or more */
|
||||
/* decNumberUnits immediately following the first element of lsu.*/
|
||||
/* These contain the remaining (more significant) digits of the */
|
||||
/* number, and may be in the lsu array, or may be guaranteed by */
|
||||
/* some other mechanism (such as being contained in another */
|
||||
/* structure, or being overlaid on dynamically allocated */
|
||||
/* storage). */
|
||||
/* */
|
||||
/* Each integer of the coefficient (except potentially the last) */
|
||||
/* contains DECDPUN digits (e.g., a value in the range 0 through */
|
||||
/* 99999999 if DECDPUN is 8, or 0 through 999 if DECDPUN is 3). */
|
||||
/* */
|
||||
/* 2. A decNumber converted to a string may need up to digits+14 */
|
||||
/* characters. The worst cases (non-exponential and exponential */
|
||||
/* formats) are -0.00000{9...}# and -9.{9...}E+999999999# */
|
||||
/* (where # is '\0') */
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* decNumber public functions and macros */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* Conversions */
|
||||
decNumber * decNumberFromInt32(decNumber *, int32_t);
|
||||
decNumber * decNumberFromUInt32(decNumber *, uint32_t);
|
||||
decNumber *decNumberFromInt64(decNumber *, int64_t);
|
||||
decNumber *decNumberFromUInt64(decNumber *, uint64_t);
|
||||
decNumber *decNumberFromInt128(decNumber *, uint64_t, int64_t);
|
||||
decNumber *decNumberFromUInt128(decNumber *, uint64_t, uint64_t);
|
||||
decNumber * decNumberFromString(decNumber *, const char *, decContext *);
|
||||
char * decNumberToString(const decNumber *, char *);
|
||||
char * decNumberToEngString(const decNumber *, char *);
|
||||
uint32_t decNumberToUInt32(const decNumber *, decContext *);
|
||||
int32_t decNumberToInt32(const decNumber *, decContext *);
|
||||
int64_t decNumberIntegralToInt64(const decNumber *dn, decContext *set);
|
||||
void decNumberIntegralToInt128(const decNumber *dn, decContext *set,
|
||||
uint64_t *plow, uint64_t *phigh);
|
||||
uint8_t * decNumberGetBCD(const decNumber *, uint8_t *);
|
||||
decNumber * decNumberSetBCD(decNumber *, const uint8_t *, uint32_t);
|
||||
|
||||
/* Operators and elementary functions */
|
||||
decNumber * decNumberAbs(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberAdd(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberAnd(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberCompare(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberCompareSignal(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberCompareTotal(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberCompareTotalMag(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberDivide(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberDivideInteger(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberExp(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberFMA(decNumber *, const decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberInvert(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberLn(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberLogB(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberLog10(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberMax(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberMaxMag(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberMin(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberMinMag(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberMinus(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberMultiply(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberNormalize(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberOr(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberPlus(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberPower(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberQuantize(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberReduce(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberRemainder(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberRemainderNear(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberRescale(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberRotate(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberSameQuantum(decNumber *, const decNumber *, const decNumber *);
|
||||
decNumber * decNumberScaleB(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberShift(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberSquareRoot(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberSubtract(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberToIntegralExact(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberToIntegralValue(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberXor(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
|
||||
/* Utilities */
|
||||
enum decClass decNumberClass(const decNumber *, decContext *);
|
||||
const char * decNumberClassToString(enum decClass);
|
||||
decNumber * decNumberCopy(decNumber *, const decNumber *);
|
||||
decNumber * decNumberCopyAbs(decNumber *, const decNumber *);
|
||||
decNumber * decNumberCopyNegate(decNumber *, const decNumber *);
|
||||
decNumber * decNumberCopySign(decNumber *, const decNumber *, const decNumber *);
|
||||
decNumber * decNumberNextMinus(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberNextPlus(decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberNextToward(decNumber *, const decNumber *, const decNumber *, decContext *);
|
||||
decNumber * decNumberTrim(decNumber *);
|
||||
const char * decNumberVersion(void);
|
||||
decNumber * decNumberZero(decNumber *);
|
||||
|
||||
/* Functions for testing decNumbers (normality depends on context) */
|
||||
int32_t decNumberIsNormal(const decNumber *, decContext *);
|
||||
int32_t decNumberIsSubnormal(const decNumber *, decContext *);
|
||||
|
||||
/* Macros for testing decNumber *dn */
|
||||
#define decNumberIsCanonical(dn) (1) /* All decNumbers are saintly */
|
||||
#define decNumberIsFinite(dn) (((dn)->bits&DECSPECIAL)==0)
|
||||
#define decNumberIsInfinite(dn) (((dn)->bits&DECINF)!=0)
|
||||
#define decNumberIsNaN(dn) (((dn)->bits&(DECNAN|DECSNAN))!=0)
|
||||
#define decNumberIsNegative(dn) (((dn)->bits&DECNEG)!=0)
|
||||
#define decNumberIsQNaN(dn) (((dn)->bits&(DECNAN))!=0)
|
||||
#define decNumberIsSNaN(dn) (((dn)->bits&(DECSNAN))!=0)
|
||||
#define decNumberIsSpecial(dn) (((dn)->bits&DECSPECIAL)!=0)
|
||||
#define decNumberIsZero(dn) (*(dn)->lsu==0 \
|
||||
&& (dn)->digits==1 \
|
||||
&& (((dn)->bits&DECSPECIAL)==0))
|
||||
#define decNumberRadix(dn) (10)
|
||||
|
||||
#endif
|
663
include/libdecnumber/decNumberLocal.h
Normal file
663
include/libdecnumber/decNumberLocal.h
Normal file
|
@ -0,0 +1,663 @@
|
|||
/* Local definitions for the decNumber C Library.
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
Contributed by IBM Corporation. Author Mike Cowlishaw.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* decNumber package local type, tuning, and macro definitions */
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* This header file is included by all modules in the decNumber */
|
||||
/* library, and contains local type definitions, tuning parameters, */
|
||||
/* etc. It should not need to be used by application programs. */
|
||||
/* decNumber.h or one of decDouble (etc.) must be included first. */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#ifndef DECNUMBERLOCAL_H
|
||||
#define DECNUMBERLOCAL_H
|
||||
|
||||
#define DECVERSION "decNumber 3.53" /* Package Version [16 max.] */
|
||||
#define DECNLAUTHOR "Mike Cowlishaw" /* Who to blame */
|
||||
|
||||
#include "libdecnumber/dconfig.h"
|
||||
#include "libdecnumber/decContext.h"
|
||||
|
||||
/* Conditional code flag -- set this to match hardware platform */
|
||||
/* 1=little-endian, 0=big-endian */
|
||||
#if WORDS_BIGENDIAN
|
||||
#define DECLITEND 0
|
||||
#else
|
||||
#define DECLITEND 1
|
||||
#endif
|
||||
|
||||
/* Conditional code flag -- set this to 1 for best performance */
|
||||
#define DECUSE64 1 /* 1=use int64s, 0=int32 & smaller only */
|
||||
|
||||
/* Conditional check flags -- set these to 0 for best performance */
|
||||
#define DECCHECK 0 /* 1 to enable robust checking */
|
||||
#define DECALLOC 0 /* 1 to enable memory accounting */
|
||||
#define DECTRACE 0 /* 1 to trace certain internals, etc. */
|
||||
|
||||
/* Tuning parameter for decNumber (arbitrary precision) module */
|
||||
#define DECBUFFER 36 /* Size basis for local buffers. This */
|
||||
/* should be a common maximum precision */
|
||||
/* rounded up to a multiple of 4; must */
|
||||
/* be zero or positive. */
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* Definitions for all modules (general-purpose) */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
/* Local names for common types -- for safety, decNumber modules do */
|
||||
/* not use int or long directly. */
|
||||
#define Flag uint8_t
|
||||
#define Byte int8_t
|
||||
#define uByte uint8_t
|
||||
#define Short int16_t
|
||||
#define uShort uint16_t
|
||||
#define Int int32_t
|
||||
#define uInt uint32_t
|
||||
#define Unit decNumberUnit
|
||||
#if DECUSE64
|
||||
#define Long int64_t
|
||||
#define uLong uint64_t
|
||||
#endif
|
||||
|
||||
/* Development-use definitions */
|
||||
typedef long int LI; /* for printf arguments only */
|
||||
#define DECNOINT 0 /* 1 to check no internal use of 'int' */
|
||||
#if DECNOINT
|
||||
/* if these interfere with your C includes, do not set DECNOINT */
|
||||
#define int ? /* enable to ensure that plain C 'int' */
|
||||
#define long ?? /* .. or 'long' types are not used */
|
||||
#endif
|
||||
|
||||
/* Shared lookup tables */
|
||||
extern const uByte DECSTICKYTAB[10]; /* re-round digits if sticky */
|
||||
extern const uLong DECPOWERS[20]; /* powers of ten table */
|
||||
/* The following are included from decDPD.h */
|
||||
extern const uShort DPD2BIN[1024]; /* DPD -> 0-999 */
|
||||
extern const uShort BIN2DPD[1000]; /* 0-999 -> DPD */
|
||||
extern const uInt DPD2BINK[1024]; /* DPD -> 0-999000 */
|
||||
extern const uInt DPD2BINM[1024]; /* DPD -> 0-999000000 */
|
||||
extern const uByte DPD2BCD8[4096]; /* DPD -> ddd + len */
|
||||
extern const uByte BIN2BCD8[4000]; /* 0-999 -> ddd + len */
|
||||
extern const uShort BCD2DPD[2458]; /* 0-0x999 -> DPD (0x999=2457)*/
|
||||
|
||||
/* LONGMUL32HI -- set w=(u*v)>>32, where w, u, and v are uInts */
|
||||
/* (that is, sets w to be the high-order word of the 64-bit result; */
|
||||
/* the low-order word is simply u*v.) */
|
||||
/* This version is derived from Knuth via Hacker's Delight; */
|
||||
/* it seems to optimize better than some others tried */
|
||||
#define LONGMUL32HI(w, u, v) { \
|
||||
uInt u0, u1, v0, v1, w0, w1, w2, t; \
|
||||
u0=u & 0xffff; u1=u>>16; \
|
||||
v0=v & 0xffff; v1=v>>16; \
|
||||
w0=u0*v0; \
|
||||
t=u1*v0 + (w0>>16); \
|
||||
w1=t & 0xffff; w2=t>>16; \
|
||||
w1=u0*v1 + w1; \
|
||||
(w)=u1*v1 + w2 + (w1>>16);}
|
||||
|
||||
/* ROUNDUP -- round an integer up to a multiple of n */
|
||||
#define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n)
|
||||
|
||||
/* ROUNDDOWN -- round an integer down to a multiple of n */
|
||||
#define ROUNDDOWN(i, n) (((i)/n)*n)
|
||||
#define ROUNDDOWN4(i) ((i)&~3) /* special for n=4 */
|
||||
|
||||
/* References to multi-byte sequences under different sizes */
|
||||
/* Refer to a uInt from four bytes starting at a char* or uByte*, */
|
||||
/* etc. */
|
||||
#define UINTAT(b) (*((uInt *)(b)))
|
||||
#define USHORTAT(b) (*((uShort *)(b)))
|
||||
#define UBYTEAT(b) (*((uByte *)(b)))
|
||||
|
||||
/* X10 and X100 -- multiply integer i by 10 or 100 */
|
||||
/* [shifts are usually faster than multiply; could be conditional] */
|
||||
#define X10(i) (((i)<<1)+((i)<<3))
|
||||
#define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
|
||||
|
||||
/* MAXI and MINI -- general max & min (not in ANSI) for integers */
|
||||
#define MAXI(x,y) ((x)<(y)?(y):(x))
|
||||
#define MINI(x,y) ((x)>(y)?(y):(x))
|
||||
|
||||
/* Useful constants */
|
||||
#define BILLION 1000000000 /* 10**9 */
|
||||
/* CHARMASK: 0x30303030 for ASCII/UTF8; 0xF0F0F0F0 for EBCDIC */
|
||||
#define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0')
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* Definitions for arbitrary-precision modules (only valid after */
|
||||
/* decNumber.h has been included) */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
/* Limits and constants */
|
||||
#define DECNUMMAXP 999999999 /* maximum precision code can handle */
|
||||
#define DECNUMMAXE 999999999 /* maximum adjusted exponent ditto */
|
||||
#define DECNUMMINE -999999999 /* minimum adjusted exponent ditto */
|
||||
#if (DECNUMMAXP != DEC_MAX_DIGITS)
|
||||
#error Maximum digits mismatch
|
||||
#endif
|
||||
#if (DECNUMMAXE != DEC_MAX_EMAX)
|
||||
#error Maximum exponent mismatch
|
||||
#endif
|
||||
#if (DECNUMMINE != DEC_MIN_EMIN)
|
||||
#error Minimum exponent mismatch
|
||||
#endif
|
||||
|
||||
/* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN */
|
||||
/* digits, and D2UTABLE -- the initializer for the D2U table */
|
||||
#if DECDPUN==1
|
||||
#define DECDPUNMAX 9
|
||||
#define D2UTABLE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, \
|
||||
18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, \
|
||||
33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \
|
||||
48,49}
|
||||
#elif DECDPUN==2
|
||||
#define DECDPUNMAX 99
|
||||
#define D2UTABLE {0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10, \
|
||||
11,11,12,12,13,13,14,14,15,15,16,16,17,17,18, \
|
||||
18,19,19,20,20,21,21,22,22,23,23,24,24,25}
|
||||
#elif DECDPUN==3
|
||||
#define DECDPUNMAX 999
|
||||
#define D2UTABLE {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, \
|
||||
8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13, \
|
||||
13,14,14,14,15,15,15,16,16,16,17}
|
||||
#elif DECDPUN==4
|
||||
#define DECDPUNMAX 9999
|
||||
#define D2UTABLE {0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6, \
|
||||
6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11, \
|
||||
11,11,11,12,12,12,12,13}
|
||||
#elif DECDPUN==5
|
||||
#define DECDPUNMAX 99999
|
||||
#define D2UTABLE {0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5, \
|
||||
5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9, \
|
||||
9,9,10,10,10,10}
|
||||
#elif DECDPUN==6
|
||||
#define DECDPUNMAX 999999
|
||||
#define D2UTABLE {0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4, \
|
||||
4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8, \
|
||||
8,8,8,8,8,9}
|
||||
#elif DECDPUN==7
|
||||
#define DECDPUNMAX 9999999
|
||||
#define D2UTABLE {0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3, \
|
||||
4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7, \
|
||||
7,7,7,7,7,7}
|
||||
#elif DECDPUN==8
|
||||
#define DECDPUNMAX 99999999
|
||||
#define D2UTABLE {0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3, \
|
||||
3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6, \
|
||||
6,6,6,6,6,7}
|
||||
#elif DECDPUN==9
|
||||
#define DECDPUNMAX 999999999
|
||||
#define D2UTABLE {0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3, \
|
||||
3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5, \
|
||||
5,5,6,6,6,6}
|
||||
#elif defined(DECDPUN)
|
||||
#error DECDPUN must be in the range 1-9
|
||||
#endif
|
||||
|
||||
/* ----- Shared data (in decNumber.c) ----- */
|
||||
/* Public lookup table used by the D2U macro (see below) */
|
||||
#define DECMAXD2U 49
|
||||
extern const uByte d2utable[DECMAXD2U+1];
|
||||
|
||||
/* ----- Macros ----- */
|
||||
/* ISZERO -- return true if decNumber dn is a zero */
|
||||
/* [performance-critical in some situations] */
|
||||
#define ISZERO(dn) decNumberIsZero(dn) /* now just a local name */
|
||||
|
||||
/* D2U -- return the number of Units needed to hold d digits */
|
||||
/* (runtime version, with table lookaside for small d) */
|
||||
#if DECDPUN==8
|
||||
#define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+7)>>3))
|
||||
#elif DECDPUN==4
|
||||
#define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+3)>>2))
|
||||
#else
|
||||
#define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
|
||||
#endif
|
||||
/* SD2U -- static D2U macro (for compile-time calculation) */
|
||||
#define SD2U(d) (((d)+DECDPUN-1)/DECDPUN)
|
||||
|
||||
/* MSUDIGITS -- returns digits in msu, from digits, calculated */
|
||||
/* using D2U */
|
||||
#define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
|
||||
|
||||
/* D2N -- return the number of decNumber structs that would be */
|
||||
/* needed to contain that number of digits (and the initial */
|
||||
/* decNumber struct) safely. Note that one Unit is included in the */
|
||||
/* initial structure. Used for allocating space that is aligned on */
|
||||
/* a decNumber struct boundary. */
|
||||
#define D2N(d) \
|
||||
((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber))
|
||||
|
||||
/* TODIGIT -- macro to remove the leading digit from the unsigned */
|
||||
/* integer u at column cut (counting from the right, LSD=0) and */
|
||||
/* place it as an ASCII character into the character pointed to by */
|
||||
/* c. Note that cut must be <= 9, and the maximum value for u is */
|
||||
/* 2,000,000,000 (as is needed for negative exponents of */
|
||||
/* subnormals). The unsigned integer pow is used as a temporary */
|
||||
/* variable. */
|
||||
#define TODIGIT(u, cut, c, pow) { \
|
||||
*(c)='0'; \
|
||||
pow=DECPOWERS[cut]*2; \
|
||||
if ((u)>pow) { \
|
||||
pow*=4; \
|
||||
if ((u)>=pow) {(u)-=pow; *(c)+=8;} \
|
||||
pow/=2; \
|
||||
if ((u)>=pow) {(u)-=pow; *(c)+=4;} \
|
||||
pow/=2; \
|
||||
} \
|
||||
if ((u)>=pow) {(u)-=pow; *(c)+=2;} \
|
||||
pow/=2; \
|
||||
if ((u)>=pow) {(u)-=pow; *(c)+=1;} \
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* Definitions for fixed-precision modules (only valid after */
|
||||
/* decSingle.h, decDouble.h, or decQuad.h has been included) */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
/* bcdnum -- a structure describing a format-independent finite */
|
||||
/* number, whose coefficient is a string of bcd8 uBytes */
|
||||
typedef struct {
|
||||
uByte *msd; /* -> most significant digit */
|
||||
uByte *lsd; /* -> least ditto */
|
||||
uInt sign; /* 0=positive, DECFLOAT_Sign=negative */
|
||||
Int exponent; /* Unadjusted signed exponent (q), or */
|
||||
/* DECFLOAT_NaN etc. for a special */
|
||||
} bcdnum;
|
||||
|
||||
/* Test if exponent or bcdnum exponent must be a special, etc. */
|
||||
#define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp)
|
||||
#define EXPISINF(exp) (exp==DECFLOAT_Inf)
|
||||
#define EXPISNAN(exp) (exp==DECFLOAT_qNaN || exp==DECFLOAT_sNaN)
|
||||
#define NUMISSPECIAL(num) (EXPISSPECIAL((num)->exponent))
|
||||
|
||||
/* Refer to a 32-bit word or byte in a decFloat (df) by big-endian */
|
||||
/* (array) notation (the 0 word or byte contains the sign bit), */
|
||||
/* automatically adjusting for endianness; similarly address a word */
|
||||
/* in the next-wider format (decFloatWider, or dfw) */
|
||||
#define DECWORDS (DECBYTES/4)
|
||||
#define DECWWORDS (DECWBYTES/4)
|
||||
#if DECLITEND
|
||||
#define DFWORD(df, off) ((df)->words[DECWORDS-1-(off)])
|
||||
#define DFBYTE(df, off) ((df)->bytes[DECBYTES-1-(off)])
|
||||
#define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)])
|
||||
#else
|
||||
#define DFWORD(df, off) ((df)->words[off])
|
||||
#define DFBYTE(df, off) ((df)->bytes[off])
|
||||
#define DFWWORD(dfw, off) ((dfw)->words[off])
|
||||
#endif
|
||||
|
||||
/* Tests for sign or specials, directly on DECFLOATs */
|
||||
#define DFISSIGNED(df) (DFWORD(df, 0)&0x80000000)
|
||||
#define DFISSPECIAL(df) ((DFWORD(df, 0)&0x78000000)==0x78000000)
|
||||
#define DFISINF(df) ((DFWORD(df, 0)&0x7c000000)==0x78000000)
|
||||
#define DFISNAN(df) ((DFWORD(df, 0)&0x7c000000)==0x7c000000)
|
||||
#define DFISQNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7c000000)
|
||||
#define DFISSNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7e000000)
|
||||
|
||||
/* Shared lookup tables */
|
||||
extern const uInt DECCOMBMSD[64]; /* Combination field -> MSD */
|
||||
extern const uInt DECCOMBFROM[48]; /* exp+msd -> Combination */
|
||||
|
||||
/* Private generic (utility) routine */
|
||||
#if DECCHECK || DECTRACE
|
||||
extern void decShowNum(const bcdnum *, const char *);
|
||||
#endif
|
||||
|
||||
/* Format-dependent macros and constants */
|
||||
#if defined(DECPMAX)
|
||||
|
||||
/* Useful constants */
|
||||
#define DECPMAX9 (ROUNDUP(DECPMAX, 9)/9) /* 'Pmax' in 10**9s */
|
||||
/* Top words for a zero */
|
||||
#define SINGLEZERO 0x22500000
|
||||
#define DOUBLEZERO 0x22380000
|
||||
#define QUADZERO 0x22080000
|
||||
/* [ZEROWORD is defined to be one of these in the DFISZERO macro] */
|
||||
|
||||
/* Format-dependent common tests: */
|
||||
/* DFISZERO -- test for (any) zero */
|
||||
/* DFISCCZERO -- test for coefficient continuation being zero */
|
||||
/* DFISCC01 -- test for coefficient contains only 0s and 1s */
|
||||
/* DFISINT -- test for finite and exponent q=0 */
|
||||
/* DFISUINT01 -- test for sign=0, finite, exponent q=0, and */
|
||||
/* MSD=0 or 1 */
|
||||
/* ZEROWORD is also defined here. */
|
||||
/* In DFISZERO the first test checks the least-significant word */
|
||||
/* (most likely to be non-zero); the penultimate tests MSD and */
|
||||
/* DPDs in the signword, and the final test excludes specials and */
|
||||
/* MSD>7. DFISINT similarly has to allow for the two forms of */
|
||||
/* MSD codes. DFISUINT01 only has to allow for one form of MSD */
|
||||
/* code. */
|
||||
#if DECPMAX==7
|
||||
#define ZEROWORD SINGLEZERO
|
||||
/* [test macros not needed except for Zero] */
|
||||
#define DFISZERO(df) ((DFWORD(df, 0)&0x1c0fffff)==0 \
|
||||
&& (DFWORD(df, 0)&0x60000000)!=0x60000000)
|
||||
#elif DECPMAX==16
|
||||
#define ZEROWORD DOUBLEZERO
|
||||
#define DFISZERO(df) ((DFWORD(df, 1)==0 \
|
||||
&& (DFWORD(df, 0)&0x1c03ffff)==0 \
|
||||
&& (DFWORD(df, 0)&0x60000000)!=0x60000000))
|
||||
#define DFISINT(df) ((DFWORD(df, 0)&0x63fc0000)==0x22380000 \
|
||||
||(DFWORD(df, 0)&0x7bfc0000)==0x6a380000)
|
||||
#define DFISUINT01(df) ((DFWORD(df, 0)&0xfbfc0000)==0x22380000)
|
||||
#define DFISCCZERO(df) (DFWORD(df, 1)==0 \
|
||||
&& (DFWORD(df, 0)&0x0003ffff)==0)
|
||||
#define DFISCC01(df) ((DFWORD(df, 0)&~0xfffc9124)==0 \
|
||||
&& (DFWORD(df, 1)&~0x49124491)==0)
|
||||
#elif DECPMAX==34
|
||||
#define ZEROWORD QUADZERO
|
||||
#define DFISZERO(df) ((DFWORD(df, 3)==0 \
|
||||
&& DFWORD(df, 2)==0 \
|
||||
&& DFWORD(df, 1)==0 \
|
||||
&& (DFWORD(df, 0)&0x1c003fff)==0 \
|
||||
&& (DFWORD(df, 0)&0x60000000)!=0x60000000))
|
||||
#define DFISINT(df) ((DFWORD(df, 0)&0x63ffc000)==0x22080000 \
|
||||
||(DFWORD(df, 0)&0x7bffc000)==0x6a080000)
|
||||
#define DFISUINT01(df) ((DFWORD(df, 0)&0xfbffc000)==0x22080000)
|
||||
#define DFISCCZERO(df) (DFWORD(df, 3)==0 \
|
||||
&& DFWORD(df, 2)==0 \
|
||||
&& DFWORD(df, 1)==0 \
|
||||
&& (DFWORD(df, 0)&0x00003fff)==0)
|
||||
|
||||
#define DFISCC01(df) ((DFWORD(df, 0)&~0xffffc912)==0 \
|
||||
&& (DFWORD(df, 1)&~0x44912449)==0 \
|
||||
&& (DFWORD(df, 2)&~0x12449124)==0 \
|
||||
&& (DFWORD(df, 3)&~0x49124491)==0)
|
||||
#endif
|
||||
|
||||
/* Macros to test if a certain 10 bits of a uInt or pair of uInts */
|
||||
/* are a canonical declet [higher or lower bits are ignored]. */
|
||||
/* declet is at offset 0 (from the right) in a uInt: */
|
||||
#define CANONDPD(dpd) (((dpd)&0x300)==0 || ((dpd)&0x6e)!=0x6e)
|
||||
/* declet is at offset k (a multiple of 2) in a uInt: */
|
||||
#define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0 \
|
||||
|| ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
|
||||
/* declet is at offset k (a multiple of 2) in a pair of uInts: */
|
||||
/* [the top 2 bits will always be in the more-significant uInt] */
|
||||
#define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0 \
|
||||
|| ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k))) \
|
||||
|| ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
|
||||
|
||||
/* Macro to test whether a full-length (length DECPMAX) BCD8 */
|
||||
/* coefficient is zero */
|
||||
/* test just the LSWord first, then the remainder */
|
||||
#if DECPMAX==7
|
||||
#define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0 \
|
||||
&& UINTAT((u)+DECPMAX-7)==0)
|
||||
#elif DECPMAX==16
|
||||
#define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0 \
|
||||
&& (UINTAT((u)+DECPMAX-8)+UINTAT((u)+DECPMAX-12) \
|
||||
+UINTAT((u)+DECPMAX-16))==0)
|
||||
#elif DECPMAX==34
|
||||
#define ISCOEFFZERO(u) (UINTAT((u)+DECPMAX-4)==0 \
|
||||
&& (UINTAT((u)+DECPMAX-8) +UINTAT((u)+DECPMAX-12) \
|
||||
+UINTAT((u)+DECPMAX-16)+UINTAT((u)+DECPMAX-20) \
|
||||
+UINTAT((u)+DECPMAX-24)+UINTAT((u)+DECPMAX-28) \
|
||||
+UINTAT((u)+DECPMAX-32)+USHORTAT((u)+DECPMAX-34))==0)
|
||||
#endif
|
||||
|
||||
/* Macros and masks for the exponent continuation field and MSD */
|
||||
/* Get the exponent continuation from a decFloat *df as an Int */
|
||||
#define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL)))
|
||||
/* Ditto, from the next-wider format */
|
||||
#define GETWECON(df) ((Int)((DFWWORD((df), 0)&0x03ffffff)>>(32-6-DECWECONL)))
|
||||
/* Get the biased exponent similarly */
|
||||
#define GETEXP(df) ((Int)(DECCOMBEXP[DFWORD((df), 0)>>26]+GETECON(df)))
|
||||
/* Get the unbiased exponent similarly */
|
||||
#define GETEXPUN(df) ((Int)GETEXP(df)-DECBIAS)
|
||||
/* Get the MSD similarly (as uInt) */
|
||||
#define GETMSD(df) (DECCOMBMSD[DFWORD((df), 0)>>26])
|
||||
|
||||
/* Compile-time computes of the exponent continuation field masks */
|
||||
/* full exponent continuation field: */
|
||||
#define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
|
||||
/* same, not including its first digit (the qNaN/sNaN selector): */
|
||||
#define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
|
||||
|
||||
/* Macros to decode the coefficient in a finite decFloat *df into */
|
||||
/* a BCD string (uByte *bcdin) of length DECPMAX uBytes */
|
||||
|
||||
/* In-line sequence to convert 10 bits at right end of uInt dpd */
|
||||
/* to three BCD8 digits starting at uByte u. Note that an extra */
|
||||
/* byte is written to the right of the three digits because this */
|
||||
/* moves four at a time for speed; the alternative macro moves */
|
||||
/* exactly three bytes */
|
||||
#define dpd2bcd8(u, dpd) { \
|
||||
UINTAT(u)=UINTAT(&DPD2BCD8[((dpd)&0x3ff)*4]);}
|
||||
|
||||
#define dpd2bcd83(u, dpd) { \
|
||||
*(u)=DPD2BCD8[((dpd)&0x3ff)*4]; \
|
||||
*(u+1)=DPD2BCD8[((dpd)&0x3ff)*4+1]; \
|
||||
*(u+2)=DPD2BCD8[((dpd)&0x3ff)*4+2];}
|
||||
|
||||
/* Decode the declets. After extracting each one, it is decoded */
|
||||
/* to BCD8 using a table lookup (also used for variable-length */
|
||||
/* decode). Each DPD decode is 3 bytes BCD8 plus a one-byte */
|
||||
/* length which is not used, here). Fixed-length 4-byte moves */
|
||||
/* are fast, however, almost everywhere, and so are used except */
|
||||
/* for the final three bytes (to avoid overrun). The code below */
|
||||
/* is 36 instructions for Doubles and about 70 for Quads, even */
|
||||
/* on IA32. */
|
||||
|
||||
/* Two macros are defined for each format: */
|
||||
/* GETCOEFF extracts the coefficient of the current format */
|
||||
/* GETWCOEFF extracts the coefficient of the next-wider format. */
|
||||
/* The latter is a copy of the next-wider GETCOEFF using DFWWORD. */
|
||||
|
||||
#if DECPMAX==7
|
||||
#define GETCOEFF(df, bcd) { \
|
||||
uInt sourhi=DFWORD(df, 0); \
|
||||
*(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
|
||||
dpd2bcd8(bcd+1, sourhi>>10); \
|
||||
dpd2bcd83(bcd+4, sourhi);}
|
||||
#define GETWCOEFF(df, bcd) { \
|
||||
uInt sourhi=DFWWORD(df, 0); \
|
||||
uInt sourlo=DFWWORD(df, 1); \
|
||||
*(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
|
||||
dpd2bcd8(bcd+1, sourhi>>8); \
|
||||
dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
|
||||
dpd2bcd8(bcd+7, sourlo>>20); \
|
||||
dpd2bcd8(bcd+10, sourlo>>10); \
|
||||
dpd2bcd83(bcd+13, sourlo);}
|
||||
|
||||
#elif DECPMAX==16
|
||||
#define GETCOEFF(df, bcd) { \
|
||||
uInt sourhi=DFWORD(df, 0); \
|
||||
uInt sourlo=DFWORD(df, 1); \
|
||||
*(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
|
||||
dpd2bcd8(bcd+1, sourhi>>8); \
|
||||
dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
|
||||
dpd2bcd8(bcd+7, sourlo>>20); \
|
||||
dpd2bcd8(bcd+10, sourlo>>10); \
|
||||
dpd2bcd83(bcd+13, sourlo);}
|
||||
#define GETWCOEFF(df, bcd) { \
|
||||
uInt sourhi=DFWWORD(df, 0); \
|
||||
uInt sourmh=DFWWORD(df, 1); \
|
||||
uInt sourml=DFWWORD(df, 2); \
|
||||
uInt sourlo=DFWWORD(df, 3); \
|
||||
*(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
|
||||
dpd2bcd8(bcd+1, sourhi>>4); \
|
||||
dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
|
||||
dpd2bcd8(bcd+7, sourmh>>16); \
|
||||
dpd2bcd8(bcd+10, sourmh>>6); \
|
||||
dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
|
||||
dpd2bcd8(bcd+16, sourml>>18); \
|
||||
dpd2bcd8(bcd+19, sourml>>8); \
|
||||
dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
|
||||
dpd2bcd8(bcd+25, sourlo>>20); \
|
||||
dpd2bcd8(bcd+28, sourlo>>10); \
|
||||
dpd2bcd83(bcd+31, sourlo);}
|
||||
|
||||
#elif DECPMAX==34
|
||||
#define GETCOEFF(df, bcd) { \
|
||||
uInt sourhi=DFWORD(df, 0); \
|
||||
uInt sourmh=DFWORD(df, 1); \
|
||||
uInt sourml=DFWORD(df, 2); \
|
||||
uInt sourlo=DFWORD(df, 3); \
|
||||
*(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
|
||||
dpd2bcd8(bcd+1, sourhi>>4); \
|
||||
dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
|
||||
dpd2bcd8(bcd+7, sourmh>>16); \
|
||||
dpd2bcd8(bcd+10, sourmh>>6); \
|
||||
dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
|
||||
dpd2bcd8(bcd+16, sourml>>18); \
|
||||
dpd2bcd8(bcd+19, sourml>>8); \
|
||||
dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
|
||||
dpd2bcd8(bcd+25, sourlo>>20); \
|
||||
dpd2bcd8(bcd+28, sourlo>>10); \
|
||||
dpd2bcd83(bcd+31, sourlo);}
|
||||
|
||||
#define GETWCOEFF(df, bcd) {??} /* [should never be used] */
|
||||
#endif
|
||||
|
||||
/* Macros to decode the coefficient in a finite decFloat *df into */
|
||||
/* a base-billion uInt array, with the least-significant */
|
||||
/* 0-999999999 'digit' at offset 0. */
|
||||
|
||||
/* Decode the declets. After extracting each one, it is decoded */
|
||||
/* to binary using a table lookup. Three tables are used; one */
|
||||
/* the usual DPD to binary, the other two pre-multiplied by 1000 */
|
||||
/* and 1000000 to avoid multiplication during decode. These */
|
||||
/* tables can also be used for multiplying up the MSD as the DPD */
|
||||
/* code for 0 through 9 is the identity. */
|
||||
#define DPD2BIN0 DPD2BIN /* for prettier code */
|
||||
|
||||
#if DECPMAX==7
|
||||
#define GETCOEFFBILL(df, buf) { \
|
||||
uInt sourhi=DFWORD(df, 0); \
|
||||
(buf)[0]=DPD2BIN0[sourhi&0x3ff] \
|
||||
+DPD2BINK[(sourhi>>10)&0x3ff] \
|
||||
+DPD2BINM[DECCOMBMSD[sourhi>>26]];}
|
||||
|
||||
#elif DECPMAX==16
|
||||
#define GETCOEFFBILL(df, buf) { \
|
||||
uInt sourhi, sourlo; \
|
||||
sourlo=DFWORD(df, 1); \
|
||||
(buf)[0]=DPD2BIN0[sourlo&0x3ff] \
|
||||
+DPD2BINK[(sourlo>>10)&0x3ff] \
|
||||
+DPD2BINM[(sourlo>>20)&0x3ff]; \
|
||||
sourhi=DFWORD(df, 0); \
|
||||
(buf)[1]=DPD2BIN0[((sourhi<<2) | (sourlo>>30))&0x3ff] \
|
||||
+DPD2BINK[(sourhi>>8)&0x3ff] \
|
||||
+DPD2BINM[DECCOMBMSD[sourhi>>26]];}
|
||||
|
||||
#elif DECPMAX==34
|
||||
#define GETCOEFFBILL(df, buf) { \
|
||||
uInt sourhi, sourmh, sourml, sourlo; \
|
||||
sourlo=DFWORD(df, 3); \
|
||||
(buf)[0]=DPD2BIN0[sourlo&0x3ff] \
|
||||
+DPD2BINK[(sourlo>>10)&0x3ff] \
|
||||
+DPD2BINM[(sourlo>>20)&0x3ff]; \
|
||||
sourml=DFWORD(df, 2); \
|
||||
(buf)[1]=DPD2BIN0[((sourml<<2) | (sourlo>>30))&0x3ff] \
|
||||
+DPD2BINK[(sourml>>8)&0x3ff] \
|
||||
+DPD2BINM[(sourml>>18)&0x3ff]; \
|
||||
sourmh=DFWORD(df, 1); \
|
||||
(buf)[2]=DPD2BIN0[((sourmh<<4) | (sourml>>28))&0x3ff] \
|
||||
+DPD2BINK[(sourmh>>6)&0x3ff] \
|
||||
+DPD2BINM[(sourmh>>16)&0x3ff]; \
|
||||
sourhi=DFWORD(df, 0); \
|
||||
(buf)[3]=DPD2BIN0[((sourhi<<6) | (sourmh>>26))&0x3ff] \
|
||||
+DPD2BINK[(sourhi>>4)&0x3ff] \
|
||||
+DPD2BINM[DECCOMBMSD[sourhi>>26]];}
|
||||
|
||||
#endif
|
||||
|
||||
/* Macros to decode the coefficient in a finite decFloat *df into */
|
||||
/* a base-thousand uInt array, with the least-significant 0-999 */
|
||||
/* 'digit' at offset 0. */
|
||||
|
||||
/* Decode the declets. After extracting each one, it is decoded */
|
||||
/* to binary using a table lookup. */
|
||||
#if DECPMAX==7
|
||||
#define GETCOEFFTHOU(df, buf) { \
|
||||
uInt sourhi=DFWORD(df, 0); \
|
||||
(buf)[0]=DPD2BIN[sourhi&0x3ff]; \
|
||||
(buf)[1]=DPD2BIN[(sourhi>>10)&0x3ff]; \
|
||||
(buf)[2]=DECCOMBMSD[sourhi>>26];}
|
||||
|
||||
#elif DECPMAX==16
|
||||
#define GETCOEFFTHOU(df, buf) { \
|
||||
uInt sourhi, sourlo; \
|
||||
sourlo=DFWORD(df, 1); \
|
||||
(buf)[0]=DPD2BIN[sourlo&0x3ff]; \
|
||||
(buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
|
||||
(buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
|
||||
sourhi=DFWORD(df, 0); \
|
||||
(buf)[3]=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \
|
||||
(buf)[4]=DPD2BIN[(sourhi>>8)&0x3ff]; \
|
||||
(buf)[5]=DECCOMBMSD[sourhi>>26];}
|
||||
|
||||
#elif DECPMAX==34
|
||||
#define GETCOEFFTHOU(df, buf) { \
|
||||
uInt sourhi, sourmh, sourml, sourlo; \
|
||||
sourlo=DFWORD(df, 3); \
|
||||
(buf)[0]=DPD2BIN[sourlo&0x3ff]; \
|
||||
(buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
|
||||
(buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
|
||||
sourml=DFWORD(df, 2); \
|
||||
(buf)[3]=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \
|
||||
(buf)[4]=DPD2BIN[(sourml>>8)&0x3ff]; \
|
||||
(buf)[5]=DPD2BIN[(sourml>>18)&0x3ff]; \
|
||||
sourmh=DFWORD(df, 1); \
|
||||
(buf)[6]=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \
|
||||
(buf)[7]=DPD2BIN[(sourmh>>6)&0x3ff]; \
|
||||
(buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff]; \
|
||||
sourhi=DFWORD(df, 0); \
|
||||
(buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \
|
||||
(buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff]; \
|
||||
(buf)[11]=DECCOMBMSD[sourhi>>26];}
|
||||
|
||||
#endif
|
||||
|
||||
/* Set a decFloat to the maximum positive finite number (Nmax) */
|
||||
#if DECPMAX==7
|
||||
#define DFSETNMAX(df) \
|
||||
{DFWORD(df, 0)=0x77f3fcff;}
|
||||
#elif DECPMAX==16
|
||||
#define DFSETNMAX(df) \
|
||||
{DFWORD(df, 0)=0x77fcff3f; \
|
||||
DFWORD(df, 1)=0xcff3fcff;}
|
||||
#elif DECPMAX==34
|
||||
#define DFSETNMAX(df) \
|
||||
{DFWORD(df, 0)=0x77ffcff3; \
|
||||
DFWORD(df, 1)=0xfcff3fcf; \
|
||||
DFWORD(df, 2)=0xf3fcff3f; \
|
||||
DFWORD(df, 3)=0xcff3fcff;}
|
||||
#endif
|
||||
|
||||
/* [end of format-dependent macros and constants] */
|
||||
#endif
|
||||
|
||||
#endif
|
99
include/libdecnumber/dpd/decimal128.h
Normal file
99
include/libdecnumber/dpd/decimal128.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* Decimal 128-bit format module header for the decNumber C Library.
|
||||
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
|
||||
Contributed by IBM Corporation. Author Mike Cowlishaw.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Decimal 128-bit format module header */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#ifndef DECIMAL128_H
|
||||
#define DECIMAL128_H
|
||||
|
||||
#define DEC128NAME "decimal128" /* Short name */
|
||||
#define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */
|
||||
#define DEC128AUTHOR "Mike Cowlishaw" /* Who to blame */
|
||||
|
||||
/* parameters for decimal128s */
|
||||
#define DECIMAL128_Bytes 16 /* length */
|
||||
#define DECIMAL128_Pmax 34 /* maximum precision (digits) */
|
||||
#define DECIMAL128_Emax 6144 /* maximum adjusted exponent */
|
||||
#define DECIMAL128_Emin -6143 /* minimum adjusted exponent */
|
||||
#define DECIMAL128_Bias 6176 /* bias for the exponent */
|
||||
#define DECIMAL128_String 43 /* maximum string length, +1 */
|
||||
#define DECIMAL128_EconL 12 /* exp. continuation length */
|
||||
/* highest biased exponent (Elimit-1) */
|
||||
#define DECIMAL128_Ehigh (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
|
||||
|
||||
/* check enough digits, if pre-defined */
|
||||
#if defined(DECNUMDIGITS)
|
||||
#if (DECNUMDIGITS<DECIMAL128_Pmax)
|
||||
#error decimal128.h needs pre-defined DECNUMDIGITS>=34 for safe use
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DECNUMDIGITS
|
||||
#define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/
|
||||
#endif
|
||||
#include "libdecnumber/decNumber.h"
|
||||
|
||||
/* Decimal 128-bit type, accessible by bytes */
|
||||
typedef struct {
|
||||
uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/
|
||||
} decimal128;
|
||||
|
||||
/* special values [top byte excluding sign bit; last two bits are */
|
||||
/* don't-care for Infinity on input, last bit don't-care for NaN] */
|
||||
#if !defined(DECIMAL_NaN)
|
||||
#define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
|
||||
#define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
|
||||
#define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
|
||||
#endif
|
||||
|
||||
#include "decimal128Local.h"
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* Routines */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* String conversions */
|
||||
decimal128 * decimal128FromString(decimal128 *, const char *, decContext *);
|
||||
char * decimal128ToString(const decimal128 *, char *);
|
||||
char * decimal128ToEngString(const decimal128 *, char *);
|
||||
|
||||
/* decNumber conversions */
|
||||
decimal128 * decimal128FromNumber(decimal128 *, const decNumber *,
|
||||
decContext *);
|
||||
decNumber * decimal128ToNumber(const decimal128 *, decNumber *);
|
||||
|
||||
/* Format-dependent utilities */
|
||||
uint32_t decimal128IsCanonical(const decimal128 *);
|
||||
decimal128 * decimal128Canonical(decimal128 *, const decimal128 *);
|
||||
|
||||
#endif
|
47
include/libdecnumber/dpd/decimal128Local.h
Normal file
47
include/libdecnumber/dpd/decimal128Local.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* Local definitions for use with the decNumber C Library.
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
#if !defined(DECIMAL128LOCAL)
|
||||
|
||||
/* The compiler needs sign manipulation functions for decimal128 which
|
||||
are not part of the decNumber package. */
|
||||
|
||||
/* Set sign; this assumes the sign was previously zero. */
|
||||
#define decimal128SetSign(d,b) \
|
||||
{ (d)->bytes[WORDS_BIGENDIAN ? 0 : 15] |= ((unsigned) (b) << 7); }
|
||||
|
||||
/* Clear sign. */
|
||||
#define decimal128ClearSign(d) \
|
||||
{ (d)->bytes[WORDS_BIGENDIAN ? 0 : 15] &= ~0x80; }
|
||||
|
||||
/* Flip sign. */
|
||||
#define decimal128FlipSign(d) \
|
||||
{ (d)->bytes[WORDS_BIGENDIAN ? 0 : 15] ^= 0x80; }
|
||||
|
||||
#endif
|
97
include/libdecnumber/dpd/decimal32.h
Normal file
97
include/libdecnumber/dpd/decimal32.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* Decimal 32-bit format module header for the decNumber C Library.
|
||||
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
|
||||
Contributed by IBM Corporation. Author Mike Cowlishaw.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Decimal 32-bit format module header */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#ifndef DECIMAL32_H
|
||||
#define DECIMAL32_H
|
||||
|
||||
#define DEC32NAME "decimal32" /* Short name */
|
||||
#define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */
|
||||
#define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */
|
||||
|
||||
/* parameters for decimal32s */
|
||||
#define DECIMAL32_Bytes 4 /* length */
|
||||
#define DECIMAL32_Pmax 7 /* maximum precision (digits) */
|
||||
#define DECIMAL32_Emax 96 /* maximum adjusted exponent */
|
||||
#define DECIMAL32_Emin -95 /* minimum adjusted exponent */
|
||||
#define DECIMAL32_Bias 101 /* bias for the exponent */
|
||||
#define DECIMAL32_String 15 /* maximum string length, +1 */
|
||||
#define DECIMAL32_EconL 6 /* exp. continuation length */
|
||||
/* highest biased exponent (Elimit-1) */
|
||||
#define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1)
|
||||
|
||||
/* check enough digits, if pre-defined */
|
||||
#if defined(DECNUMDIGITS)
|
||||
#if (DECNUMDIGITS<DECIMAL32_Pmax)
|
||||
#error decimal32.h needs pre-defined DECNUMDIGITS>=7 for safe use
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DECNUMDIGITS
|
||||
#define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/
|
||||
#endif
|
||||
#include "libdecnumber/decNumber.h"
|
||||
|
||||
/* Decimal 32-bit type, accessible by bytes */
|
||||
typedef struct {
|
||||
uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/
|
||||
} decimal32;
|
||||
|
||||
/* special values [top byte excluding sign bit; last two bits are */
|
||||
/* don't-care for Infinity on input, last bit don't-care for NaN] */
|
||||
#if !defined(DECIMAL_NaN)
|
||||
#define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
|
||||
#define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
|
||||
#define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* Routines */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* String conversions */
|
||||
decimal32 * decimal32FromString(decimal32 *, const char *, decContext *);
|
||||
char * decimal32ToString(const decimal32 *, char *);
|
||||
char * decimal32ToEngString(const decimal32 *, char *);
|
||||
|
||||
/* decNumber conversions */
|
||||
decimal32 * decimal32FromNumber(decimal32 *, const decNumber *,
|
||||
decContext *);
|
||||
decNumber * decimal32ToNumber(const decimal32 *, decNumber *);
|
||||
|
||||
/* Format-dependent utilities */
|
||||
uint32_t decimal32IsCanonical(const decimal32 *);
|
||||
decimal32 * decimal32Canonical(decimal32 *, const decimal32 *);
|
||||
|
||||
#endif
|
99
include/libdecnumber/dpd/decimal64.h
Normal file
99
include/libdecnumber/dpd/decimal64.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* Decimal 64-bit format module header for the decNumber C Library.
|
||||
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
|
||||
Contributed by IBM Corporation. Author Mike Cowlishaw.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
In addition to the permissions in the GNU General Public License,
|
||||
the Free Software Foundation gives you unlimited permission to link
|
||||
the compiled version of this file into combinations with other
|
||||
programs, and to distribute those combinations without any
|
||||
restriction coming from the use of this file. (The General Public
|
||||
License restrictions do apply in other respects; for example, they
|
||||
cover modification of the file, and distribution when not linked
|
||||
into a combine executable.)
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301, USA. */
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Decimal 64-bit format module header */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#ifndef DECIMAL64_H
|
||||
#define DECIMAL64_H
|
||||
|
||||
#define DEC64NAME "decimal64" /* Short name */
|
||||
#define DEC64FULLNAME "Decimal 64-bit Number" /* Verbose name */
|
||||
#define DEC64AUTHOR "Mike Cowlishaw" /* Who to blame */
|
||||
|
||||
|
||||
/* parameters for decimal64s */
|
||||
#define DECIMAL64_Bytes 8 /* length */
|
||||
#define DECIMAL64_Pmax 16 /* maximum precision (digits) */
|
||||
#define DECIMAL64_Emax 384 /* maximum adjusted exponent */
|
||||
#define DECIMAL64_Emin -383 /* minimum adjusted exponent */
|
||||
#define DECIMAL64_Bias 398 /* bias for the exponent */
|
||||
#define DECIMAL64_String 24 /* maximum string length, +1 */
|
||||
#define DECIMAL64_EconL 8 /* exp. continuation length */
|
||||
/* highest biased exponent (Elimit-1) */
|
||||
#define DECIMAL64_Ehigh (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1)
|
||||
|
||||
/* check enough digits, if pre-defined */
|
||||
#if defined(DECNUMDIGITS)
|
||||
#if (DECNUMDIGITS<DECIMAL64_Pmax)
|
||||
#error decimal64.h needs pre-defined DECNUMDIGITS>=16 for safe use
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DECNUMDIGITS
|
||||
#define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined*/
|
||||
#endif
|
||||
#include "libdecnumber/decNumber.h"
|
||||
|
||||
/* Decimal 64-bit type, accessible by bytes */
|
||||
typedef struct {
|
||||
uint8_t bytes[DECIMAL64_Bytes]; /* decimal64: 1, 5, 8, 50 bits*/
|
||||
} decimal64;
|
||||
|
||||
/* special values [top byte excluding sign bit; last two bits are */
|
||||
/* don't-care for Infinity on input, last bit don't-care for NaN] */
|
||||
#if !defined(DECIMAL_NaN)
|
||||
#define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
|
||||
#define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
|
||||
#define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* Routines */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* String conversions */
|
||||
decimal64 * decimal64FromString(decimal64 *, const char *, decContext *);
|
||||
char * decimal64ToString(const decimal64 *, char *);
|
||||
char * decimal64ToEngString(const decimal64 *, char *);
|
||||
|
||||
/* decNumber conversions */
|
||||
decimal64 * decimal64FromNumber(decimal64 *, const decNumber *,
|
||||
decContext *);
|
||||
decNumber * decimal64ToNumber(const decimal64 *, decNumber *);
|
||||
|
||||
/* Format-dependent utilities */
|
||||
uint32_t decimal64IsCanonical(const decimal64 *);
|
||||
decimal64 * decimal64Canonical(decimal64 *, const decimal64 *);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue