Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display rationals as long lists of digits in Lisp?

I'm just starting to learn Lisp and was wondering how to display a rational as a decimal number with lots of digits.

If I use (float x), where x is a rational then it displays about 8 digits or so. But I want to display hundreds of digits.

like image 665
jiggpig Avatar asked Jul 23 '10 15:07

jiggpig


2 Answers

You will have to implement an algorithm to basically do the long division and calculate the digits yourself. There is no native datatype capable of holding hundreds of decimal digits.

like image 75
jdmichal Avatar answered Sep 28 '22 09:09

jdmichal


You can use CLISP, an implementation of Common Lisp. As an extension it provides floats with settable precision. See: http://clisp.cons.org/beta/impnotes/num-concepts.html#lfd

There are also systems like Maxima and Axiom that run on top of Common Lisp. These also can compute with high precision reals.

The Common Lisp standard though doesn't provide that.

like image 32
Rainer Joswig Avatar answered Sep 28 '22 08:09

Rainer Joswig