I wanted the hexadecimal string for a large integer such as below:

(format "%x" 2738188573457603759)

This returns 2600000000f95c00 which is incorrect, it should be 2600000000f95caf.

The value of most-positive-fixnum on my box is 0x1fffffffffffffff which is less than the number I'm supplying above.

As a user I'm a bit baffled what is happening. The manual indicates integers larger than this range are converted to a floating-point number which is a concern for precision but I suspect this is what is biting me here?

I should have known there was an issue with this number since normally I evaluate them directly using eval-last-sexp and it didn't show the octal/hex variants.. :)

I wonder why Emacs Lisp doesn't support bignums, so precision would not be an issue?

  • 0x1fffffffffffffff is less than 0x2600000000f95caf, which would explain why you're getting these problems.
    – user12563
    Commented Feb 9, 2018 at 7:55
  • 1
    Wrt your last question: I've been asking for bignum support for a long time. The place to ask that is [email protected]. The place to request it is either on that same list or via M-x report-emacs-bug (that's for enhancements too, not just bug reports).
    – Drew
    Commented Feb 9, 2018 at 16:27
  • For latecomers, bignum support was added in Emacs 27.1, and consequently the issue in the question no longer occurs.
    – phils
    Commented Dec 18, 2023 at 5:57

1 Answer 1


You've answered your own question -- you're dealing with a number which is larger than most-positive-fixnum and are encountering floating point precision errors as a result. (Refer to https://floating-point-gui.de/ to understand what's going on in detail).

The usual solution in Emacs is to use M-x calc. Type d 6 in the calc buffer to run calc-hex-radix (or d r to enter any supported radix value), and then all numbers will be displayed in hex.

In this case, you can enter 2738188573457603759 and it will be displayed as 16#2600000000F95CAF.

Support for bignums has since been added to Emacs (starting from 27.1), so using calc is no longer necessary -- the code in the question nowadays produces an accurate result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.