PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/module/cmath/constant.py

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