3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2005 by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "That only makes eleven (plus one mislaid) and not fourteen, unless
13 * wizards count differently to other people."
17 =head1 Numeric functions
19 This file contains all the stuff needed by perl for manipulating numeric
20 values, including such things as replacements for the OS's atof() function
27 #define PERL_IN_NUMERIC_C
31 Perl_cast_ulong(pTHX_ NV f)
34 return f < I32_MIN ? (U32) I32_MIN : (U32)(I32) f;
37 if (f < U32_MAX_P1_HALF)
40 return ((U32) f) | (1 + U32_MAX >> 1);
45 return f > 0 ? U32_MAX : 0 /* NaN */;
49 Perl_cast_i32(pTHX_ NV f)
52 return f < I32_MIN ? I32_MIN : (I32) f;
55 if (f < U32_MAX_P1_HALF)
58 return (I32)(((U32) f) | (1 + U32_MAX >> 1));
63 return f > 0 ? (I32)U32_MAX : 0 /* NaN */;
67 Perl_cast_iv(pTHX_ NV f)
70 return f < IV_MIN ? IV_MIN : (IV) f;
73 /* For future flexibility allowing for sizeof(UV) >= sizeof(IV) */
74 if (f < UV_MAX_P1_HALF)
77 return (IV)(((UV) f) | (1 + UV_MAX >> 1));
82 return f > 0 ? (IV)UV_MAX : 0 /* NaN */;
86 Perl_cast_uv(pTHX_ NV f)
89 return f < IV_MIN ? (UV) IV_MIN : (UV)(IV) f;
92 if (f < UV_MAX_P1_HALF)
95 return ((UV) f) | (1 + UV_MAX >> 1);
100 return f > 0 ? UV_MAX : 0 /* NaN */;
103 #if defined(HUGE_VAL) || (defined(USE_LONG_DOUBLE) && defined(HUGE_VALL))
105 * This hack is to force load of "huge" support from libm.a
106 * So it is in perl for (say) POSIX to use.
107 * Needed for SunOS with Sun's 'acc' for example.
112 # if defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
122 converts a string representing a binary number to numeric form.
124 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
125 conversion flags, and I<result> should be NULL or a pointer to an NV.
126 The scan stops at the end of the string, or the first invalid character.
127 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
128 invalid character will also trigger a warning.
129 On return I<*len> is set to the length of the scanned string,
130 and I<*flags> gives output flags.
132 If the value is <= C<UV_MAX> it is returned as a UV, the output flags are clear,
133 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_bin>
134 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
135 and writes the value to I<*result> (or the value is discarded if I<result>
138 The binary number may optionally be prefixed with "0b" or "b" unless
139 C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
140 C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the binary
141 number may use '_' characters to separate digits.
147 Perl_grok_bin(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
148 const char *s = start;
153 const UV max_div_2 = UV_MAX / 2;
154 const bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES;
155 bool overflowed = FALSE;
158 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
159 /* strip off leading b or 0b.
160 for compatibility silently suffer "b" and "0b" as valid binary
167 else if (len >= 2 && s[0] == '0' && s[1] == 'b') {
174 for (; len-- && (bit = *s); s++) {
175 if (bit == '0' || bit == '1') {
176 /* Write it in this wonky order with a goto to attempt to get the
177 compiler to make the common case integer-only loop pretty tight.
178 With gcc seems to be much straighter code than old scan_bin. */
181 if (value <= max_div_2) {
182 value = (value << 1) | (bit - '0');
185 /* Bah. We're just overflowed. */
186 if (ckWARN_d(WARN_OVERFLOW))
187 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
188 "Integer overflow in binary number");
190 value_nv = (NV) value;
193 /* If an NV has not enough bits in its mantissa to
194 * represent a UV this summing of small low-order numbers
195 * is a waste of time (because the NV cannot preserve
196 * the low-order bits anyway): we could just remember when
197 * did we overflow and in the end just multiply value_nv by the
199 value_nv += (NV)(bit - '0');
202 if (bit == '_' && len && allow_underscores && (bit = s[1])
203 && (bit == '0' || bit == '1'))
209 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
210 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
211 "Illegal binary digit '%c' ignored", *s);
215 if ( ( overflowed && value_nv > 4294967295.0)
217 || (!overflowed && value > 0xffffffff )
220 if (ckWARN(WARN_PORTABLE))
221 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
222 "Binary number > 0b11111111111111111111111111111111 non-portable");
229 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
238 converts a string representing a hex number to numeric form.
240 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
241 conversion flags, and I<result> should be NULL or a pointer to an NV.
242 The scan stops at the end of the string, or the first invalid character.
243 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
244 invalid character will also trigger a warning.
245 On return I<*len> is set to the length of the scanned string,
246 and I<*flags> gives output flags.
248 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
249 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_hex>
250 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
251 and writes the value to I<*result> (or the value is discarded if I<result>
254 The hex number may optionally be prefixed with "0x" or "x" unless
255 C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
256 C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the hex
257 number may use '_' characters to separate digits.
263 Perl_grok_hex(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
265 const char *s = start;
270 const UV max_div_16 = UV_MAX / 16;
271 const bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES;
272 bool overflowed = FALSE;
273 const char *hexdigit;
275 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
276 /* strip off leading x or 0x.
277 for compatibility silently suffer "x" and "0x" as valid hex numbers.
284 else if (len >= 2 && s[0] == '0' && s[1] == 'x') {
291 for (; len-- && *s; s++) {
292 hexdigit = strchr(PL_hexdigit, *s);
294 /* Write it in this wonky order with a goto to attempt to get the
295 compiler to make the common case integer-only loop pretty tight.
296 With gcc seems to be much straighter code than old scan_hex. */
299 if (value <= max_div_16) {
300 value = (value << 4) | ((hexdigit - PL_hexdigit) & 15);
303 /* Bah. We're just overflowed. */
304 if (ckWARN_d(WARN_OVERFLOW))
305 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
306 "Integer overflow in hexadecimal number");
308 value_nv = (NV) value;
311 /* If an NV has not enough bits in its mantissa to
312 * represent a UV this summing of small low-order numbers
313 * is a waste of time (because the NV cannot preserve
314 * the low-order bits anyway): we could just remember when
315 * did we overflow and in the end just multiply value_nv by the
316 * right amount of 16-tuples. */
317 value_nv += (NV)((hexdigit - PL_hexdigit) & 15);
320 if (*s == '_' && len && allow_underscores && s[1]
321 && (hexdigit = strchr(PL_hexdigit, s[1])))
327 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
328 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
329 "Illegal hexadecimal digit '%c' ignored", *s);
333 if ( ( overflowed && value_nv > 4294967295.0)
335 || (!overflowed && value > 0xffffffff )
338 if (ckWARN(WARN_PORTABLE))
339 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
340 "Hexadecimal number > 0xffffffff non-portable");
347 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
356 converts a string representing an octal number to numeric form.
358 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
359 conversion flags, and I<result> should be NULL or a pointer to an NV.
360 The scan stops at the end of the string, or the first invalid character.
361 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
362 invalid character will also trigger a warning.
363 On return I<*len> is set to the length of the scanned string,
364 and I<*flags> gives output flags.
366 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
367 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_oct>
368 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
369 and writes the value to I<*result> (or the value is discarded if I<result>
372 If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the octal
373 number may use '_' characters to separate digits.
379 Perl_grok_oct(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
380 const char *s = start;
385 const UV max_div_8 = UV_MAX / 8;
386 const bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES;
387 bool overflowed = FALSE;
389 for (; len-- && *s; s++) {
390 /* gcc 2.95 optimiser not smart enough to figure that this subtraction
391 out front allows slicker code. */
392 int digit = *s - '0';
393 if (digit >= 0 && digit <= 7) {
394 /* Write it in this wonky order with a goto to attempt to get the
395 compiler to make the common case integer-only loop pretty tight.
399 if (value <= max_div_8) {
400 value = (value << 3) | digit;
403 /* Bah. We're just overflowed. */
404 if (ckWARN_d(WARN_OVERFLOW))
405 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
406 "Integer overflow in octal number");
408 value_nv = (NV) value;
411 /* If an NV has not enough bits in its mantissa to
412 * represent a UV this summing of small low-order numbers
413 * is a waste of time (because the NV cannot preserve
414 * the low-order bits anyway): we could just remember when
415 * did we overflow and in the end just multiply value_nv by the
416 * right amount of 8-tuples. */
417 value_nv += (NV)digit;
420 if (digit == ('_' - '0') && len && allow_underscores
421 && (digit = s[1] - '0') && (digit >= 0 && digit <= 7))
427 /* Allow \octal to work the DWIM way (that is, stop scanning
428 * as soon as non-octal characters are seen, complain only if
429 * someone seems to want to use the digits eight and nine). */
430 if (digit == 8 || digit == 9) {
431 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
432 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
433 "Illegal octal digit '%c' ignored", *s);
438 if ( ( overflowed && value_nv > 4294967295.0)
440 || (!overflowed && value > 0xffffffff )
443 if (ckWARN(WARN_PORTABLE))
444 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
445 "Octal number > 037777777777 non-portable");
452 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
461 For backwards compatibility. Use C<grok_bin> instead.
465 For backwards compatibility. Use C<grok_hex> instead.
469 For backwards compatibility. Use C<grok_oct> instead.
475 Perl_scan_bin(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
478 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
479 const UV ruv = grok_bin (start, &len, &flags, &rnv);
482 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
486 Perl_scan_oct(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
489 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
490 const UV ruv = grok_oct (start, &len, &flags, &rnv);
493 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
497 Perl_scan_hex(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
500 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
501 const UV ruv = grok_hex (start, &len, &flags, &rnv);
504 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
508 =for apidoc grok_numeric_radix
510 Scan and skip for a numeric decimal separator (radix).
515 Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
517 #ifdef USE_LOCALE_NUMERIC
518 if (PL_numeric_radix_sv && IN_LOCALE) {
520 const char* radix = SvPV(PL_numeric_radix_sv, len);
521 if (*sp + len <= send && memEQ(*sp, radix, len)) {
526 /* always try "." if numeric radix didn't match because
527 * we may have data from different locales mixed */
529 if (*sp < send && **sp == '.') {
537 =for apidoc grok_number
539 Recognise (or not) a number. The type of the number is returned
540 (0 if unrecognised), otherwise it is a bit-ORed combination of
541 IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
542 IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
544 If the value of the number can fit an in UV, it is returned in the *valuep
545 IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
546 will never be set unless *valuep is valid, but *valuep may have been assigned
547 to during processing even though IS_NUMBER_IN_UV is not set on return.
548 If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
549 valuep is non-NULL, but no actual assignment (or SEGV) will occur.
551 IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
552 seen (in which case *valuep gives the true value truncated to an integer), and
553 IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
554 absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
555 number is larger than a UV.
560 Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep)
563 const char *send = pv + len;
564 const UV max_div_10 = UV_MAX / 10;
565 const char max_mod_10 = UV_MAX % 10;
570 while (s < send && isSPACE(*s))
574 } else if (*s == '-') {
576 numtype = IS_NUMBER_NEG;
584 /* next must be digit or the radix separator or beginning of infinity */
586 /* UVs are at least 32 bits, so the first 9 decimal digits cannot
589 /* This construction seems to be more optimiser friendly.
590 (without it gcc does the isDIGIT test and the *s - '0' separately)
591 With it gcc on arm is managing 6 instructions (6 cycles) per digit.
592 In theory the optimiser could deduce how far to unroll the loop
593 before checking for overflow. */
595 int digit = *s - '0';
596 if (digit >= 0 && digit <= 9) {
597 value = value * 10 + digit;
600 if (digit >= 0 && digit <= 9) {
601 value = value * 10 + digit;
604 if (digit >= 0 && digit <= 9) {
605 value = value * 10 + digit;
608 if (digit >= 0 && digit <= 9) {
609 value = value * 10 + digit;
612 if (digit >= 0 && digit <= 9) {
613 value = value * 10 + digit;
616 if (digit >= 0 && digit <= 9) {
617 value = value * 10 + digit;
620 if (digit >= 0 && digit <= 9) {
621 value = value * 10 + digit;
624 if (digit >= 0 && digit <= 9) {
625 value = value * 10 + digit;
627 /* Now got 9 digits, so need to check
628 each time for overflow. */
630 while (digit >= 0 && digit <= 9
631 && (value < max_div_10
632 || (value == max_div_10
633 && digit <= max_mod_10))) {
634 value = value * 10 + digit;
640 if (digit >= 0 && digit <= 9
643 skip the remaining digits, don't
644 worry about setting *valuep. */
647 } while (s < send && isDIGIT(*s));
649 IS_NUMBER_GREATER_THAN_UV_MAX;
669 numtype |= IS_NUMBER_IN_UV;
674 if (GROK_NUMERIC_RADIX(&s, send)) {
675 numtype |= IS_NUMBER_NOT_INT;
676 while (s < send && isDIGIT(*s)) /* optional digits after the radix */
680 else if (GROK_NUMERIC_RADIX(&s, send)) {
681 numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */
682 /* no digits before the radix means we need digits after it */
683 if (s < send && isDIGIT(*s)) {
686 } while (s < send && isDIGIT(*s));
688 /* integer approximation is valid - it's 0. */
694 } else if (*s == 'I' || *s == 'i') {
695 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
696 s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
697 s++; if (s < send && (*s == 'I' || *s == 'i')) {
698 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
699 s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
700 s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
701 s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
705 } else if (*s == 'N' || *s == 'n') {
706 /* XXX TODO: There are signaling NaNs and quiet NaNs. */
707 s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
708 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
715 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
716 numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;
718 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
719 numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT;
720 } else if (s < send) {
721 /* we can have an optional exponent part */
722 if (*s == 'e' || *s == 'E') {
723 /* The only flag we keep is sign. Blow away any "it's UV" */
724 numtype &= IS_NUMBER_NEG;
725 numtype |= IS_NUMBER_NOT_INT;
727 if (s < send && (*s == '-' || *s == '+'))
729 if (s < send && isDIGIT(*s)) {
732 } while (s < send && isDIGIT(*s));
738 while (s < send && isSPACE(*s))
742 if (len == 10 && memEQ(pv, "0 but true", 10)) {
745 return IS_NUMBER_IN_UV;
751 S_mulexp10(NV value, I32 exponent)
763 /* On OpenVMS VAX we by default use the D_FLOAT double format,
764 * and that format does not have *easy* capabilities [1] for
765 * overflowing doubles 'silently' as IEEE fp does. We also need
766 * to support G_FLOAT on both VAX and Alpha, and though the exponent
767 * range is much larger than D_FLOAT it still doesn't do silent
768 * overflow. Therefore we need to detect early whether we would
769 * overflow (this is the behaviour of the native string-to-float
770 * conversion routines, and therefore of native applications, too).
772 * [1] Trying to establish a condition handler to trap floating point
773 * exceptions is not a good idea. */
775 /* In UNICOS and in certain Cray models (such as T90) there is no
776 * IEEE fp, and no way at all from C to catch fp overflows gracefully.
777 * There is something you can do if you are willing to use some
778 * inline assembler: the instruction is called DFI-- but that will
779 * disable *all* floating point interrupts, a little bit too large
780 * a hammer. Therefore we need to catch potential overflows before
783 #if ((defined(VMS) && !defined(__IEEE_FP)) || defined(_UNICOS)) && defined(NV_MAX_10_EXP)
785 NV exp_v = log10(value);
786 if (exponent >= NV_MAX_10_EXP || exponent + exp_v >= NV_MAX_10_EXP)
789 if (-(exponent + exp_v) >= NV_MAX_10_EXP)
791 while (-exponent >= NV_MAX_10_EXP) {
792 /* combination does not overflow, but 10^(-exponent) does */
802 exponent = -exponent;
804 for (bit = 1; exponent; bit <<= 1) {
805 if (exponent & bit) {
808 /* Floating point exceptions are supposed to be turned off,
809 * but if we're obviously done, don't risk another iteration.
811 if (exponent == 0) break;
815 return negative ? value / result : value * result;
819 Perl_my_atof(pTHX_ const char* s)
822 #ifdef USE_LOCALE_NUMERIC
823 if (PL_numeric_local && IN_LOCALE) {
826 /* Scan the number twice; once using locale and once without;
827 * choose the larger result (in absolute value). */
829 SET_NUMERIC_STANDARD();
832 if ((y < 0.0 && y < x) || (y > 0.0 && y > x))
844 Perl_my_atof2(pTHX_ const char* orig, NV* value)
846 NV result[3] = {0.0, 0.0, 0.0};
847 const char* s = orig;
849 UV accumulator[2] = {0,0}; /* before/after dp */
851 const char* send = s + strlen(orig) - 1;
853 I32 exp_adjust[2] = {0,0};
854 I32 exp_acc[2] = {-1, -1};
855 /* the current exponent adjust for the accumulators */
860 I32 sig_digits = 0; /* noof significant digits seen so far */
862 /* There is no point in processing more significant digits
863 * than the NV can hold. Note that NV_DIG is a lower-bound value,
864 * while we need an upper-bound value. We add 2 to account for this;
865 * since it will have been conservative on both the first and last digit.
866 * For example a 32-bit mantissa with an exponent of 4 would have
867 * exact values in the set
875 * where for the purposes of calculating NV_DIG we would have to discount
876 * both the first and last digit, since neither can hold all values from
877 * 0..9; but for calculating the value we must examine those two digits.
879 #define MAX_SIG_DIGITS (NV_DIG+2)
881 /* the max number we can accumulate in a UV, and still safely do 10*N+9 */
882 #define MAX_ACCUMULATE ( (UV) ((UV_MAX - 9)/10))
884 /* leading whitespace */
897 /* we accumulate digits into an integer; when this becomes too
898 * large, we add the total to NV and start again */
908 /* don't start counting until we see the first significant
909 * digit, eg the 5 in 0.00005... */
910 if (!sig_digits && digit == 0)
913 if (++sig_digits > MAX_SIG_DIGITS) {
914 /* limits of precision reached */
916 ++accumulator[seen_dp];
917 } else if (digit == 5) {
918 if (old_digit % 2) { /* round to even - Allen */
919 ++accumulator[seen_dp];
927 /* skip remaining digits */
928 while (isDIGIT(*s)) {
934 /* warn of loss of precision? */
937 if (accumulator[seen_dp] > MAX_ACCUMULATE) {
938 /* add accumulator to result and start again */
939 result[seen_dp] = S_mulexp10(result[seen_dp],
941 + (NV)accumulator[seen_dp];
942 accumulator[seen_dp] = 0;
943 exp_acc[seen_dp] = 0;
945 accumulator[seen_dp] = accumulator[seen_dp] * 10 + digit;
949 else if (!seen_dp && GROK_NUMERIC_RADIX(&s, send)) {
951 if (sig_digits > MAX_SIG_DIGITS) {
953 while (isDIGIT(*s)) {
964 result[0] = S_mulexp10(result[0], exp_acc[0]) + (NV)accumulator[0];
966 result[1] = S_mulexp10(result[1], exp_acc[1]) + (NV)accumulator[1];
969 if (seen_digit && (*s == 'e' || *s == 'E')) {
970 bool expnegative = 0;
981 exponent = exponent * 10 + (*s++ - '0');
983 exponent = -exponent;
988 /* now apply the exponent */
991 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0])
992 + S_mulexp10(result[1],exponent-exp_adjust[1]);
994 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0]);
997 /* now apply the sign */
999 result[2] = -result[2];
1000 #endif /* USE_PERL_ATOF */
1005 #if ! defined(HAS_MODFL) && defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
1007 Perl_my_modfl(long double x, long double *ip)
1010 return (x == *ip ? copysignl(0.0L, x) : x - *ip);
1014 #if ! defined(HAS_FREXPL) && defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
1016 Perl_my_frexpl(long double x, int *e) {
1017 *e = x == 0.0L ? 0 : ilogbl(x) + 1;
1018 return (scalbnl(x, -*e));
1024 * c-indentation-style: bsd
1026 * indent-tabs-mode: t
1029 * ex: set ts=8 sts=4 sw=4 noet: