Jope wrote:My problem is really how to go about specifying that double-float should be used for the calculations.

For example use one of these:

- Code: Select all
`(defun GL (n)`

(GL_start 1 (/ 1 (sqrt 2.0d0)) (/ 1 4) 1 n))

(defun GL (n)

(GL_start 1 (/ 1 (sqrt (the double-float 2.0))) (/ 1 4) 1 n))

(

Edit: do

not use the second version, see below for the reasons why not.)

Jope wrote:As you can see in the example, GL(8) has the same number of digits as GL(30), but I would like to be able to control the number of digits displayed depending on the inputted 'n'.

If GNU_CL uses IEEE floats (what is very likely) then you're out of luck because then the number of digits is defined by IEEE and not by GNU_CL. The only possibilies would be either to artificially cripple the floats, e.g. by:

- Code: Select all
`(defun digits-after-dot (float digits)`

(let ((factor (* (expt 10 digits))))

(/ (ftruncate (* float factor)) factor)))

(digits-after-dot pi 3) => 3.141

(digits-after-dot pi 4) => 3.1415

(digits-after-dot pi 5) => 3.14159

But this is a rather wacky hack that will quickly raise "floating point overflow" errors, and will of course not display more digits than defined by IEEE.

The only other alternative is using "bigfloats", e.g:

- bf.lisp - Common Lisp Bigfloat Package by Richard Fateman

- edgar