[Scilab-users] How to print int64 or uint64 integers at full accuracy?
Samuel Gougeon
sgougeon at free.fr
Mon Aug 29 00:05:22 CEST 2016
Hello all,
I am wondering how it is possible to print (in a file, in a string) new
64 bit integers,
at full accuracy. Their relative accuracy is better than for decimal numbers
(1/2^63 instead of %eps=1/2^52).
In Scilab 5, digits lower than 1/%eps -- that are somewhat randomly set --
can be displayed but are not relevant:
-->format(24)
-->%pi
%pi =
3.141592653589793115998
-->(%pi-3.141592653589793)==0
ans =
T
In Scilab 6, digits beyond %eps are displayed as 0. This is great:
--> format(24)
--> %pi
%pi =
3.141592653589793100000
However, this change is applied to all numbers, even to integers.
The issue is that Scilab 6 also brings super-integers :) int64 / uint64
having 64-bit mantissae, instead of 53-bit mantissae for decimal numbers.
Hence, int64 have a relative accuracy better than %eps.
Unfortunately the related digits can't be printed.
Only the default display in console works.
Examples:
i = int64(2)^62 + 1
printf("%d %i %ld %li \n", i, i ,i, i)
format(22)
string(i)
// I found this undocumented trick with printf format, but there is the
same truncature:
printf("%20.0f\n", i)
// Results:
--> i = int64(2)^62 + 1
i =
4611686018427387905 // The right value!
--> printf("%d %i %ld %li \n", i, i ,i, i)
-2147483648 -2147483648 -2147483648 -2147483648 // Oups. %lld does
nor work
--> format(22)
--> string(i)
ans =
4611686018427387900 // bad trailing zeros
--> // I found this undocumented trick with printf format, but there is
the same truncature:
--> printf("%20.0f\n", i)
4611686018427387900 // Same issue (final 5 missing)
I started looking for a solution with write() and its fortran formating,
but it looks no more ready for int64 integers.
Would you know any solution?
Thanks
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160829/b0d3e04a/attachment.htm>
More information about the users
mailing list