From: Jarkko Hietaniemi Date: Fri, 24 May 2002 21:39:53 +0000 (+0000) Subject: In some (rare) platforms (such as UNICOS) using the native X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a36244b753e9b2747b70a6f37a7bcd86eaa61bcb;p=p5sagit%2Fp5-mst-13.2.git In some (rare) platforms (such as UNICOS) using the native atof is still better. p4raw-id: //depot/perl@16771 --- diff --git a/numeric.c b/numeric.c index 93f4cb4..d214416 100644 --- a/numeric.c +++ b/numeric.c @@ -783,17 +783,17 @@ Perl_my_atof(pTHX_ const char* s) /* Scan the number twice; once using locale and once without; * choose the larger result (in absolute value). */ - Perl_atof2(aTHX_ s, &x); + Perl_atof2(s, x); SET_NUMERIC_STANDARD(); - Perl_atof2(aTHX_ s, &y); + Perl_atof2(s, y); SET_NUMERIC_LOCAL(); if ((y < 0.0 && y < x) || (y > 0.0 && y > x)) return y; } else - Perl_atof2(aTHX_ s, &x); + Perl_atof2(s, x); #else - Perl_atof2(aTHX_ s, &x); + Perl_atof2(s, x); #endif return x; } @@ -802,8 +802,9 @@ char* Perl_my_atof2(pTHX_ const char* orig, NV* value) { NV result = 0.0; - bool negative = 0; char* s = (char*)orig; +#ifdef USE_PERL_ATOF + bool negative = 0; char* send = s + strlen(orig) - 1; bool seendigit = 0; I32 expextra = 0; @@ -926,6 +927,7 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value) /* now apply the sign */ if (negative) result = -result; +#endif /* USE_PERL_ATOF */ *value = result; return s; } diff --git a/perl.h b/perl.h index 09be747..43678ee 100644 --- a/perl.h +++ b/perl.h @@ -1428,8 +1428,30 @@ int isnan(double d); # endif #endif -#define Perl_atof(s) Perl_my_atof(s) -#define Perl_atof2(s, np) Perl_my_atof2(s, np) +/* The default is to use Perl's own atof() implementation (in numeric.c). + * Usually that is the one to use but for some platforms (e.g. UNICOS) + * it is however best to use the native implementation of atof. + * You can experiment with using your native one by -DUSE_PERL_ATOF=0. + * Some good tests to try out with either setting are t/base/num.t, + * t/op/numconvert.t, and t/op/pack.t. */ + +#ifndef USE_PERL_ATOF +# ifndef _UNICOS +# define USE_PERL_ATOF +# endif +#else +# if USE_PERL_ATOF == 0 +# undef USE_PERL_ATOF +# endif +#endif + +#ifdef USE_PERL_ATOF +# define Perl_atof(s) Perl_my_atof(s) +# define Perl_atof2(s, n) Perl_my_atof2(aTHX_ (s), &(n)) +#else +# define Perl_atof(s) (NV)atof(s) +# define Perl_atof2(s, n) ((n) = atof(s)) +#endif /* Previously these definitions used hardcoded figures. * It is hoped these formula are more portable, although