3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 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_ 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_ char *start, STRLEN *len_p, I32 *flags, NV *result) {
248 const char *s = start;
253 const UV max_div_16 = UV_MAX / 16;
254 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
255 bool overflowed = FALSE;
257 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
258 /* strip off leading x or 0x.
259 for compatibility silently suffer "x" and "0x" as valid hex numbers.
266 else if (len >= 2 && s[0] == '0' && s[1] == 'x') {
273 for (; len-- && *s; s++) {
274 const char *hexdigit = strchr(PL_hexdigit, *s);
276 /* Write it in this wonky order with a goto to attempt to get the
277 compiler to make the common case integer-only loop pretty tight.
278 With gcc seems to be much straighter code than old scan_hex. */
281 if (value <= max_div_16) {
282 value = (value << 4) | ((hexdigit - PL_hexdigit) & 15);
285 /* Bah. We're just overflowed. */
286 if (ckWARN_d(WARN_OVERFLOW))
287 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
288 "Integer overflow in hexadecimal number");
290 value_nv = (NV) value;
293 /* If an NV has not enough bits in its mantissa to
294 * represent a UV this summing of small low-order numbers
295 * is a waste of time (because the NV cannot preserve
296 * the low-order bits anyway): we could just remember when
297 * did we overflow and in the end just multiply value_nv by the
298 * right amount of 16-tuples. */
299 value_nv += (NV)((hexdigit - PL_hexdigit) & 15);
302 if (*s == '_' && len && allow_underscores && s[1]
303 && (hexdigit = strchr(PL_hexdigit, s[1])))
309 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
310 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
311 "Illegal hexadecimal digit '%c' ignored", *s);
315 if ( ( overflowed && value_nv > 4294967295.0)
317 || (!overflowed && value > 0xffffffff )
320 if (ckWARN(WARN_PORTABLE))
321 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
322 "Hexadecimal number > 0xffffffff non-portable");
329 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
338 converts a string representing an octal number to numeric form.
340 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
341 conversion flags, and I<result> should be NULL or a pointer to an NV.
342 The scan stops at the end of the string, or the first invalid character.
343 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
344 invalid character will also trigger a warning.
345 On return I<*len> is set to the length of the scanned string,
346 and I<*flags> gives output flags.
348 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
349 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_oct>
350 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
351 and writes the value to I<*result> (or the value is discarded if I<result>
354 If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the octal
355 number may use '_' characters to separate digits.
361 Perl_grok_oct(pTHX_ char *start, STRLEN *len_p, I32 *flags, NV *result) {
362 const char *s = start;
367 const UV max_div_8 = UV_MAX / 8;
368 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
369 bool overflowed = FALSE;
371 for (; len-- && *s; s++) {
372 /* gcc 2.95 optimiser not smart enough to figure that this subtraction
373 out front allows slicker code. */
374 int digit = *s - '0';
375 if (digit >= 0 && digit <= 7) {
376 /* Write it in this wonky order with a goto to attempt to get the
377 compiler to make the common case integer-only loop pretty tight.
381 if (value <= max_div_8) {
382 value = (value << 3) | digit;
385 /* Bah. We're just overflowed. */
386 if (ckWARN_d(WARN_OVERFLOW))
387 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
388 "Integer overflow in octal number");
390 value_nv = (NV) value;
393 /* If an NV has not enough bits in its mantissa to
394 * represent a UV this summing of small low-order numbers
395 * is a waste of time (because the NV cannot preserve
396 * the low-order bits anyway): we could just remember when
397 * did we overflow and in the end just multiply value_nv by the
398 * right amount of 8-tuples. */
399 value_nv += (NV)digit;
402 if (digit == ('_' - '0') && len && allow_underscores
403 && (digit = s[1] - '0') && (digit >= 0 && digit <= 7))
409 /* Allow \octal to work the DWIM way (that is, stop scanning
410 * as soon as non-octal characters are seen, complain only if
411 * someone seems to want to use the digits eight and nine). */
412 if (digit == 8 || digit == 9) {
413 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
414 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
415 "Illegal octal digit '%c' ignored", *s);
420 if ( ( overflowed && value_nv > 4294967295.0)
422 || (!overflowed && value > 0xffffffff )
425 if (ckWARN(WARN_PORTABLE))
426 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
427 "Octal number > 037777777777 non-portable");
434 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
443 For backwards compatibility. Use C<grok_bin> instead.
447 For backwards compatibility. Use C<grok_hex> instead.
451 For backwards compatibility. Use C<grok_oct> instead.
457 Perl_scan_bin(pTHX_ char *start, STRLEN len, STRLEN *retlen)
460 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
461 const UV ruv = grok_bin (start, &len, &flags, &rnv);
464 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
468 Perl_scan_oct(pTHX_ char *start, STRLEN len, STRLEN *retlen)
471 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
472 const UV ruv = grok_oct (start, &len, &flags, &rnv);
475 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
479 Perl_scan_hex(pTHX_ char *start, STRLEN len, STRLEN *retlen)
482 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
483 const UV ruv = grok_hex (start, &len, &flags, &rnv);
486 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
490 =for apidoc grok_numeric_radix
492 Scan and skip for a numeric decimal separator (radix).
497 Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
499 #ifdef USE_LOCALE_NUMERIC
500 if (PL_numeric_radix_sv && IN_LOCALE) {
502 const char * const radix = SvPV(PL_numeric_radix_sv, len);
503 if (*sp + len <= send && memEQ(*sp, radix, len)) {
508 /* always try "." if numeric radix didn't match because
509 * we may have data from different locales mixed */
511 if (*sp < send && **sp == '.') {
519 =for apidoc grok_number
521 Recognise (or not) a number. The type of the number is returned
522 (0 if unrecognised), otherwise it is a bit-ORed combination of
523 IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
524 IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
526 If the value of the number can fit an in UV, it is returned in the *valuep
527 IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
528 will never be set unless *valuep is valid, but *valuep may have been assigned
529 to during processing even though IS_NUMBER_IN_UV is not set on return.
530 If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
531 valuep is non-NULL, but no actual assignment (or SEGV) will occur.
533 IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
534 seen (in which case *valuep gives the true value truncated to an integer), and
535 IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
536 absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
537 number is larger than a UV.
542 Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep)
545 const char * const send = pv + len;
546 const UV max_div_10 = UV_MAX / 10;
547 const char max_mod_10 = UV_MAX % 10;
552 while (s < send && isSPACE(*s))
556 } else if (*s == '-') {
558 numtype = IS_NUMBER_NEG;
566 /* next must be digit or the radix separator or beginning of infinity */
568 /* UVs are at least 32 bits, so the first 9 decimal digits cannot
571 /* This construction seems to be more optimiser friendly.
572 (without it gcc does the isDIGIT test and the *s - '0' separately)
573 With it gcc on arm is managing 6 instructions (6 cycles) per digit.
574 In theory the optimiser could deduce how far to unroll the loop
575 before checking for overflow. */
577 int digit = *s - '0';
578 if (digit >= 0 && digit <= 9) {
579 value = value * 10 + digit;
582 if (digit >= 0 && digit <= 9) {
583 value = value * 10 + digit;
586 if (digit >= 0 && digit <= 9) {
587 value = value * 10 + digit;
590 if (digit >= 0 && digit <= 9) {
591 value = value * 10 + digit;
594 if (digit >= 0 && digit <= 9) {
595 value = value * 10 + digit;
598 if (digit >= 0 && digit <= 9) {
599 value = value * 10 + digit;
602 if (digit >= 0 && digit <= 9) {
603 value = value * 10 + digit;
606 if (digit >= 0 && digit <= 9) {
607 value = value * 10 + digit;
609 /* Now got 9 digits, so need to check
610 each time for overflow. */
612 while (digit >= 0 && digit <= 9
613 && (value < max_div_10
614 || (value == max_div_10
615 && digit <= max_mod_10))) {
616 value = value * 10 + digit;
622 if (digit >= 0 && digit <= 9
625 skip the remaining digits, don't
626 worry about setting *valuep. */
629 } while (s < send && isDIGIT(*s));
631 IS_NUMBER_GREATER_THAN_UV_MAX;
651 numtype |= IS_NUMBER_IN_UV;
656 if (GROK_NUMERIC_RADIX(&s, send)) {
657 numtype |= IS_NUMBER_NOT_INT;
658 while (s < send && isDIGIT(*s)) /* optional digits after the radix */
662 else if (GROK_NUMERIC_RADIX(&s, send)) {
663 numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */
664 /* no digits before the radix means we need digits after it */
665 if (s < send && isDIGIT(*s)) {
668 } while (s < send && isDIGIT(*s));
670 /* integer approximation is valid - it's 0. */
676 } else if (*s == 'I' || *s == 'i') {
677 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
678 s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
679 s++; if (s < send && (*s == 'I' || *s == 'i')) {
680 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
681 s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
682 s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
683 s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
687 } else if (*s == 'N' || *s == 'n') {
688 /* XXX TODO: There are signaling NaNs and quiet NaNs. */
689 s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
690 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
697 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
698 numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;
700 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
701 numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT;
702 } else if (s < send) {
703 /* we can have an optional exponent part */
704 if (*s == 'e' || *s == 'E') {
705 /* The only flag we keep is sign. Blow away any "it's UV" */
706 numtype &= IS_NUMBER_NEG;
707 numtype |= IS_NUMBER_NOT_INT;
709 if (s < send && (*s == '-' || *s == '+'))
711 if (s < send && isDIGIT(*s)) {
714 } while (s < send && isDIGIT(*s));
720 while (s < send && isSPACE(*s))
724 if (len == 10 && memEQ(pv, "0 but true", 10)) {
727 return IS_NUMBER_IN_UV;
733 S_mulexp10(NV value, I32 exponent)
745 /* On OpenVMS VAX we by default use the D_FLOAT double format,
746 * and that format does not have *easy* capabilities [1] for
747 * overflowing doubles 'silently' as IEEE fp does. We also need
748 * to support G_FLOAT on both VAX and Alpha, and though the exponent
749 * range is much larger than D_FLOAT it still doesn't do silent
750 * overflow. Therefore we need to detect early whether we would
751 * overflow (this is the behaviour of the native string-to-float
752 * conversion routines, and therefore of native applications, too).
754 * [1] Trying to establish a condition handler to trap floating point
755 * exceptions is not a good idea. */
757 /* In UNICOS and in certain Cray models (such as T90) there is no
758 * IEEE fp, and no way at all from C to catch fp overflows gracefully.
759 * There is something you can do if you are willing to use some
760 * inline assembler: the instruction is called DFI-- but that will
761 * disable *all* floating point interrupts, a little bit too large
762 * a hammer. Therefore we need to catch potential overflows before
765 #if ((defined(VMS) && !defined(__IEEE_FP)) || defined(_UNICOS)) && defined(NV_MAX_10_EXP)
767 const NV exp_v = log10(value);
768 if (exponent >= NV_MAX_10_EXP || exponent + exp_v >= NV_MAX_10_EXP)
771 if (-(exponent + exp_v) >= NV_MAX_10_EXP)
773 while (-exponent >= NV_MAX_10_EXP) {
774 /* combination does not overflow, but 10^(-exponent) does */
784 exponent = -exponent;
786 for (bit = 1; exponent; bit <<= 1) {
787 if (exponent & bit) {
790 /* Floating point exceptions are supposed to be turned off,
791 * but if we're obviously done, don't risk another iteration.
793 if (exponent == 0) break;
797 return negative ? value / result : value * result;
801 Perl_my_atof(pTHX_ const char* s)
804 #ifdef USE_LOCALE_NUMERIC
805 if (PL_numeric_local && IN_LOCALE) {
808 /* Scan the number twice; once using locale and once without;
809 * choose the larger result (in absolute value). */
811 SET_NUMERIC_STANDARD();
814 if ((y < 0.0 && y < x) || (y > 0.0 && y > x))
826 Perl_my_atof2(pTHX_ const char* orig, NV* value)
828 NV result[3] = {0.0, 0.0, 0.0};
829 const char* s = orig;
831 UV accumulator[2] = {0,0}; /* before/after dp */
833 const char* send = s + strlen(orig) - 1;
835 I32 exp_adjust[2] = {0,0};
836 I32 exp_acc[2] = {-1, -1};
837 /* the current exponent adjust for the accumulators */
842 I32 sig_digits = 0; /* noof significant digits seen so far */
844 /* There is no point in processing more significant digits
845 * than the NV can hold. Note that NV_DIG is a lower-bound value,
846 * while we need an upper-bound value. We add 2 to account for this;
847 * since it will have been conservative on both the first and last digit.
848 * For example a 32-bit mantissa with an exponent of 4 would have
849 * exact values in the set
857 * where for the purposes of calculating NV_DIG we would have to discount
858 * both the first and last digit, since neither can hold all values from
859 * 0..9; but for calculating the value we must examine those two digits.
861 #define MAX_SIG_DIGITS (NV_DIG+2)
863 /* the max number we can accumulate in a UV, and still safely do 10*N+9 */
864 #define MAX_ACCUMULATE ( (UV) ((UV_MAX - 9)/10))
866 /* leading whitespace */
879 /* punt to strtod for NaN/Inf; if no support for it there, tough luck */
882 if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I') {
883 const char *p = negative ? s - 1 : s;
886 rslt = strtod(p, &endp);
894 /* we accumulate digits into an integer; when this becomes too
895 * large, we add the total to NV and start again */
905 /* don't start counting until we see the first significant
906 * digit, eg the 5 in 0.00005... */
907 if (!sig_digits && digit == 0)
910 if (++sig_digits > MAX_SIG_DIGITS) {
911 /* limits of precision reached */
913 ++accumulator[seen_dp];
914 } else if (digit == 5) {
915 if (old_digit % 2) { /* round to even - Allen */
916 ++accumulator[seen_dp];
924 /* skip remaining digits */
925 while (isDIGIT(*s)) {
931 /* warn of loss of precision? */
934 if (accumulator[seen_dp] > MAX_ACCUMULATE) {
935 /* add accumulator to result and start again */
936 result[seen_dp] = S_mulexp10(result[seen_dp],
938 + (NV)accumulator[seen_dp];
939 accumulator[seen_dp] = 0;
940 exp_acc[seen_dp] = 0;
942 accumulator[seen_dp] = accumulator[seen_dp] * 10 + digit;
946 else if (!seen_dp && GROK_NUMERIC_RADIX(&s, send)) {
948 if (sig_digits > MAX_SIG_DIGITS) {
950 while (isDIGIT(*s)) {
961 result[0] = S_mulexp10(result[0], exp_acc[0]) + (NV)accumulator[0];
963 result[1] = S_mulexp10(result[1], exp_acc[1]) + (NV)accumulator[1];
966 if (seen_digit && (*s == 'e' || *s == 'E')) {
967 bool expnegative = 0;
978 exponent = exponent * 10 + (*s++ - '0');
980 exponent = -exponent;
985 /* now apply the exponent */
988 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0])
989 + S_mulexp10(result[1],exponent-exp_adjust[1]);
991 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0]);
994 /* now apply the sign */
996 result[2] = -result[2];
997 #endif /* USE_PERL_ATOF */
1002 #if ! defined(HAS_MODFL) && defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
1004 Perl_my_modfl(long double x, long double *ip)
1007 return (x == *ip ? copysignl(0.0L, x) : x - *ip);
1011 #if ! defined(HAS_FREXPL) && defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
1013 Perl_my_frexpl(long double x, int *e) {
1014 *e = x == 0.0L ? 0 : ilogbl(x) + 1;
1015 return (scalbnl(x, -*e));
1021 * c-indentation-style: bsd
1023 * indent-tabs-mode: t
1026 * ex: set ts=8 sts=4 sw=4 noet: