]>
git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/src/third_party/duktape-1.8.0/src-separate/duk_replacements.c
2 * Replacements for missing platform functions.
4 * Unlike the originals, fpclassify() and signbit() replacements don't
5 * work on any floating point types, only doubles. The C typing here
6 * mimics the standard prototypes.
9 #include "duk_internal.h"
11 #if defined(DUK_USE_COMPUTED_NAN)
12 DUK_INTERNAL
double duk_computed_nan
;
15 #if defined(DUK_USE_COMPUTED_INFINITY)
16 DUK_INTERNAL
double duk_computed_infinity
;
19 #if defined(DUK_USE_REPL_FPCLASSIFY)
20 DUK_INTERNAL
int duk_repl_fpclassify(double x
) {
22 duk_uint_fast16_t expt
;
23 duk_small_int_t mzero
;
26 expt
= (duk_uint_fast16_t
) (u
.us
[DUK_DBL_IDX_US0
] & 0x7ff0UL
);
27 if (expt
> 0x0000UL
&& expt
< 0x7ff0UL
) {
28 /* expt values [0x001,0x7fe] = normal */
32 mzero
= (u
.ui
[DUK_DBL_IDX_UI1
] == 0 && (u
.ui
[DUK_DBL_IDX_UI0
] & 0x000fffffUL
) == 0);
33 if (expt
== 0x0000UL
) {
34 /* expt 0x000 is zero/subnormal */
38 return DUK_FP_SUBNORMAL
;
41 /* expt 0xfff is infinite/nan */
43 return DUK_FP_INFINITE
;
51 #if defined(DUK_USE_REPL_SIGNBIT)
52 DUK_INTERNAL
int duk_repl_signbit(double x
) {
55 return (int) (u
.uc
[DUK_DBL_IDX_UC0
] & 0x80UL
);
59 #if defined(DUK_USE_REPL_ISFINITE)
60 DUK_INTERNAL
int duk_repl_isfinite(double x
) {
61 int c
= DUK_FPCLASSIFY(x
);
62 if (c
== DUK_FP_NAN
|| c
== DUK_FP_INFINITE
) {
70 #if defined(DUK_USE_REPL_ISNAN)
71 DUK_INTERNAL
int duk_repl_isnan(double x
) {
72 int c
= DUK_FPCLASSIFY(x
);
73 return (c
== DUK_FP_NAN
);
77 #if defined(DUK_USE_REPL_ISINF)
78 DUK_INTERNAL
int duk_repl_isinf(double x
) {
79 int c
= DUK_FPCLASSIFY(x
);
80 return (c
== DUK_FP_INFINITE
);