Debian Codegraph @

rpython/rlib/constant.py

raw symbols SCIP
1 import math
2 from rpython.rtyper.tool import rffi_platform
3 from rpython.translator.tool.cbuild import ExternalCompilationInfo
4
5
6 class CConfig:
7 _compilation_info_ = ExternalCompilationInfo(includes=['float.h'])
8
9 DBL_MAX = rffi_platform.DefinedConstantDouble('DBL_MAX')
10 DBL_MIN = rffi_platform.DefinedConstantDouble('DBL_MIN')
11 DBL_MANT_DIG = rffi_platform.ConstantInteger('DBL_MANT_DIG')
12
13
14 for k, v in rffi_platform.configure(CConfig).items():
15 assert v is not None, "no value found for %r" % k
16 globals()[k] = v
17
18
19 assert 0.0 < DBL_MAX < (1e200*1e200)
20 assert math.isinf(DBL_MAX * 1.0001)
21 assert DBL_MIN > 0.0
22 assert DBL_MIN * (2**-53) == 0.0
23
24
25 # Constants.
26 M_LN2 = 0.6931471805599453094 # natural log of 2
27 M_LN10 = 2.302585092994045684 # natural log of 10
28
29
30 # CM_LARGE_DOUBLE is used to avoid spurious overflow in the sqrt, log,
31 # inverse trig and inverse hyperbolic trig functions. Its log is used in the
32 # evaluation of exp, cos, cosh, sin, sinh, tan, and tanh to avoid unecessary
33 # overflow.
34 CM_LARGE_DOUBLE = DBL_MAX/4.
35 CM_SQRT_LARGE_DOUBLE = math.sqrt(CM_LARGE_DOUBLE)
36 CM_LOG_LARGE_DOUBLE = math.log(CM_LARGE_DOUBLE)
37 CM_SQRT_DBL_MIN = math.sqrt(DBL_MIN)
38
39 # CM_SCALE_UP is an odd integer chosen such that multiplication by
40 # 2**CM_SCALE_UP is sufficient to turn a subnormal into a normal.
41 # CM_SCALE_DOWN is (-(CM_SCALE_UP+1)/2). These scalings are used to compute
42 # square roots accurately when the real and imaginary parts of the argument
43 # are subnormal.
44 CM_SCALE_UP = (2*(DBL_MANT_DIG/2) + 1)
45 CM_SCALE_DOWN = -(CM_SCALE_UP+1)/2