# [sdiy] large numbers

Andre Majorel aym-htnys at teaser.fr
Fri Jul 13 22:02:25 CEST 2018

```On 2018-07-13 09:42 -0700, Tim Ressel wrote:

> I need to generate a lookup table with 64 bit values. Usually
> I use Excel but there is a problem: It only does 14 decimal
> places. I don't think this is enough. Any suggestions?

What sort of 64-bit values ? Signed integers, unsigned integers,
IEEE 754 double precision, something else ?

To express a 64-bit integer in decimal, you need 20 digits (64 *
log 2 / log 10 = 19.266...)

In C/C++, type "long double" is usually capable of accurately
representing 64-bit integers (as long as you use another
compiler than MSVC, apparently). See
https://en.wikipedia.org/wiki/Long_double

In Perl, you can get as many digits as you like by using
Math::BigFloat or Math::BigInt. Perl is pretty good at
converting between characters, floating point and binary of
either endianness, thanks to pack() and unpack(). This program
writes 160 bytes to stdout, representing 1! through 20! as
64-bit big-endian unsigned integers :

use Math::BigFloat;
for (my \$n = 1; \$n <= 20; \$n++)
{
my \$f = Math::BigFloat->new(\$n);
\$f->bfac();
print pack('Q>', \$f->as_int());
}

Hex-and-ASCII dump of the output :

0000_0000  00 00 00 00  00 00 00 01  ........
0000_0008  00 00 00 00  00 00 00 02  ........
0000_0010  00 00 00 00  00 00 00 06  ........
0000_0018  00 00 00 00  00 00 00 18  ........
0000_0020  00 00 00 00  00 00 00 78  .......x
0000_0028  00 00 00 00  00 00 02 D0  .......Ð
0000_0030  00 00 00 00  00 00 13 B0  .......°
0000_0038  00 00 00 00  00 00 9D 80  ........
0000_0040  00 00 00 00  00 05 89 80  ........
0000_0048  00 00 00 00  00 37 5F 00  .....7_.
0000_0050  00 00 00 00  02 61 15 00  .....a..
0000_0058  00 00 00 00  1C 8C FC 00  ......ü.
0000_0060  00 00 00 01  73 28 CC 00  ....s(Ì.
0000_0068  00 00 00 14  4C 3B 28 00  ....L;(.
0000_0070  00 00 01 30  77 77 58 00  ...0wwX.
0000_0078  00 00 13 07  77 75 80 00  ....wu..
0000_0080  00 01 43 7E  EE CD 80 00  ..C~îÍ..
0000_0088  00 16 BE EC  CA 73 00 00  ..¾ìÊs..
0000_0090  01 B0 2B 93  06 89 00 00  .°+.....
0000_0098  21 C3 67 7C  82 B4 00 00  !Ãg|.´..

--
André Majorel http://www.teaser.fr/~amajorel/

```