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 */;
106 converts a string representing a binary number to numeric form.
108 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
109 conversion flags, and I<result> should be NULL or a pointer to an NV.
110 The scan stops at the end of the string, or the first invalid character.
111 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
112 invalid character will also trigger a warning.
113 On return I<*len> is set to the length of the scanned string,
114 and I<*flags> gives output flags.
116 If the value is <= C<UV_MAX> it is returned as a UV, the output flags are clear,
117 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_bin>
118 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
119 and writes the value to I<*result> (or the value is discarded if I<result>
122 The binary number may optionally be prefixed with "0b" or "b" unless
123 C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
124 C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the binary
125 number may use '_' characters to separate digits.
131 Perl_grok_bin(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
132 const char *s = start;
137 const UV max_div_2 = UV_MAX / 2;
138 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
139 bool overflowed = FALSE;
142 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
143 /* strip off leading b or 0b.
144 for compatibility silently suffer "b" and "0b" as valid binary
151 else if (len >= 2 && s[0] == '0' && s[1] == 'b') {
158 for (; len-- && (bit = *s); s++) {
159 if (bit == '0' || bit == '1') {
160 /* Write it in this wonky order with a goto to attempt to get the
161 compiler to make the common case integer-only loop pretty tight.
162 With gcc seems to be much straighter code than old scan_bin. */
165 if (value <= max_div_2) {
166 value = (value << 1) | (bit - '0');
169 /* Bah. We're just overflowed. */
170 if (ckWARN_d(WARN_OVERFLOW))
171 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
172 "Integer overflow in binary number");
174 value_nv = (NV) value;
177 /* If an NV has not enough bits in its mantissa to
178 * represent a UV this summing of small low-order numbers
179 * is a waste of time (because the NV cannot preserve
180 * the low-order bits anyway): we could just remember when
181 * did we overflow and in the end just multiply value_nv by the
183 value_nv += (NV)(bit - '0');
186 if (bit == '_' && len && allow_underscores && (bit = s[1])
187 && (bit == '0' || bit == '1'))
193 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
194 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
195 "Illegal binary digit '%c' ignored", *s);
199 if ( ( overflowed && value_nv > 4294967295.0)
201 || (!overflowed && value > 0xffffffff )
204 if (ckWARN(WARN_PORTABLE))
205 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
206 "Binary number > 0b11111111111111111111111111111111 non-portable");
213 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
222 converts a string representing a hex number to numeric form.
224 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
225 conversion flags, and I<result> should be NULL or a pointer to an NV.
226 The scan stops at the end of the string, or the first invalid character.
227 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
228 invalid character will also trigger a warning.
229 On return I<*len> is set to the length of the scanned string,
230 and I<*flags> gives output flags.
232 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
233 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_hex>
234 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
235 and writes the value to I<*result> (or the value is discarded if I<result>
238 The hex number may optionally be prefixed with "0x" or "x" unless
239 C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
240 C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the hex
241 number may use '_' characters to separate digits.
247 Perl_grok_hex(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
249 const char *s = start;
254 const UV max_div_16 = UV_MAX / 16;
255 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
256 bool overflowed = FALSE;
258 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
259 /* strip off leading x or 0x.
260 for compatibility silently suffer "x" and "0x" as valid hex numbers.
267 else if (len >= 2 && s[0] == '0' && s[1] == 'x') {
274 for (; len-- && *s; s++) {
275 const char *hexdigit = strchr(PL_hexdigit, *s);
277 /* Write it in this wonky order with a goto to attempt to get the
278 compiler to make the common case integer-only loop pretty tight.
279 With gcc seems to be much straighter code than old scan_hex. */
282 if (value <= max_div_16) {
283 value = (value << 4) | ((hexdigit - PL_hexdigit) & 15);
286 /* Bah. We're just overflowed. */
287 if (ckWARN_d(WARN_OVERFLOW))
288 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
289 "Integer overflow in hexadecimal number");
291 value_nv = (NV) value;
294 /* If an NV has not enough bits in its mantissa to
295 * represent a UV this summing of small low-order numbers
296 * is a waste of time (because the NV cannot preserve
297 * the low-order bits anyway): we could just remember when
298 * did we overflow and in the end just multiply value_nv by the
299 * right amount of 16-tuples. */
300 value_nv += (NV)((hexdigit - PL_hexdigit) & 15);
303 if (*s == '_' && len && allow_underscores && s[1]
304 && (hexdigit = strchr(PL_hexdigit, s[1])))
310 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
311 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
312 "Illegal hexadecimal digit '%c' ignored", *s);
316 if ( ( overflowed && value_nv > 4294967295.0)
318 || (!overflowed && value > 0xffffffff )
321 if (ckWARN(WARN_PORTABLE))
322 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
323 "Hexadecimal number > 0xffffffff non-portable");
330 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
339 converts a string representing an octal number to numeric form.
341 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
342 conversion flags, and I<result> should be NULL or a pointer to an NV.
343 The scan stops at the end of the string, or the first invalid character.
344 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
345 invalid character will also trigger a warning.
346 On return I<*len> is set to the length of the scanned string,
347 and I<*flags> gives output flags.
349 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
350 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_oct>
351 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
352 and writes the value to I<*result> (or the value is discarded if I<result>
355 If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the octal
356 number may use '_' characters to separate digits.
362 Perl_grok_oct(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
363 const char *s = start;
368 const UV max_div_8 = UV_MAX / 8;
369 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
370 bool overflowed = FALSE;
372 for (; len-- && *s; s++) {
373 /* gcc 2.95 optimiser not smart enough to figure that this subtraction
374 out front allows slicker code. */
375 int digit = *s - '0';
376 if (digit >= 0 && digit <= 7) {
377 /* Write it in this wonky order with a goto to attempt to get the
378 compiler to make the common case integer-only loop pretty tight.
382 if (value <= max_div_8) {
383 value = (value << 3) | digit;
386 /* Bah. We're just overflowed. */
387 if (ckWARN_d(WARN_OVERFLOW))
388 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
389 "Integer overflow in octal number");
391 value_nv = (NV) value;
394 /* If an NV has not enough bits in its mantissa to
395 * represent a UV this summing of small low-order numbers
396 * is a waste of time (because the NV cannot preserve
397 * the low-order bits anyway): we could just remember when
398 * did we overflow and in the end just multiply value_nv by the
399 * right amount of 8-tuples. */
400 value_nv += (NV)digit;
403 if (digit == ('_' - '0') && len && allow_underscores
404 && (digit = s[1] - '0') && (digit >= 0 && digit <= 7))
410 /* Allow \octal to work the DWIM way (that is, stop scanning
411 * as soon as non-octal characters are seen, complain only if
412 * someone seems to want to use the digits eight and nine). */
413 if (digit == 8 || digit == 9) {
414 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
415 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
416 "Illegal octal digit '%c' ignored", *s);
421 if ( ( overflowed && value_nv > 4294967295.0)
423 || (!overflowed && value > 0xffffffff )
426 if (ckWARN(WARN_PORTABLE))
427 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
428 "Octal number > 037777777777 non-portable");
435 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
444 For backwards compatibility. Use C<grok_bin> instead.
448 For backwards compatibility. Use C<grok_hex> instead.
452 For backwards compatibility. Use C<grok_oct> instead.
458 Perl_scan_bin(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
461 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
462 const UV ruv = grok_bin (start, &len, &flags, &rnv);
465 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
469 Perl_scan_oct(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
472 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
473 const UV ruv = grok_oct (start, &len, &flags, &rnv);
476 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
480 Perl_scan_hex(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
483 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
484 const UV ruv = grok_hex (start, &len, &flags, &rnv);
487 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
491 =for apidoc grok_numeric_radix
493 Scan and skip for a numeric decimal separator (radix).
498 Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
500 #ifdef USE_LOCALE_NUMERIC
501 if (PL_numeric_radix_sv && IN_LOCALE) {
503 const char * const radix = SvPV(PL_numeric_radix_sv, len);
504 if (*sp + len <= send && memEQ(*sp, radix, len)) {
509 /* always try "." if numeric radix didn't match because
510 * we may have data from different locales mixed */
512 if (*sp < send && **sp == '.') {
520 =for apidoc grok_number
522 Recognise (or not) a number. The type of the number is returned
523 (0 if unrecognised), otherwise it is a bit-ORed combination of
524 IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
525 IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
527 If the value of the number can fit an in UV, it is returned in the *valuep
528 IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
529 will never be set unless *valuep is valid, but *valuep may have been assigned
530 to during processing even though IS_NUMBER_IN_UV is not set on return.
531 If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
532 valuep is non-NULL, but no actual assignment (or SEGV) will occur.
534 IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
535 seen (in which case *valuep gives the true value truncated to an integer), and
536 IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
537 absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
538 number is larger than a UV.
543 Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep)
546 const char * const send = pv + len;
547 const UV max_div_10 = UV_MAX / 10;
548 const char max_mod_10 = UV_MAX % 10;
553 while (s < send && isSPACE(*s))
557 } else if (*s == '-') {
559 numtype = IS_NUMBER_NEG;
567 /* next must be digit or the radix separator or beginning of infinity */
569 /* UVs are at least 32 bits, so the first 9 decimal digits cannot
572 /* This construction seems to be more optimiser friendly.
573 (without it gcc does the isDIGIT test and the *s - '0' separately)
574 With it gcc on arm is managing 6 instructions (6 cycles) per digit.
575 In theory the optimiser could deduce how far to unroll the loop
576 before checking for overflow. */
578 int digit = *s - '0';
579 if (digit >= 0 && digit <= 9) {
580 value = value * 10 + digit;
583 if (digit >= 0 && digit <= 9) {
584 value = value * 10 + digit;
587 if (digit >= 0 && digit <= 9) {
588 value = value * 10 + digit;
591 if (digit >= 0 && digit <= 9) {
592 value = value * 10 + digit;
595 if (digit >= 0 && digit <= 9) {
596 value = value * 10 + digit;
599 if (digit >= 0 && digit <= 9) {
600 value = value * 10 + digit;
603 if (digit >= 0 && digit <= 9) {
604 value = value * 10 + digit;
607 if (digit >= 0 && digit <= 9) {
608 value = value * 10 + digit;
610 /* Now got 9 digits, so need to check
611 each time for overflow. */
613 while (digit >= 0 && digit <= 9
614 && (value < max_div_10
615 || (value == max_div_10
616 && digit <= max_mod_10))) {
617 value = value * 10 + digit;
623 if (digit >= 0 && digit <= 9
626 skip the remaining digits, don't
627 worry about setting *valuep. */
630 } while (s < send && isDIGIT(*s));
632 IS_NUMBER_GREATER_THAN_UV_MAX;
652 numtype |= IS_NUMBER_IN_UV;
657 if (GROK_NUMERIC_RADIX(&s, send)) {
658 numtype |= IS_NUMBER_NOT_INT;
659 while (s < send && isDIGIT(*s)) /* optional digits after the radix */
663 else if (GROK_NUMERIC_RADIX(&s, send)) {
664 numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */
665 /* no digits before the radix means we need digits after it */
666 if (s < send && isDIGIT(*s)) {
669 } while (s < send && isDIGIT(*s));
671 /* integer approximation is valid - it's 0. */
677 } else if (*s == 'I' || *s == 'i') {
678 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
679 s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
680 s++; if (s < send && (*s == 'I' || *s == 'i')) {
681 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
682 s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
683 s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
684 s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
688 } else if (*s == 'N' || *s == 'n') {
689 /* XXX TODO: There are signaling NaNs and quiet NaNs. */
690 s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
691 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
698 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
699 numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;
701 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
702 numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT;
703 } else if (s < send) {
704 /* we can have an optional exponent part */
705 if (*s == 'e' || *s == 'E') {
706 /* The only flag we keep is sign. Blow away any "it's UV" */
707 numtype &= IS_NUMBER_NEG;
708 numtype |= IS_NUMBER_NOT_INT;
710 if (s < send && (*s == '-' || *s == '+'))
712 if (s < send && isDIGIT(*s)) {
715 } while (s < send && isDIGIT(*s));
721 while (s < send && isSPACE(*s))
725 if (len == 10 && memEQ(pv, "0 but true", 10)) {
728 return IS_NUMBER_IN_UV;
734 S_mulexp10(NV value, I32 exponent)
746 /* On OpenVMS VAX we by default use the D_FLOAT double format,
747 * and that format does not have *easy* capabilities [1] for
748 * overflowing doubles 'silently' as IEEE fp does. We also need
749 * to support G_FLOAT on both VAX and Alpha, and though the exponent
750 * range is much larger than D_FLOAT it still doesn't do silent
751 * overflow. Therefore we need to detect early whether we would
752 * overflow (this is the behaviour of the native string-to-float
753 * conversion routines, and therefore of native applications, too).
755 * [1] Trying to establish a condition handler to trap floating point
756 * exceptions is not a good idea. */
758 /* In UNICOS and in certain Cray models (such as T90) there is no
759 * IEEE fp, and no way at all from C to catch fp overflows gracefully.
760 * There is something you can do if you are willing to use some
761 * inline assembler: the instruction is called DFI-- but that will
762 * disable *all* floating point interrupts, a little bit too large
763 * a hammer. Therefore we need to catch potential overflows before
766 #if ((defined(VMS) && !defined(__IEEE_FP)) || defined(_UNICOS)) && defined(NV_MAX_10_EXP)
768 const NV exp_v = log10(value);
769 if (exponent >= NV_MAX_10_EXP || exponent + exp_v >= NV_MAX_10_EXP)
772 if (-(exponent + exp_v) >= NV_MAX_10_EXP)
774 while (-exponent >= NV_MAX_10_EXP) {
775 /* combination does not overflow, but 10^(-exponent) does */
785 exponent = -exponent;
787 for (bit = 1; exponent; bit <<= 1) {
788 if (exponent & bit) {
791 /* Floating point exceptions are supposed to be turned off,
792 * but if we're obviously done, don't risk another iteration.
794 if (exponent == 0) break;
798 return negative ? value / result : value * result;
802 Perl_my_atof(pTHX_ const char* s)
805 #ifdef USE_LOCALE_NUMERIC
806 if (PL_numeric_local && IN_LOCALE) {
809 /* Scan the number twice; once using locale and once without;
810 * choose the larger result (in absolute value). */
812 SET_NUMERIC_STANDARD();
815 if ((y < 0.0 && y < x) || (y > 0.0 && y > x))
827 Perl_my_atof2(pTHX_ const char* orig, NV* value)
829 NV result[3] = {0.0, 0.0, 0.0};
830 const char* s = orig;
832 UV accumulator[2] = {0,0}; /* before/after dp */
834 const char* send = s + strlen(orig) - 1;
836 I32 exp_adjust[2] = {0,0};
837 I32 exp_acc[2] = {-1, -1};
838 /* the current exponent adjust for the accumulators */
843 I32 sig_digits = 0; /* noof significant digits seen so far */
845 /* There is no point in processing more significant digits
846 * than the NV can hold. Note that NV_DIG is a lower-bound value,
847 * while we need an upper-bound value. We add 2 to account for this;
848 * since it will have been conservative on both the first and last digit.
849 * For example a 32-bit mantissa with an exponent of 4 would have
850 * exact values in the set
858 * where for the purposes of calculating NV_DIG we would have to discount
859 * both the first and last digit, since neither can hold all values from
860 * 0..9; but for calculating the value we must examine those two digits.
862 #define MAX_SIG_DIGITS (NV_DIG+2)
864 /* the max number we can accumulate in a UV, and still safely do 10*N+9 */
865 #define MAX_ACCUMULATE ( (UV) ((UV_MAX - 9)/10))
867 /* leading whitespace */
880 /* punt to strtod for NaN/Inf; if no support for it there, tough luck */
883 if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I') {
884 const char *p = negative ? s - 1 : s;
887 rslt = strtod(p, &endp);
895 /* we accumulate digits into an integer; when this becomes too
896 * large, we add the total to NV and start again */
906 /* don't start counting until we see the first significant
907 * digit, eg the 5 in 0.00005... */
908 if (!sig_digits && digit == 0)
911 if (++sig_digits > MAX_SIG_DIGITS) {
912 /* limits of precision reached */
914 ++accumulator[seen_dp];
915 } else if (digit == 5) {
916 if (old_digit % 2) { /* round to even - Allen */
917 ++accumulator[seen_dp];
925 /* skip remaining digits */
926 while (isDIGIT(*s)) {
932 /* warn of loss of precision? */
935 if (accumulator[seen_dp] > MAX_ACCUMULATE) {
936 /* add accumulator to result and start again */
937 result[seen_dp] = S_mulexp10(result[seen_dp],
939 + (NV)accumulator[seen_dp];
940 accumulator[seen_dp] = 0;
941 exp_acc[seen_dp] = 0;
943 accumulator[seen_dp] = accumulator[seen_dp] * 10 + digit;
947 else if (!seen_dp && GROK_NUMERIC_RADIX(&s, send)) {
949 if (sig_digits > MAX_SIG_DIGITS) {
951 while (isDIGIT(*s)) {
962 result[0] = S_mulexp10(result[0], exp_acc[0]) + (NV)accumulator[0];
964 result[1] = S_mulexp10(result[1], exp_acc[1]) + (NV)accumulator[1];
967 if (seen_digit && (*s == 'e' || *s == 'E')) {
968 bool expnegative = 0;
979 exponent = exponent * 10 + (*s++ - '0');
981 exponent = -exponent;
986 /* now apply the exponent */
989 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0])
990 + S_mulexp10(result[1],exponent-exp_adjust[1]);
992 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0]);
995 /* now apply the sign */
997 result[2] = -result[2];
998 #endif /* USE_PERL_ATOF */
1003 #if ! defined(HAS_MODFL) && defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
1005 Perl_my_modfl(long double x, long double *ip)
1008 return (x == *ip ? copysignl(0.0L, x) : x - *ip);
1012 #if ! defined(HAS_FREXPL) && defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
1014 Perl_my_frexpl(long double x, int *e) {
1015 *e = x == 0.0L ? 0 : ilogbl(x) + 1;
1016 return (scalbnl(x, -*e));
1022 * c-indentation-style: bsd
1024 * indent-tabs-mode: t
1027 * ex: set ts=8 sts=4 sw=4 noet: