[Tutor] greater precision?

Dave Angel d at davea.name
Mon Oct 29 12:34:57 CET 2012


On 10/29/2012 06:54 AM, John Collins wrote:
> Hi Steve,
> Thanks. From
> >>>mkpoints.py 32 32.txt
>
> here's a sample of the output
>
> -0.396087591388 -0.781284022758 0.482400140683
> -0.967387012461 -0.0838047084421 -0.239037944614
> 0.0208969821213 -0.489420208746 0.871797668848
> 0.887250003871 -0.258893773768 -0.38178717178
> 0.426352071227 -0.457758408728 -0.780180203927
> 0.612061168992 -0.280383142359 0.739436555016
> -0.887250003871 0.258893773768 0.38178717178
> -0.0971745158475 -0.994342015264 -0.0429076933695
> -0.120898756509 -0.759794654167 -0.638823586113
> -0.0208969821213 0.489420208746 -0.871797668848
> 0.482396765336 -0.834880934468 -0.265079584379
> 0.66383194755 0.726669941038 0.176855710123
>
>
> from
> >>>nfaces.py 32.txt 32fa.txt
>
> here's a sample of the output
>
> point vertex_0_2_12 -0.0288974102653 -0.851924110364 0.66948446135
> point vertex_13_24_27 -0.122445373457 1.00045419254 0.398644871129
> point vertex_0_7_15 -0.482610585141 -0.963539328269 0.1161816686
> point vertex_3_10_17 0.848541556491 -0.639691741968 -0.213520247975
> point vertex_1_6_14 -1.05498774772 0.248634080415 -0.00106786881656
> point vertex_13_24_31 -0.291794484064 0.826881428947 0.637135994637
> point vertex_1_6_25 -1.07023716261 -0.0479998647263 0.164643927545
> point vertex_3_17_28 1.05498774772 -0.248634080415 0.00106786881656
> point vertex_1_15_25 -0.975134617659 -0.4675255693 -0.073154040374
> point vertex_4_8_10 0.291794484064 -0.826881428947 -0.637135994637
> point vertex_9_19_20 -0.400242088946 0.638705226984 -0.778897359983
> normal face_30 -0.617395768043 -0.359222235879 -0.699844161834
> face face_31 vertex_21_29_31
> face face_31 vertex_13_21_31
> face face_31 vertex_13_24_31
> face face_31 vertex_6_24_31
> face face_31 vertex_6_29_31
> normal face_31 -0.426352071227 0.457758408728 0.780180203927
>
>
> As you can see, there are exactly 12 significant figures.

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.


> <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.



-- 

DaveA



More information about the Tutor mailing list