summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2015-02-07 09:27:05 -0500
committerJarkko Hietaniemi <jhi@iki.fi>2015-02-08 21:54:49 -0500
commitb74dc0b3c96390d8bf83d8c3ffc0c2c2d1f0a5d3 (patch)
tree2981618c8ed1ec170fd9726bc176597ea4b39fd9 /numeric.c
parentc3a8e5a5b4bb89a15de642c023dfd5cbc4678938 (diff)
downloadperl-b74dc0b3c96390d8bf83d8c3ffc0c2c2d1f0a5d3.tar.gz
infnan: add nan_hibyte
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index a6f6018adc..16717aa412 100644
--- a/numeric.c
+++ b/numeric.c
@@ -548,6 +548,41 @@ Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
}
/*
+=for apidoc nan_hibyte
+
+Given an NV, returns pointer to the byte containing the most
+significant bit of the NaN, this bit is most commonly the
+quiet/signaling bit of the NaN. The mask will contain a mask
+appropriate for manipulating the most significant bit.
+Note that this bit may not be the highest bit of the byte.
+
+If the NV is not a NaN, returns NULL.
+
+Most platforms have "high bit is one" -> quiet nan.
+The known opposite exceptions are older MIPS and HPPA platforms.
+
+Some platforms do not differentiate between quiet and signaling NaNs.
+
+=cut
+*/
+U8*
+Perl_nan_hibyte(NV *nvp, U8* mask)
+{
+ STRLEN i = (NV_MANT_REAL_DIG - 1) / 8;
+ STRLEN j = (NV_MANT_REAL_DIG - 1) % 8;
+
+ PERL_ARGS_ASSERT_NAN_HIBYTE;
+
+ *mask = 1 << j;
+#ifdef NV_BIG_ENDIAN
+ return (U8*) nvp + NVSIZE - 1 - i;
+#endif
+#ifdef NV_LITTLE_ENDIAN
+ return (U8*) nvp + i;
+#endif
+}
+
+/*
=for apidoc grok_infnan
Helper for grok_number(), accepts various ways of spelling "infinity"