Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Fucking sprintf rounding - how does it work?

by daxim (Chaplain)
on Sep 03, 2012 at 17:13 UTC ( #991485=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Fucking sprintf rounding - how does it work?
in thread F***ing sprintf rounding - how does it work?

Certainly.

$ perl -e'printf qq[%s => %.68f => %.1f\n], (qq[0.${_}5]) x 3 for (0.. +9)' 0.05 => 0.050000000000000000000677626357803440271254658000543713569641 +11328125 => 0.1 0.15 => 0.150000000000000000005421010862427522170037264004349708557128 +90625000 => 0.2 0.25 => 0.250000000000000000000000000000000000000000000000000000000000 +00000000 => 0.2 0.35 => 0.349999999999999999994578989137572477829962735995650291442871 +09375000 => 0.3 0.45 => 0.449999999999999999989157978275144955659925471991300582885742 +18750000 => 0.4 0.55 => 0.550000000000000000010842021724855044340074528008699417114257 +81250000 => 0.6 0.65 => 0.649999999999999999978315956550289911319850943982601165771484 +37500000 => 0.6 0.75 => 0.750000000000000000000000000000000000000000000000000000000000 +00000000 => 0.8 0.85 => 0.850000000000000000021684043449710088680149056017398834228515 +62500000 => 0.9 0.95 => 0.949999999999999999989157978275144955659925471991300582885742 +18750000 => 0.9

$ perl -V
Summary of my perl5 (revision 5 version 16 subversion 0) configuration +: Platform: osname=linux, osvers=3.1.10-1.9-desktop, archname=x86_64-linux-thr +ead-multi-ld uname='linux champion 3.1.10-1.9-desktop #1 smp preempt thu apr 5 +18:48:38 utc 2012 (4a97ec8) x86_64 x86_64 x86_64 gnulinux ' config_args='-de -Dprefix=/home/daxim/local/share/perlbrew/perls/p +erl-5.16.0 -DDEBUGGING -Dusemorebits -Dusethreads -Dcf_email=daxim@cp +an.org -Dperladmin=daxim@cpan.org -Accflags=-fPIC' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=define, use64bitall=define, uselongdouble=define usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fPIC -DDEBUGGING -f +no-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LA +RGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -g', cppflags='-D_REENTRANT -D_GNU_SOURCE -fPIC -DDEBUGGING -fno-strict +-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.6.2', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long', ivsize=8, nvtype='long double', nvsize=16, Off_t='o +ff_t', lseeksize=8 alignbytes=16, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/li +b /lib64 /usr/lib64 /usr/local/lib64 libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -l +c -lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.15.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.15' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib -fs +tack-protector' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING HAS_TIMES MULTIPLICITY PERLIO_LAYERS PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PERL_TRACK_MEMPOOL USE_64_BIT_ALL USE_64_BIT_I +NT USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LONG_DOUBLE USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API Built under linux Compiled at May 22 2012 09:25:33 %ENV: PERLBREW_BASHRC_VERSION="0.42" PERLBREW_HOME="/home/daxim/.perlbrew" PERLBREW_MANPATH="/home/daxim/local/share/perlbrew/perls/perl-5.16 +.0/man" PERLBREW_PATH="/home/daxim/local/share/perlbrew/bin:/home/daxim/lo +cal/share/perlbrew/perls/perl-5.16.0/bin" PERLBREW_PERL="perl-5.16.0" PERLBREW_ROOT="/home/daxim/local/share/perlbrew" PERLBREW_VERSION="0.42" @INC: /home/daxim/local/share/perlbrew/perls/perl-5.16.0/lib/site_perl/5 +.16.0/x86_64-linux-thread-multi-ld /home/daxim/local/share/perlbrew/perls/perl-5.16.0/lib/site_perl/5 +.16.0 /home/daxim/local/share/perlbrew/perls/perl-5.16.0/lib/5.16.0/x86_ +64-linux-thread-multi-ld /home/daxim/local/share/perlbrew/perls/perl-5.16.0/lib/5.16.0 .


Comment on Re^3: Fucking sprintf rounding - how does it work?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991485]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2015-07-08 03:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls