Take the 2-minute tour ×

I eval a lisp expression in scratch

(+ (/ 1 2) (/ 1 2))

I got a 0.

normally it should be 1.

share|improve this question
Didn't you just answer the question yourself? –  tripleee May 23 '12 at 11:49
add comment

3 Answers

As Oleg points out, operators usually default to integer arithmetic unless you include floating point arguments (like 1.0).

With respect to your question about rational number support, emacs-calc (which is part of emacs) supports many number types including fractions (i.e. rational numbers), complex numbers, infinite precision integers, etc. Your code must call emacs-calc functions (instead of /, etc.) in order to use calc's arithmetic.



share|improve this answer
Ah, calc to the rescue yet again. I should have thought of that. –  phils May 23 '12 at 20:24
add comment

Try this way

(+ (/ 1.0 2) (/ 1.0 2))

According to emacs doc

Function: / dividend divisor &rest divisors

if all the arguments are integers, then the result is an integer too.

share|improve this answer
That fails to answer the question, although between the lines, you can infer that because Emacs uses floats, it doesn't have a separate type for real numbers. (Many Lisp implementations have one; that is, 1/3 is represented precisely, rather than as a floating-point approximation.) –  tripleee May 23 '12 at 12:19
add comment

You can read all about numbers in elisp here:

C-hig (elisp) Numbers RET

As already indicated by tripleee, it is apparent that the answer is "no".

share|improve this answer
add comment

Your Answer


