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)
35 return f < I32_MIN ? (U32) I32_MIN : (U32)(I32) f;
38 if (f < U32_MAX_P1_HALF)
41 return ((U32) f) | (1 + U32_MAX >> 1);
46 return f > 0 ? U32_MAX : 0 /* NaN */;
50 Perl_cast_i32(pTHX_ NV f)
54 return f < I32_MIN ? I32_MIN : (I32) f;
57 if (f < U32_MAX_P1_HALF)
60 return (I32)(((U32) f) | (1 + U32_MAX >> 1));
65 return f > 0 ? (I32)U32_MAX : 0 /* NaN */;
69 Perl_cast_iv(pTHX_ NV f)
73 return f < IV_MIN ? IV_MIN : (IV) f;
76 /* For future flexibility allowing for sizeof(UV) >= sizeof(IV) */
77 if (f < UV_MAX_P1_HALF)
80 return (IV)(((UV) f) | (1 + UV_MAX >> 1));
85 return f > 0 ? (IV)UV_MAX : 0 /* NaN */;
89 Perl_cast_uv(pTHX_ NV f)
93 return f < IV_MIN ? (UV) IV_MIN : (UV)(IV) f;
96 if (f < UV_MAX_P1_HALF)
99 return ((UV) f) | (1 + UV_MAX >> 1);
104 return f > 0 ? UV_MAX : 0 /* NaN */;
110 converts a string representing a binary number to numeric form.
112 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
113 conversion flags, and I<result> should be NULL or a pointer to an NV.
114 The scan stops at the end of the string, or the first invalid character.
115 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
116 invalid character will also trigger a warning.
117 On return I<*len> is set to the length of the scanned string,
118 and I<*flags> gives output flags.
120 If the value is <= C<UV_MAX> it is returned as a UV, the output flags are clear,
121 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_bin>
122 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
123 and writes the value to I<*result> (or the value is discarded if I<result>
126 The binary number may optionally be prefixed with "0b" or "b" unless
127 C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
128 C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the binary
129 number may use '_' characters to separate digits.
135 Perl_grok_bin(pTHX_ char *start, STRLEN *len_p, I32 *flags, NV *result) {
136 const char *s = start;
141 const UV max_div_2 = UV_MAX / 2;
142 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
143 bool overflowed = FALSE;
146 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
147 /* strip off leading b or 0b.
148 for compatibility silently suffer "b" and "0b" as valid binary
155 else if (len >= 2 && s[0] == '0' && s[1] == 'b') {
162 for (; len-- && (bit = *s); s++) {
163 if (bit == '0' || bit == '1') {
164 /* Write it in this wonky order with a goto to attempt to get the
165 compiler to make the common case integer-only loop pretty tight.
166 With gcc seems to be much straighter code than old scan_bin. */
169 if (value <= max_div_2) {
170 value = (value << 1) | (bit - '0');
173 /* Bah. We're just overflowed. */
174 if (ckWARN_d(WARN_OVERFLOW))
175 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
176 "Integer overflow in binary number");
178 value_nv = (NV) value;
181 /* If an NV has not enough bits in its mantissa to
182 * represent a UV this summing of small low-order numbers
183 * is a waste of time (because the NV cannot preserve
184 * the low-order bits anyway): we could just remember when
185 * did we overflow and in the end just multiply value_nv by the
187 value_nv += (NV)(bit - '0');
190 if (bit == '_' && len && allow_underscores && (bit = s[1])
191 && (bit == '0' || bit == '1'))
197 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
198 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
199 "Illegal binary digit '%c' ignored", *s);
203 if ( ( overflowed && value_nv > 4294967295.0)
205 || (!overflowed && value > 0xffffffff )
208 if (ckWARN(WARN_PORTABLE))
209 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
210 "Binary number > 0b11111111111111111111111111111111 non-portable");
217 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
226 converts a string representing a hex number to numeric form.
228 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
229 conversion flags, and I<result> should be NULL or a pointer to an NV.
230 The scan stops at the end of the string, or the first invalid character.
231 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
232 invalid character will also trigger a warning.
233 On return I<*len> is set to the length of the scanned string,
234 and I<*flags> gives output flags.
236 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
237 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_hex>
238 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
239 and writes the value to I<*result> (or the value is discarded if I<result>
242 The hex number may optionally be prefixed with "0x" or "x" unless
243 C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
244 C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the hex
245 number may use '_' characters to separate digits.
251 Perl_grok_hex(pTHX_ char *start, STRLEN *len_p, I32 *flags, NV *result) {
252 const char *s = start;
257 const UV max_div_16 = UV_MAX / 16;
258 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
259 bool overflowed = FALSE;
261 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
262 /* strip off leading x or 0x.
263 for compatibility silently suffer "x" and "0x" as valid hex numbers.
270 else if (len >= 2 && s[0] == '0' && s[1] == 'x') {
277 for (; len-- && *s; s++) {
278 const char *hexdigit = strchr(PL_hexdigit, *s);
280 /* Write it in this wonky order with a goto to attempt to get the
281 compiler to make the common case integer-only loop pretty tight.
282 With gcc seems to be much straighter code than old scan_hex. */
285 if (value <= max_div_16) {
286 value = (value << 4) | ((hexdigit - PL_hexdigit) & 15);
289 /* Bah. We're just overflowed. */
290 if (ckWARN_d(WARN_OVERFLOW))
291 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
292 "Integer overflow in hexadecimal number");
294 value_nv = (NV) value;
297 /* If an NV has not enough bits in its mantissa to
298 * represent a UV this summing of small low-order numbers
299 * is a waste of time (because the NV cannot preserve
300 * the low-order bits anyway): we could just remember when
301 * did we overflow and in the end just multiply value_nv by the
302 * right amount of 16-tuples. */
303 value_nv += (NV)((hexdigit - PL_hexdigit) & 15);
306 if (*s == '_' && len && allow_underscores && s[1]
307 && (hexdigit = strchr(PL_hexdigit, s[1])))
313 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
314 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
315 "Illegal hexadecimal digit '%c' ignored", *s);
319 if ( ( overflowed && value_nv > 4294967295.0)
321 || (!overflowed && value > 0xffffffff )
324 if (ckWARN(WARN_PORTABLE))
325 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
326 "Hexadecimal number > 0xffffffff non-portable");
333 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
342 converts a string representing an octal number to numeric form.
344 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
345 conversion flags, and I<result> should be NULL or a pointer to an NV.
346 The scan stops at the end of the string, or the first invalid character.
347 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
348 invalid character will also trigger a warning.
349 On return I<*len> is set to the length of the scanned string,
350 and I<*flags> gives output flags.
352 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
353 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_oct>
354 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
355 and writes the value to I<*result> (or the value is discarded if I<result>
358 If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the octal
359 number may use '_' characters to separate digits.
365 Perl_grok_oct(pTHX_ char *start, STRLEN *len_p, I32 *flags, NV *result) {
366 const char *s = start;
371 const UV max_div_8 = UV_MAX / 8;
372 const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
373 bool overflowed = FALSE;
375 for (; len-- && *s; s++) {
376 /* gcc 2.95 optimiser not smart enough to figure that this subtraction
377 out front allows slicker code. */
378 int digit = *s - '0';
379 if (digit >= 0 && digit <= 7) {
380 /* Write it in this wonky order with a goto to attempt to get the
381 compiler to make the common case integer-only loop pretty tight.
385 if (value <= max_div_8) {
386 value = (value << 3) | digit;
389 /* Bah. We're just overflowed. */
390 if (ckWARN_d(WARN_OVERFLOW))
391 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
392 "Integer overflow in octal number");
394 value_nv = (NV) value;
397 /* If an NV has not enough bits in its mantissa to
398 * represent a UV this summing of small low-order numbers
399 * is a waste of time (because the NV cannot preserve
400 * the low-order bits anyway): we could just remember when
401 * did we overflow and in the end just multiply value_nv by the
402 * right amount of 8-tuples. */
403 value_nv += (NV)digit;
406 if (digit == ('_' - '0') && len && allow_underscores
407 && (digit = s[1] - '0') && (digit >= 0 && digit <= 7))
413 /* Allow \octal to work the DWIM way (that is, stop scanning
414 * as soon as non-octal characters are seen, complain only if
415 * someone seems to want to use the digits eight and nine). */
416 if (digit == 8 || digit == 9) {
417 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
418 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
419 "Illegal octal digit '%c' ignored", *s);
424 if ( ( overflowed && value_nv > 4294967295.0)
426 || (!overflowed && value > 0xffffffff )
429 if (ckWARN(WARN_PORTABLE))
430 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
431 "Octal number > 037777777777 non-portable");
438 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
447 For backwards compatibility. Use C<grok_bin> instead.
451 For backwards compatibility. Use C<grok_hex> instead.
455 For backwards compatibility. Use C<grok_oct> instead.
461 Perl_scan_bin(pTHX_ char *start, STRLEN len, STRLEN *retlen)
464 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
465 const UV ruv = grok_bin (start, &len, &flags, &rnv);
468 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
472 Perl_scan_oct(pTHX_ char *start, STRLEN len, STRLEN *retlen)
475 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
476 const UV ruv = grok_oct (start, &len, &flags, &rnv);
479 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
483 Perl_scan_hex(pTHX_ char *start, STRLEN len, STRLEN *retlen)
486 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
487 const UV ruv = grok_hex (start, &len, &flags, &rnv);
490 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
494 =for apidoc grok_numeric_radix
496 Scan and skip for a numeric decimal separator (radix).
501 Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
503 #ifdef USE_LOCALE_NUMERIC
504 if (PL_numeric_radix_sv && IN_LOCALE) {
506 const char * const radix = SvPV(PL_numeric_radix_sv, len);
507 if (*sp + len <= send && memEQ(*sp, radix, len)) {
512 /* always try "." if numeric radix didn't match because
513 * we may have data from different locales mixed */
515 if (*sp < send && **sp == '.') {
523 =for apidoc grok_number
525 Recognise (or not) a number. The type of the number is returned
526 (0 if unrecognised), otherwise it is a bit-ORed combination of
527 IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
528 IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
530 If the value of the number can fit an in UV, it is returned in the *valuep
531 IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
532 will never be set unless *valuep is valid, but *valuep may have been assigned
533 to during processing even though IS_NUMBER_IN_UV is not set on return.
534 If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
535 valuep is non-NULL, but no actual assignment (or SEGV) will occur.
537 IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
538 seen (in which case *valuep gives the true value truncated to an integer), and
539 IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
540 absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
541 number is larger than a UV.
546 Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep)
549 const char * const send = pv + len;
550 const UV max_div_10 = UV_MAX / 10;
551 const char max_mod_10 = UV_MAX % 10;
556 while (s < send && isSPACE(*s))
560 } else if (*s == '-') {
562 numtype = IS_NUMBER_NEG;
570 /* next must be digit or the radix separator or beginning of infinity */
572 /* UVs are at least 32 bits, so the first 9 decimal digits cannot
575 /* This construction seems to be more optimiser friendly.
576 (without it gcc does the isDIGIT test and the *s - '0' separately)
577 With it gcc on arm is managing 6 instructions (6 cycles) per digit.
578 In theory the optimiser could deduce how far to unroll the loop
579 before checking for overflow. */
581 int digit = *s - '0';
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;
610 if (digit >= 0 && digit <= 9) {
611 value = value * 10 + digit;
613 /* Now got 9 digits, so need to check
614 each time for overflow. */
616 while (digit >= 0 && digit <= 9
617 && (value < max_div_10
618 || (value == max_div_10
619 && digit <= max_mod_10))) {
620 value = value * 10 + digit;
626 if (digit >= 0 && digit <= 9
629 skip the remaining digits, don't
630 worry about setting *valuep. */
633 } while (s < send && isDIGIT(*s));
635 IS_NUMBER_GREATER_THAN_UV_MAX;
655 numtype |= IS_NUMBER_IN_UV;
660 if (GROK_NUMERIC_RADIX(&s, send)) {
661 numtype |= IS_NUMBER_NOT_INT;
662 while (s < send && isDIGIT(*s)) /* optional digits after the radix */
666 else if (GROK_NUMERIC_RADIX(&s, send)) {
667 numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */
668 /* no digits before the radix means we need digits after it */
669 if (s < send && isDIGIT(*s)) {
672 } while (s < send && isDIGIT(*s));
674 /* integer approximation is valid - it's 0. */
680 } else if (*s == 'I' || *s == 'i') {
681 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
682 s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
683 s++; if (s < send && (*s == 'I' || *s == 'i')) {
684 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
685 s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
686 s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
687 s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
691 } else if (*s == 'N' || *s == 'n') {
692 /* XXX TODO: There are signaling NaNs and quiet NaNs. */
693 s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
694 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
701 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
702 numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;
704 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
705 numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT;
706 } else if (s < send) {
707 /* we can have an optional exponent part */
708 if (*s == 'e' || *s == 'E') {
709 /* The only flag we keep is sign. Blow away any "it's UV" */
710 numtype &= IS_NUMBER_NEG;
711 numtype |= IS_NUMBER_NOT_INT;
713 if (s < send && (*s == '-' || *s == '+'))
715 if (s < send && isDIGIT(*s)) {
718 } while (s < send && isDIGIT(*s));
724 while (s < send && isSPACE(*s))
728 if (len == 10 && memEQ(pv, "0 but true", 10)) {
731 return IS_NUMBER_IN_UV;
737 S_mulexp10(NV value, I32 exponent)
749 /* On OpenVMS VAX we by default use the D_FLOAT double format,
750 * and that format does not have *easy* capabilities [1] for
751 * overflowing doubles 'silently' as IEEE fp does. We also need
752 * to support G_FLOAT on both VAX and Alpha, and though the exponent
753 * range is much larger than D_FLOAT it still doesn't do silent
754 * overflow. Therefore we need to detect early whether we would
755 * overflow (this is the behaviour of the native string-to-float
756 * conversion routines, and therefore of native applications, too).
758 * [1] Trying to establish a condition handler to trap floating point
759 * exceptions is not a good idea. */
761 /* In UNICOS and in certain Cray models (such as T90) there is no
762 * IEEE fp, and no way at all from C to catch fp overflows gracefully.
763 * There is something you can do if you are willing to use some
764 * inline assembler: the instruction is called DFI-- but that will
765 * disable *all* floating point interrupts, a little bit too large
766 * a hammer. Therefore we need to catch potential overflows before
769 #if ((defined(VMS) && !defined(__IEEE_FP)) || defined(_UNICOS)) && defined(NV_MAX_10_EXP)
771 const NV exp_v = log10(value);
772 if (exponent >= NV_MAX_10_EXP || exponent + exp_v >= NV_MAX_10_EXP)
775 if (-(exponent + exp_v) >= NV_MAX_10_EXP)
777 while (-exponent >= NV_MAX_10_EXP) {
778 /* combination does not overflow, but 10^(-exponent) does */
788 exponent = -exponent;
790 for (bit = 1; exponent; bit <<= 1) {
791 if (exponent & bit) {
794 /* Floating point exceptions are supposed to be turned off,
795 * but if we're obviously done, don't risk another iteration.
797 if (exponent == 0) break;
801 return negative ? value / result : value * result;
805 Perl_my_atof(pTHX_ const char* s)
808 #ifdef USE_LOCALE_NUMERIC
809 if (PL_numeric_local && IN_LOCALE) {
812 /* Scan the number twice; once using locale and once without;
813 * choose the larger result (in absolute value). */
815 SET_NUMERIC_STANDARD();
818 if ((y < 0.0 && y < x) || (y > 0.0 && y > x))
830 Perl_my_atof2(pTHX_ const char* orig, NV* value)
832 NV result[3] = {0.0, 0.0, 0.0};
833 const char* s = orig;
835 UV accumulator[2] = {0,0}; /* before/after dp */
837 const char* send = s + strlen(orig) - 1;
839 I32 exp_adjust[2] = {0,0};
840 I32 exp_acc[2] = {-1, -1};
841 /* the current exponent adjust for the accumulators */
846 I32 sig_digits = 0; /* noof significant digits seen so far */
848 /* There is no point in processing more significant digits
849 * than the NV can hold. Note that NV_DIG is a lower-bound value,
850 * while we need an upper-bound value. We add 2 to account for this;
851 * since it will have been conservative on both the first and last digit.
852 * For example a 32-bit mantissa with an exponent of 4 would have
853 * exact values in the set
861 * where for the purposes of calculating NV_DIG we would have to discount
862 * both the first and last digit, since neither can hold all values from
863 * 0..9; but for calculating the value we must examine those two digits.
865 #define MAX_SIG_DIGITS (NV_DIG+2)
867 /* the max number we can accumulate in a UV, and still safely do 10*N+9 */
868 #define MAX_ACCUMULATE ( (UV) ((UV_MAX - 9)/10))
870 /* leading whitespace */
883 /* punt to strtod for NaN/Inf; if no support for it there, tough luck */
886 if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I') {
887 const char *p = negative ? s - 1 : s;
890 rslt = strtod(p, &endp);
898 /* we accumulate digits into an integer; when this becomes too
899 * large, we add the total to NV and start again */
909 /* don't start counting until we see the first significant
910 * digit, eg the 5 in 0.00005... */
911 if (!sig_digits && digit == 0)
914 if (++sig_digits > MAX_SIG_DIGITS) {
915 /* limits of precision reached */
917 ++accumulator[seen_dp];
918 } else if (digit == 5) {
919 if (old_digit % 2) { /* round to even - Allen */
920 ++accumulator[seen_dp];
928 /* skip remaining digits */
929 while (isDIGIT(*s)) {
935 /* warn of loss of precision? */
938 if (accumulator[seen_dp] > MAX_ACCUMULATE) {
939 /* add accumulator to result and start again */
940 result[seen_dp] = S_mulexp10(result[seen_dp],
942 + (NV)accumulator[seen_dp];
943 accumulator[seen_dp] = 0;
944 exp_acc[seen_dp] = 0;
946 accumulator[seen_dp] = accumulator[seen_dp] * 10 + digit;
950 else if (!seen_dp && GROK_NUMERIC_RADIX(&s, send)) {
952 if (sig_digits > MAX_SIG_DIGITS) {
954 while (isDIGIT(*s)) {
965 result[0] = S_mulexp10(result[0], exp_acc[0]) + (NV)accumulator[0];
967 result[1] = S_mulexp10(result[1], exp_acc[1]) + (NV)accumulator[1];
970 if (seen_digit && (*s == 'e' || *s == 'E')) {
971 bool expnegative = 0;
982 exponent = exponent * 10 + (*s++ - '0');
984 exponent = -exponent;
989 /* now apply the exponent */
992 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0])
993 + S_mulexp10(result[1],exponent-exp_adjust[1]);
995 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0]);
998 /* now apply the sign */
1000 result[2] = -result[2];
1001 #endif /* USE_PERL_ATOF */
1006 #if ! defined(HAS_MODFL) && defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
1008 Perl_my_modfl(long double x, long double *ip)
1011 return (x == *ip ? copysignl(0.0L, x) : x - *ip);
1015 #if ! defined(HAS_FREXPL) && defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
1017 Perl_my_frexpl(long double x, int *e) {
1018 *e = x == 0.0L ? 0 : ilogbl(x) + 1;
1019 return (scalbnl(x, -*e));
1025 * c-indentation-style: bsd
1027 * indent-tabs-mode: t
1030 * ex: set ts=8 sts=4 sw=4 noet: