Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does emacs has rational number data type

Tags:

emacs

elisp

I eval a lisp expression in scratch

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

I got a 0.

normally it should be 1.

like image 324
liwei Avatar asked May 23 '12 11:05

liwei


1 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.

GNU Emacs Calc Manual:

  • Fractions
  • Index of Lisp Math Functions
like image 133
Juancho Avatar answered Sep 29 '22 00:09

Juancho