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;
274 if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
275 /* strip off leading x or 0x.
276 for compatibility silently suffer "x" and "0x" as valid hex numbers.
283 else if (len >= 2 && s[0] == '0' && s[1] == 'x') {
290 for (; len-- && *s; s++) {
291 const char *hexdigit = strchr(PL_hexdigit, *s);
293 /* Write it in this wonky order with a goto to attempt to get the
294 compiler to make the common case integer-only loop pretty tight.
295 With gcc seems to be much straighter code than old scan_hex. */
298 if (value <= max_div_16) {
299 value = (value << 4) | ((hexdigit - PL_hexdigit) & 15);
302 /* Bah. We're just overflowed. */
303 if (ckWARN_d(WARN_OVERFLOW))
304 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
305 "Integer overflow in hexadecimal number");
307 value_nv = (NV) value;
310 /* If an NV has not enough bits in its mantissa to
311 * represent a UV this summing of small low-order numbers
312 * is a waste of time (because the NV cannot preserve
313 * the low-order bits anyway): we could just remember when
314 * did we overflow and in the end just multiply value_nv by the
315 * right amount of 16-tuples. */
316 value_nv += (NV)((hexdigit - PL_hexdigit) & 15);
319 if (*s == '_' && len && allow_underscores && s[1]
320 && (hexdigit = strchr(PL_hexdigit, s[1])))
326 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
327 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
328 "Illegal hexadecimal digit '%c' ignored", *s);
332 if ( ( overflowed && value_nv > 4294967295.0)
334 || (!overflowed && value > 0xffffffff )
337 if (ckWARN(WARN_PORTABLE))
338 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
339 "Hexadecimal number > 0xffffffff non-portable");
346 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
355 converts a string representing an octal number to numeric form.
357 On entry I<start> and I<*len> give the string to scan, I<*flags> gives
358 conversion flags, and I<result> should be NULL or a pointer to an NV.
359 The scan stops at the end of the string, or the first invalid character.
360 Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
361 invalid character will also trigger a warning.
362 On return I<*len> is set to the length of the scanned string,
363 and I<*flags> gives output flags.
365 If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
366 and nothing is written to I<*result>. If the value is > UV_MAX C<grok_oct>
367 returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
368 and writes the value to I<*result> (or the value is discarded if I<result>
371 If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the octal
372 number may use '_' characters to separate digits.
378 Perl_grok_oct(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
379 const char *s = start;
384 const UV max_div_8 = UV_MAX / 8;
385 const bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES;
386 bool overflowed = FALSE;
388 for (; len-- && *s; s++) {
389 /* gcc 2.95 optimiser not smart enough to figure that this subtraction
390 out front allows slicker code. */
391 int digit = *s - '0';
392 if (digit >= 0 && digit <= 7) {
393 /* Write it in this wonky order with a goto to attempt to get the
394 compiler to make the common case integer-only loop pretty tight.
398 if (value <= max_div_8) {
399 value = (value << 3) | digit;
402 /* Bah. We're just overflowed. */
403 if (ckWARN_d(WARN_OVERFLOW))
404 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
405 "Integer overflow in octal number");
407 value_nv = (NV) value;
410 /* If an NV has not enough bits in its mantissa to
411 * represent a UV this summing of small low-order numbers
412 * is a waste of time (because the NV cannot preserve
413 * the low-order bits anyway): we could just remember when
414 * did we overflow and in the end just multiply value_nv by the
415 * right amount of 8-tuples. */
416 value_nv += (NV)digit;
419 if (digit == ('_' - '0') && len && allow_underscores
420 && (digit = s[1] - '0') && (digit >= 0 && digit <= 7))
426 /* Allow \octal to work the DWIM way (that is, stop scanning
427 * as soon as non-octal characters are seen, complain only if
428 * someone seems to want to use the digits eight and nine). */
429 if (digit == 8 || digit == 9) {
430 if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT) && ckWARN(WARN_DIGIT))
431 Perl_warner(aTHX_ packWARN(WARN_DIGIT),
432 "Illegal octal digit '%c' ignored", *s);
437 if ( ( overflowed && value_nv > 4294967295.0)
439 || (!overflowed && value > 0xffffffff )
442 if (ckWARN(WARN_PORTABLE))
443 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
444 "Octal number > 037777777777 non-portable");
451 *flags = PERL_SCAN_GREATER_THAN_UV_MAX;
460 For backwards compatibility. Use C<grok_bin> instead.
464 For backwards compatibility. Use C<grok_hex> instead.
468 For backwards compatibility. Use C<grok_oct> instead.
474 Perl_scan_bin(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
477 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
478 const UV ruv = grok_bin (start, &len, &flags, &rnv);
481 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
485 Perl_scan_oct(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
488 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
489 const UV ruv = grok_oct (start, &len, &flags, &rnv);
492 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
496 Perl_scan_hex(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
499 I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
500 const UV ruv = grok_hex (start, &len, &flags, &rnv);
503 return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
507 =for apidoc grok_numeric_radix
509 Scan and skip for a numeric decimal separator (radix).
514 Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
516 #ifdef USE_LOCALE_NUMERIC
517 if (PL_numeric_radix_sv && IN_LOCALE) {
519 const char* radix = SvPV(PL_numeric_radix_sv, len);
520 if (*sp + len <= send && memEQ(*sp, radix, len)) {
525 /* always try "." if numeric radix didn't match because
526 * we may have data from different locales mixed */
528 if (*sp < send && **sp == '.') {
536 =for apidoc grok_number
538 Recognise (or not) a number. The type of the number is returned
539 (0 if unrecognised), otherwise it is a bit-ORed combination of
540 IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
541 IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
543 If the value of the number can fit an in UV, it is returned in the *valuep
544 IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
545 will never be set unless *valuep is valid, but *valuep may have been assigned
546 to during processing even though IS_NUMBER_IN_UV is not set on return.
547 If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
548 valuep is non-NULL, but no actual assignment (or SEGV) will occur.
550 IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
551 seen (in which case *valuep gives the true value truncated to an integer), and
552 IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
553 absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
554 number is larger than a UV.
559 Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep)
562 const char *send = pv + len;
563 const UV max_div_10 = UV_MAX / 10;
564 const char max_mod_10 = UV_MAX % 10;
569 while (s < send && isSPACE(*s))
573 } else if (*s == '-') {
575 numtype = IS_NUMBER_NEG;
583 /* next must be digit or the radix separator or beginning of infinity */
585 /* UVs are at least 32 bits, so the first 9 decimal digits cannot
588 /* This construction seems to be more optimiser friendly.
589 (without it gcc does the isDIGIT test and the *s - '0' separately)
590 With it gcc on arm is managing 6 instructions (6 cycles) per digit.
591 In theory the optimiser could deduce how far to unroll the loop
592 before checking for overflow. */
594 int digit = *s - '0';
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;
611 if (digit >= 0 && digit <= 9) {
612 value = value * 10 + digit;
615 if (digit >= 0 && digit <= 9) {
616 value = value * 10 + digit;
619 if (digit >= 0 && digit <= 9) {
620 value = value * 10 + digit;
623 if (digit >= 0 && digit <= 9) {
624 value = value * 10 + digit;
626 /* Now got 9 digits, so need to check
627 each time for overflow. */
629 while (digit >= 0 && digit <= 9
630 && (value < max_div_10
631 || (value == max_div_10
632 && digit <= max_mod_10))) {
633 value = value * 10 + digit;
639 if (digit >= 0 && digit <= 9
642 skip the remaining digits, don't
643 worry about setting *valuep. */
646 } while (s < send && isDIGIT(*s));
648 IS_NUMBER_GREATER_THAN_UV_MAX;
668 numtype |= IS_NUMBER_IN_UV;
673 if (GROK_NUMERIC_RADIX(&s, send)) {
674 numtype |= IS_NUMBER_NOT_INT;
675 while (s < send && isDIGIT(*s)) /* optional digits after the radix */
679 else if (GROK_NUMERIC_RADIX(&s, send)) {
680 numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */
681 /* no digits before the radix means we need digits after it */
682 if (s < send && isDIGIT(*s)) {
685 } while (s < send && isDIGIT(*s));
687 /* integer approximation is valid - it's 0. */
693 } else if (*s == 'I' || *s == 'i') {
694 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
695 s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
696 s++; if (s < send && (*s == 'I' || *s == 'i')) {
697 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
698 s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
699 s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
700 s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
704 } else if (*s == 'N' || *s == 'n') {
705 /* XXX TODO: There are signaling NaNs and quiet NaNs. */
706 s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
707 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
714 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
715 numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;
717 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
718 numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT;
719 } else if (s < send) {
720 /* we can have an optional exponent part */
721 if (*s == 'e' || *s == 'E') {
722 /* The only flag we keep is sign. Blow away any "it's UV" */
723 numtype &= IS_NUMBER_NEG;
724 numtype |= IS_NUMBER_NOT_INT;
726 if (s < send && (*s == '-' || *s == '+'))
728 if (s < send && isDIGIT(*s)) {
731 } while (s < send && isDIGIT(*s));
737 while (s < send && isSPACE(*s))
741 if (len == 10 && memEQ(pv, "0 but true", 10)) {
744 return IS_NUMBER_IN_UV;
750 S_mulexp10(NV value, I32 exponent)
762 /* On OpenVMS VAX we by default use the D_FLOAT double format,
763 * and that format does not have *easy* capabilities [1] for
764 * overflowing doubles 'silently' as IEEE fp does. We also need
765 * to support G_FLOAT on both VAX and Alpha, and though the exponent
766 * range is much larger than D_FLOAT it still doesn't do silent
767 * overflow. Therefore we need to detect early whether we would
768 * overflow (this is the behaviour of the native string-to-float
769 * conversion routines, and therefore of native applications, too).
771 * [1] Trying to establish a condition handler to trap floating point
772 * exceptions is not a good idea. */
774 /* In UNICOS and in certain Cray models (such as T90) there is no
775 * IEEE fp, and no way at all from C to catch fp overflows gracefully.
776 * There is something you can do if you are willing to use some
777 * inline assembler: the instruction is called DFI-- but that will
778 * disable *all* floating point interrupts, a little bit too large
779 * a hammer. Therefore we need to catch potential overflows before
782 #if ((defined(VMS) && !defined(__IEEE_FP)) || defined(_UNICOS)) && defined(NV_MAX_10_EXP)
784 NV exp_v = log10(value);
785 if (exponent >= NV_MAX_10_EXP || exponent + exp_v >= NV_MAX_10_EXP)
788 if (-(exponent + exp_v) >= NV_MAX_10_EXP)
790 while (-exponent >= NV_MAX_10_EXP) {
791 /* combination does not overflow, but 10^(-exponent) does */
801 exponent = -exponent;
803 for (bit = 1; exponent; bit <<= 1) {
804 if (exponent & bit) {
807 /* Floating point exceptions are supposed to be turned off,
808 * but if we're obviously done, don't risk another iteration.
810 if (exponent == 0) break;
814 return negative ? value / result : value * result;
818 Perl_my_atof(pTHX_ const char* s)
821 #ifdef USE_LOCALE_NUMERIC
822 if (PL_numeric_local && IN_LOCALE) {
825 /* Scan the number twice; once using locale and once without;
826 * choose the larger result (in absolute value). */
828 SET_NUMERIC_STANDARD();
831 if ((y < 0.0 && y < x) || (y > 0.0 && y > x))
843 Perl_my_atof2(pTHX_ const char* orig, NV* value)
845 NV result[3] = {0.0, 0.0, 0.0};
846 const char* s = orig;
848 UV accumulator[2] = {0,0}; /* before/after dp */
850 const char* send = s + strlen(orig) - 1;
852 I32 exp_adjust[2] = {0,0};
853 I32 exp_acc[2] = {-1, -1};
854 /* the current exponent adjust for the accumulators */
859 I32 sig_digits = 0; /* noof significant digits seen so far */
861 /* There is no point in processing more significant digits
862 * than the NV can hold. Note that NV_DIG is a lower-bound value,
863 * while we need an upper-bound value. We add 2 to account for this;
864 * since it will have been conservative on both the first and last digit.
865 * For example a 32-bit mantissa with an exponent of 4 would have
866 * exact values in the set
874 * where for the purposes of calculating NV_DIG we would have to discount
875 * both the first and last digit, since neither can hold all values from
876 * 0..9; but for calculating the value we must examine those two digits.
878 #define MAX_SIG_DIGITS (NV_DIG+2)
880 /* the max number we can accumulate in a UV, and still safely do 10*N+9 */
881 #define MAX_ACCUMULATE ( (UV) ((UV_MAX - 9)/10))
883 /* leading whitespace */
896 /* we accumulate digits into an integer; when this becomes too
897 * large, we add the total to NV and start again */
907 /* don't start counting until we see the first significant
908 * digit, eg the 5 in 0.00005... */
909 if (!sig_digits && digit == 0)
912 if (++sig_digits > MAX_SIG_DIGITS) {
913 /* limits of precision reached */
915 ++accumulator[seen_dp];
916 } else if (digit == 5) {
917 if (old_digit % 2) { /* round to even - Allen */
918 ++accumulator[seen_dp];
926 /* skip remaining digits */
927 while (isDIGIT(*s)) {
933 /* warn of loss of precision? */
936 if (accumulator[seen_dp] > MAX_ACCUMULATE) {
937 /* add accumulator to result and start again */
938 result[seen_dp] = S_mulexp10(result[seen_dp],
940 + (NV)accumulator[seen_dp];
941 accumulator[seen_dp] = 0;
942 exp_acc[seen_dp] = 0;
944 accumulator[seen_dp] = accumulator[seen_dp] * 10 + digit;
948 else if (!seen_dp && GROK_NUMERIC_RADIX(&s, send)) {
950 if (sig_digits > MAX_SIG_DIGITS) {
952 while (isDIGIT(*s)) {
963 result[0] = S_mulexp10(result[0], exp_acc[0]) + (NV)accumulator[0];
965 result[1] = S_mulexp10(result[1], exp_acc[1]) + (NV)accumulator[1];
968 if (seen_digit && (*s == 'e' || *s == 'E')) {
969 bool expnegative = 0;
980 exponent = exponent * 10 + (*s++ - '0');
982 exponent = -exponent;
987 /* now apply the exponent */
990 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0])
991 + S_mulexp10(result[1],exponent-exp_adjust[1]);
993 result[2] = S_mulexp10(result[0],exponent+exp_adjust[0]);
996 /* now apply the sign */
998 result[2] = -result[2];
999 #endif /* USE_PERL_ATOF */
1004 #if ! defined(HAS_MODFL) && defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
1006 Perl_my_modfl(long double x, long double *ip)
1009 return (x == *ip ? copysignl(0.0L, x) : x - *ip);
1013 #if ! defined(HAS_FREXPL) && defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
1015 Perl_my_frexpl(long double x, int *e) {
1016 *e = x == 0.0L ? 0 : ilogbl(x) + 1;
1017 return (scalbnl(x, -*e));
1023 * c-indentation-style: bsd
1025 * indent-tabs-mode: t
1028 * ex: set ts=8 sts=4 sw=4 noet: