Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

470 lines
12 KiB

- replace dtoa w/ David's gdtoa, version 2008-03-15 - provide proper dtoa locks - use the real strtof implementation - add strtold, __hdtoa, __hldtoa - add %a/%A support - don't lose precision in printf, don't round to double anymore - implement extended-precision versions of libc functions: fpclassify, isnan, isinf, signbit, isnormal, isfinite, now that the ieee.h is fixed - separate vax versions of strtof, and __hdtoa - add complex math support. added functions: cacos, casin, catan, ccos, csin, ctan, cacosh, casinh, catanh, ccosh, csinh, ctanh, cexp, clog, cabs, cpow, csqrt, carg, cimag, conj, cproj, creal, cacosf, casinf, catanf, ccosf, csinf, ctanf, cacoshf, casinhf, catanhf, ccoshf, csinhf, ctanhf, cexpf, clogf, cabsf, cpowf, csqrtf, cargf, cimagf, conjf, cprojf, crealf - add fdim, fmax, fmin - add log2. (adapted implementation e_log.c. could be more acruate & faster, but it's good enough for now) - remove wrappers & cruft in libm, supposed to work-around mistakes in SVID, etc.; use ieee versions. fixes issues in python 2.6 for djm@ - make _digittoint static - proper definitions for i386, and amd64 in ieee.h - sh, powerpc don't really have extended-precision - add missing definitions for mips64 (quad), m{6,8}k (96-bit) float.h for LDBL_* - merge lead to frac for m{6,8}k, for gdtoa to work properly - add FRAC*BITS & EXT_TO_ARRAY32 definitions in ieee.h, for hdtoa&ldtoa to use - add EXT_IMPLICIT_NBIT definition, which indicates implicit normalization bit - add regression tests for libc: fpclassify and printf - arith.h & gd_qnan.h definitions - update ieee.h: hppa doesn't have quad-precision, hppa64 does - add missing prototypes to gdtoaimp - on 64-bit platforms make sure gdtoa doesn't use a long when it really wants an int - etc., what i may have forgotten... - bump libm major, due to removed&changed symbols - no libc bump, since this is riding on djm's libc major crank from a day ago discussed with / requested by / testing theo, sthen@, djm@, jsg@, merdely@, jsing@, tedu@, brad@, jakemsr@, and others. looks good to millert@ parts of the diff ok kettenis@ this commit does not include: - man page changes
16 years ago
  1. /* $OpenBSD: math.h,v 1.22 2008/09/09 20:42:55 martynas Exp $ */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunPro, a Sun Microsystems, Inc. business.
  7. * Permission to use, copy, modify, and distribute this
  8. * software is freely granted, provided that this notice
  9. * is preserved.
  10. * ====================================================
  11. */
  12. /*
  13. * from: @(#)fdlibm.h 5.1 93/09/24
  14. */
  15. #ifndef _MATH_H_
  16. #define _MATH_H_
  17. #include <sys/_types.h>
  18. #include <sys/cdefs.h>
  19. #include <sys/limits.h>
  20. /*
  21. * ANSI/POSIX
  22. */
  23. extern char __infinity[];
  24. #define HUGE_VAL (*(double *)(void *)__infinity)
  25. /*
  26. * C99
  27. */
  28. #if __ISO_C_VISIBLE >= 1999
  29. typedef __double_t double_t;
  30. typedef __float_t float_t;
  31. #define HUGE_VALF ((float)HUGE_VAL)
  32. #define HUGE_VALL ((long double)HUGE_VAL)
  33. #define INFINITY HUGE_VALF
  34. #ifndef __vax__
  35. extern char __nan[];
  36. #define NAN (*(float *)(void *)__nan)
  37. #endif /* !__vax__ */
  38. #define FP_INFINITE 0x01
  39. #define FP_NAN 0x02
  40. #define FP_NORMAL 0x04
  41. #define FP_SUBNORMAL 0x08
  42. #define FP_ZERO 0x10
  43. #define FP_ILOGB0 (-INT_MAX)
  44. #define FP_ILOGBNAN INT_MAX
  45. #define fpclassify(x) \
  46. ((sizeof (x) == sizeof (float)) ? \
  47. __fpclassifyf(x) \
  48. : (sizeof (x) == sizeof (double)) ? \
  49. __fpclassify(x) \
  50. : __fpclassifyl(x))
  51. #define isfinite(x) \
  52. ((sizeof (x) == sizeof (float)) ? \
  53. __isfinitef(x) \
  54. : (sizeof (x) == sizeof (double)) ? \
  55. __isfinite(x) \
  56. : __isfinitel(x))
  57. #define isnormal(x) \
  58. ((sizeof (x) == sizeof (float)) ? \
  59. __isnormalf(x) \
  60. : (sizeof (x) == sizeof (double)) ? \
  61. __isnormal(x) \
  62. : __isnormall(x))
  63. #define signbit(x) \
  64. ((sizeof (x) == sizeof (float)) ? \
  65. __signbitf(x) \
  66. : (sizeof (x) == sizeof (double)) ? \
  67. __signbit(x) \
  68. : __signbitl(x))
  69. #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
  70. #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
  71. #define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
  72. #define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
  73. #define islessgreater(x, y) (!isunordered((x), (y)) && \
  74. ((x) > (y) || (y) > (x)))
  75. #define isunordered(x, y) (isnan(x) || isnan(y))
  76. #endif /* __ISO_C_VISIBLE >= 1999 */
  77. #define isinf(x) \
  78. ((sizeof (x) == sizeof (float)) ? \
  79. isinff(x) \
  80. : (sizeof (x) == sizeof (double)) ? \
  81. __isinf(x) \
  82. : __isinfl(x))
  83. #define isnan(x) \
  84. ((sizeof (x) == sizeof (float)) ? \
  85. isnanf(x) \
  86. : (sizeof (x) == sizeof (double)) ? \
  87. __isnan(x) \
  88. : __isnanl(x))
  89. /*
  90. * XOPEN/SVID
  91. */
  92. #if __BSD_VISIBLE || __XPG_VISIBLE
  93. #define M_E 2.7182818284590452354 /* e */
  94. #define M_LOG2E 1.4426950408889634074 /* log 2e */
  95. #define M_LOG10E 0.43429448190325182765 /* log 10e */
  96. #define M_LN2 0.69314718055994530942 /* log e2 */
  97. #define M_LN10 2.30258509299404568402 /* log e10 */
  98. #define M_PI 3.14159265358979323846 /* pi */
  99. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  100. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  101. #define M_1_PI 0.31830988618379067154 /* 1/pi */
  102. #define M_2_PI 0.63661977236758134308 /* 2/pi */
  103. #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  104. #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  105. #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  106. #ifdef __vax__
  107. #define MAXFLOAT ((float)1.70141173319264430e+38)
  108. #else
  109. #define MAXFLOAT ((float)3.40282346638528860e+38)
  110. #endif /* __vax__ */
  111. extern int signgam;
  112. #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
  113. #if __BSD_VISIBLE
  114. #define HUGE MAXFLOAT
  115. #endif /* __BSD_VISIBLE */
  116. __BEGIN_DECLS
  117. /*
  118. * ANSI/POSIX
  119. */
  120. extern double acos(double);
  121. extern double asin(double);
  122. extern double atan(double);
  123. extern double atan2(double, double);
  124. extern double cos(double);
  125. extern double sin(double);
  126. extern double tan(double);
  127. extern double cosh(double);
  128. extern double sinh(double);
  129. extern double tanh(double);
  130. extern double exp(double);
  131. extern double frexp(double, int *);
  132. extern double ldexp(double, int);
  133. extern double log(double);
  134. extern double log10(double);
  135. extern double modf(double, double *);
  136. extern double pow(double, double);
  137. extern double sqrt(double);
  138. extern double ceil(double);
  139. extern double fabs(double);
  140. extern double floor(double);
  141. extern double fmod(double, double);
  142. /*
  143. * C99
  144. */
  145. #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE
  146. extern double acosh(double);
  147. extern double asinh(double);
  148. extern double atanh(double);
  149. extern double exp2(double);
  150. extern double expm1(double);
  151. extern int ilogb(double);
  152. extern double log1p(double);
  153. extern double log2(double);
  154. extern double logb(double);
  155. extern double scalbn(double, int);
  156. #if 0
  157. extern double scalbln(double, long int);
  158. #endif
  159. extern double cbrt(double);
  160. extern double hypot(double, double);
  161. extern double erf(double);
  162. extern double erfc(double);
  163. extern double lgamma(double);
  164. extern double tgamma(double);
  165. #if 0
  166. extern double nearbyint(double);
  167. #endif
  168. extern double rint(double);
  169. extern long int lrint(double);
  170. extern long long int llrint(double);
  171. extern double round(double);
  172. extern long int lround(double);
  173. extern long long int llround(double);
  174. extern double trunc(double);
  175. extern double remainder(double, double);
  176. extern double remquo(double, double, int *);
  177. extern double copysign(double, double);
  178. extern double nan(const char *);
  179. extern double nextafter(double, double);
  180. #if 0
  181. extern double nexttoward(double, long double);
  182. #endif
  183. extern double fdim(double, double);
  184. extern double fmax(double, double);
  185. extern double fmin(double, double);
  186. #if 0
  187. extern double fma(double, double, double);
  188. #endif
  189. #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE */
  190. #if __BSD_VISIBLE || __XPG_VISIBLE
  191. extern double j0(double);
  192. extern double j1(double);
  193. extern double jn(int, double);
  194. extern double scalb(double, double);
  195. extern double y0(double);
  196. extern double y1(double);
  197. extern double yn(int, double);
  198. #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
  199. #if __BSD_VISIBLE || __XPG_VISIBLE <= 500
  200. extern double gamma(double);
  201. #endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
  202. /*
  203. * BSD math library entry points
  204. */
  205. #if __BSD_VISIBLE
  206. extern double drem(double, double);
  207. extern int finite(double);
  208. /*
  209. * Reentrant version of gamma & lgamma; passes signgam back by reference
  210. * as the second argument; user must allocate space for signgam.
  211. */
  212. extern double gamma_r(double, int *);
  213. extern double lgamma_r(double, int *);
  214. /*
  215. * IEEE Test Vector
  216. */
  217. extern double significand(double);
  218. #endif /* __BSD_VISIBLE */
  219. /*
  220. * Float versions of C99 functions
  221. */
  222. #if __ISO_C_VISIBLE >= 1999
  223. extern float acosf(float);
  224. extern float asinf(float);
  225. extern float atanf(float);
  226. extern float atan2f(float, float);
  227. extern float cosf(float);
  228. extern float sinf(float);
  229. extern float tanf(float);
  230. extern float acoshf(float);
  231. extern float asinhf(float);
  232. extern float atanhf(float);
  233. extern float coshf(float);
  234. extern float sinhf(float);
  235. extern float tanhf(float);
  236. extern float expf(float);
  237. extern float exp2f(float);
  238. extern float expm1f(float);
  239. extern float frexpf(float, int *);
  240. extern int ilogbf(float);
  241. extern float ldexpf(float, int);
  242. extern float logf(float);
  243. extern float log10f(float);
  244. extern float log1pf(float);
  245. extern float log2f(float);
  246. extern float logbf(float);
  247. extern float modff(float, float *);
  248. extern float scalbnf(float, int);
  249. #if 0
  250. extern float scalblnf(float, long int);
  251. #endif
  252. extern float cbrtf(float);
  253. extern float fabsf(float);
  254. extern float hypotf(float, float);
  255. extern float powf(float, float);
  256. extern float sqrtf(float);
  257. extern float erff(float);
  258. extern float erfcf(float);
  259. extern float lgammaf(float);
  260. extern float tgammaf(float);
  261. extern float ceilf(float);
  262. extern float floorf(float);
  263. #if 0
  264. extern float nearbyintf(float);
  265. #endif
  266. extern float rintf(float);
  267. extern long int lrintf(float);
  268. extern long long int llrintf(float);
  269. extern float roundf(float);
  270. extern long int lroundf(float);
  271. extern long long int llroundf(float);
  272. extern float truncf(float);
  273. extern float fmodf(float, float);
  274. extern float remainderf(float, float);
  275. extern float remquof(float, float, int *);
  276. extern float copysignf(float, float);
  277. extern float nanf(const char *);
  278. extern float nextafterf(float, float);
  279. #if 0
  280. extern float nexttowardf(float, long double);
  281. #endif
  282. extern float fdimf(float, float);
  283. extern float fmaxf(float, float);
  284. extern float fminf(float, float);
  285. #if 0
  286. extern float fmaf(float, float, float);
  287. #endif
  288. #endif /* __ISO_C_VISIBLE >= 1999 */
  289. #if __BSD_VISIBLE || __XPG_VISIBLE
  290. extern float j0f(float);
  291. extern float j1f(float);
  292. extern float jnf(int, float);
  293. extern float scalbf(float, float);
  294. extern float y0f(float);
  295. extern float y1f(float);
  296. extern float ynf(int, float);
  297. #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
  298. #if __BSD_VISIBLE || __XPG_VISIBLE <= 500
  299. extern float gammaf(float);
  300. #endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
  301. /*
  302. * Float versions of BSD math library entry points
  303. */
  304. #if __BSD_VISIBLE
  305. extern float dremf(float, float);
  306. extern int finitef(float);
  307. extern int isinff(float);
  308. extern int isnanf(float);
  309. /*
  310. * Float versions of reentrant version of gamma & lgamma; passes
  311. * signgam back by reference as the second argument; user must
  312. * allocate space for signgam.
  313. */
  314. extern float gammaf_r(float, int *);
  315. extern float lgammaf_r(float, int *);
  316. /*
  317. * Float version of IEEE Test Vector
  318. */
  319. extern float significandf(float);
  320. #endif /* __BSD_VISIBLE */
  321. /*
  322. * Long double versions of C99 functions
  323. */
  324. #if __ISO_C_VISIBLE >= 1999
  325. #if 0
  326. extern long double acosl(long double);
  327. extern long double asinl(long double);
  328. extern long double atanl(long double);
  329. extern long double atan2l(long double, long double);
  330. extern long double cosl(long double);
  331. extern long double sinl(long double);
  332. extern long double tanl(long double);
  333. extern long double acoshl(long double);
  334. extern long double asinhl(long double);
  335. extern long double atanhl(long double);
  336. extern long double coshl(long double);
  337. extern long double sinhl(long double);
  338. extern long double tanhl(long double);
  339. extern long double expl(long double);
  340. extern long double exp2l(long double);
  341. extern long double expm1l(long double);
  342. extern long double frexpl(long double, int *);
  343. extern int ilogbl(long double);
  344. extern long double ldexpl(long double, int);
  345. extern long double logl(long double);
  346. extern long double log10l(long double);
  347. extern long double log1pl(long double);
  348. extern long double log2l(long double);
  349. extern long double logbl(long double);
  350. extern long double modfl(long double, long double *);
  351. extern long double scalbnl(long double, int);
  352. extern long double scalblnl(long double, long int);
  353. extern long double cbrtl(long double);
  354. extern long double fabsl(long double);
  355. extern long double hypotl(long double, long double);
  356. extern long double powl(long double, long double);
  357. extern long double sqrtl(long double);
  358. extern long double erfl(long double);
  359. extern long double erfcl(long double);
  360. extern long double lgammal(long double);
  361. extern long double tgammal(long double);
  362. extern long double ceill(long double);
  363. extern long double floorl(long double);
  364. extern long double nearbyintl(long double);
  365. extern long double rintl(long double);
  366. extern long int lrintl(long double);
  367. extern long long int llrintl(long double);
  368. extern long double roundl(long double);
  369. extern long int lroundl(long double);
  370. extern long long int llroundl(long double);
  371. extern long double truncl(long double);
  372. extern long double fmodl(long double, long double);
  373. extern long double remainderl(long double, long double);
  374. extern long double remquol(long double, long double, int *);
  375. extern long double copysignl(long double, long double);
  376. extern long double nanl(const char *);
  377. extern long double nextafterl(long double, long double);
  378. extern long double nexttowardl(long double, long double);
  379. extern long double fdiml(long double, long double);
  380. extern long double fmaxl(long double, long double);
  381. extern long double fminl(long double, long double);
  382. extern long double fmal(long double, long double, long double);
  383. #endif
  384. #endif /* __ISO_C_VISIBLE >= 1999 */
  385. /*
  386. * Library implementation
  387. */
  388. extern int __fpclassify(double);
  389. extern int __fpclassifyf(float);
  390. extern int __fpclassifyl(long double);
  391. extern int __isfinite(double);
  392. extern int __isfinitef(float);
  393. extern int __isfinitel(long double);
  394. extern int __isinf(double);
  395. extern int __isinfl(long double);
  396. extern int __isnan(double);
  397. extern int __isnanl(long double);
  398. extern int __isnormal(double);
  399. extern int __isnormalf(float);
  400. extern int __isnormall(long double);
  401. extern int __signbit(double);
  402. extern int __signbitf(float);
  403. extern int __signbitl(long double);
  404. #if __BSD_VISIBLE && defined(__vax__)
  405. extern double infnan(int);
  406. #endif /* __BSD_VISIBLE && defined(__vax__) */
  407. __END_DECLS
  408. #endif /* !_MATH_H_ */