-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_gmpq_include.h
executable file
·134 lines (109 loc) · 4.02 KB
/
math_gmpq_include.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*************************************************
Documentation of symbols defined by Math::GMPf
REQUIRED_LDBL_MANT_DIG : Defined to float.h's LDBL_MANT_DIG unless
LDBL_MANT_DIG is 106 (ie long double is
double-double) - in which case it is defined to
be 2098.
This is needed to ensure that the mpfr value is
an accurate rendition of the double-double value.
_WIN32_BIZARRE_INFNAN : Defined (on Windows only) when the perl version
(as expressed by $]) is less than 5.022.
These earlier perl versions generally stringified
NaNs as (-)1.#IND and Infs as (-)1.#INF.
The following can be used by the (internal) _mpf_get_* functions, which can
be called by Rmpq_get_NV:
#################################################
ULP_INDEX : The index of the mantissa's ULP (unit of least
precision) for perl's NV type (long double or
__float128). Value = REQUIRED_LDBL_MANT_DIG - 1,
except for DoubleDouble when it is set to 52 (ie
DBL_MANT_DIG - 1).
LOW_SUBNORMAL_EXP : Lowest subnormal exponent value for perl's NV type.
If the exponent is less than this value, then it
will be 0 when converted to an NV.
HIGH_SUBNORMAL_EXP : Highest subnormal exponent value for perl's NV type.
If the exponent is higher than this value, then it
will convert to a normalized NV.
#################################################
*************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <limits.h>
#include <float.h>
#if LDBL_MANT_DIG == 106
#define REQUIRED_LDBL_MANT_DIG 2098
#else
#define REQUIRED_LDBL_MANT_DIG LDBL_MANT_DIG
#endif
#if NVSIZE == 8 || (defined(USE_LONG_DOUBLE) && REQUIRED_LDBL_MANT_DIG == 2098)
#define ULP_INDEX 52
#define LOW_SUBNORMAL_EXP -1074
#define HIGH_SUBNORMAL_EXP -1021
#elif defined(USE_LONG_DOUBLE) && REQUIRED_LDBL_MANT_DIG == 64
#define ULP_INDEX 63
#define LOW_SUBNORMAL_EXP -16445
#define HIGH_SUBNORMAL_EXP -16381
#else
#define ULP_INDEX 112
#define LOW_SUBNORMAL_EXP -16494
#define HIGH_SUBNORMAL_EXP -16381
#endif
#if defined(USE_QUADMATH)
#include <quadmath.h>
#endif
/*
#ifdef _MSC_VER
#pragma warning(disable:4700 4715 4716)
#endif
*/
#if defined MATH_GMPQ_NEED_LONG_LONG_INT
#include <inttypes.h>
#endif
#ifdef OLDPERL
#define SvUOK SvIsUV
#endif
#ifndef Newx
# define Newx(v,n,t) New(0,v,n,t)
#endif
#ifndef Newxz
# define Newxz(v,n,t) Newz(0,v,n,t)
#endif
/* A perl bug in perl-5.20 onwards can break &PL_sv_yes and *
* &PL_sv_no. In the overload subs we therefore instead *
* use SvTRUE_nomg_NN where possible, which is available *
* beginning with perl-5.18.0. *
* Otherwise we continue using &PL_sv_yes as original *
* (&PL_sv_no is not used by this module.) *
* See See https://github.com/sisyphus/math-decimal64/pull/1 */
#if defined SvTRUE_nomg_NN
#define SWITCH_ARGS SvTRUE_nomg_NN(third)
#else
#define SWITCH_ARGS third==&PL_sv_yes
#endif
#define SV_IS_IOK(x) \
SvIOK(x)
#define SV_IS_POK(x) \
SvPOK(x)
#define SV_IS_NOK(x) \
SvNOK(x)
#define _overload_callback(_1st_arg,_2nd_arg,_3rd_arg) \
dSP; \
SV * ret; \
int count; \
char buf[32]; \
ENTER; \
PUSHMARK(SP); \
XPUSHs(b); \
XPUSHs(a); \
XPUSHs(sv_2mortal(_3rd_arg)); \
PUTBACK; \
sprintf(buf, "%s", _1st_arg); \
count = call_pv(buf, G_SCALAR); \
SPAGAIN; \
if (count != 1) \
croak("Error in %s callback to %s\n", _2nd_arg, _1st_arg); \
ret = POPs; \
SvREFCNT_inc(ret); \
LEAVE; \
return ret