in reply to Re: sprintf values
in thread sprintf values

...and C runtime library

FWIW, the C runtime library shouldn't matter here, as Perl has its own "printf"-like formatting routine ( Perl_sv_vcatpvfn() in sv.c, in case you're interested ).

Replies are listed 'Best First'.
Re^3: sprintf values
by ikegami (Patriarch) on Apr 07, 2010 at 16:18 UTC
    I think sv_vcatpvfn can or does use the C runtime to format floats. Even if it doesn't, the C runtime is used to create the floats in the first place, so it definitely matters.

      I just re-checked with ltrace, and yes you're right, it does in fact call snprintf() and frexp() to format floats.

      I had done a similar check some time ago, and was surprised to not find any libc calls related to Perl's s/printf()  (which is why I posted) — but that must have been without a float format specifier being used... (rather only integer formatting like %d, %u etc.)   As to the creation of floats, however, I don't see any calls to libc or libm. Any idea what function that would be (just out of curiosity)?

        toke.c 13286 if (floatit) { 13287 /* terminate the string */ 13288 *d = '\0'; 13289 nv = Atof(PL_tokenbuf); 13290 sv_setnv(sv, nv); 13291 }

        I didn't track Atof all the way through since I found comments in perl.h indicate Perl usually uses Perl's own atof implementation, but it can be configured to the native implementation (and does so on UNICOS).