How to gmp_import or gmp_export a negative value?
| From: | Andrey Repin | Date: | Mon, 29 Feb 2016 11:14:47 +0000 |
| Subject: | How to gmp_import or gmp_export a negative value? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-325426@lists.php.net to get a copy of this message | ||
Greetings, All.
I'm working with some big numbers my platform can't handle, and I need a way
to store and retrieve them reliably.
But much to my dismay, I've found that GMP is unable to handle negative
numbers import/export.
This can be demonstrated with a very short script:
https://3v4l.org/gOENE
<?php
$x = "\xff";
$s = gmp_export(unpack('c', $x)[1], 1);
printf("In: %d, Out: %d\n", ord($x), ord($s));
If this an intended behavior? Or am I missing some flag to make it work the
desired way?
--
Sincerely Yours, Andrey Repin <anrdaemon@freemail.ru>