[Tutor] greater precision?
John Collins
john at netcore.com.au
Mon Oct 29 12:49:23 CET 2012
Hi Dave,
> Not true. That's just what it was truncated to upon output. If you
> want to show 15 digits, then use formatted output instead of str()
> inside the realprint() function.
BIG light bulb moment! I had no idea the str() statement was truncating!
I *did* search the script for "12" or "trunc" (being a newbie!) and saw
nothing. Hence my silly questions tonight!
>> <SNIP>
>>
>> def realprint(a):
>> for i in range(len(a)):
>> outfile.write(str(a[i]))
>> if i < len(a)-1:
>> outfile.write(" ")
>> else:
>> outfile.write("\n")
>>
>
> output.write("{0:.15f}".format(x))
>
> You may want to play with the format a bit to get it the way you
> actually want it. Note that the format will happily output nonsense
> digits beyond the end of the available precision, so you have to do your
> own figuring before deciding what to display.
Hmm, well, I did modify the original script by setting the convergence
test value to 2.005e-16 up from 1e-6, soooo, I 'guess' 15 sig.figs.
will be OK. I'll have a go! That's 3 orders of magnitude better for
a few key strokes! Great! (maybe...)
John.
More information about the Tutor
mailing list