emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using the GNU GMP Library for Bignums in Emacs


From: Paul Eggert
Subject: Re: Using the GNU GMP Library for Bignums in Emacs
Date: Mon, 23 Apr 2018 13:26:22 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 04/23/2018 12:22 PM, Helmut Eller wrote:
If I read the code in in data.c correctly, than Emacs uses the
INT_MULTIPLY_WRAPV macro which boils down to the __builtin_mul_overflow.
Which indeed produces nice machine code.  But the original question was
about ANSI C, which seems to require a division and 3 conditional jumps
for the range check (with gcc 6).

Yes, in general INT_MULTIPLY_WRAPV does require a division on platforms that do not support overflow-checking builtins. In practice, though, this tends to not be an issue, as the major compilers are moving in the direction of supporting such builtins.

Does INT_MULTIPLY_WRAPV macro even perform fixnum overflow tests?

No, it checks only for machine-level overflow. We could come up with a variant that does both machine-level and fixnum-level checking simultaneously; I'm not sure it's worth the trouble, though, as most arithmetic operations are addition and subtraction and for these, fixnum-level checking suffixes.

Anyway, I find it curios that the following two expression yield
different values:

(* (* most-positive-fixnum 2) 1.0) => -2.0

(* most-positive-fixnum 2 1.0) => 4.611686018427388e+18

Cool, huh? That's done on purpose; see this Emacs commit:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=0ae6bdee0085b05028108325b0a4ce979eadb24e

The idea is to produce a floating-point answer that is more mathematically-correct, while sticking to Common Lisp-style rules for contagion and argument processing.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]