< Back to IRCAM Forum

Size of Real Number in OM

Hi! I wrote a function that converts a real number to a string, then loops through the string and collects each digit (if it is a digit) into a list.
When I tested this with the number 3.145798437 I discovered that the number seemed to be rounded to 3.1457985.
Is there a maximum of decimal places that OM can handle?

;;; Extracts each digit from a number and adds them to a list
;;; Input: Integer or Real number
;;; Output: List of digits

(lambda (n)
(let ((s (write-to-string n))
(c nil)
(ret '()))
(loop for i below (length s)
(setf c (aref s i))
(print c)
(if (digit-char-p c)
(setf ret (append ret (list (digit-char-p c))))))

Hi fm42,

This is not a limitation of OM, but rather how lisp works

If you just type:
(eval 3.145798437)
you will also get:
=> 3.1457985
The reason is that you should just eval this expression in order a greater precisions in floats:

(setf read-default-float-format 'double-float)

Then your code will return your value. By the way you can also call the pi variable which will return: