guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Floating Point?


From: Peter S. Christopher
Subject: Floating Point?
Date: Sat, 6 Sep 2003 13:10:21 -0500 (CDT)

Hi there listers,

        I've been thinking about how to make my floating point
calculations go faster. I thought that my FP calculations where so slow
because of excessive allocation. i.e. if a and b are floats then 
(+ a b) will return a *NEW* float with the value a+b in it. Is this
true? If this where true I thought that I could speed up my calculations
by replacing the normal operands (+,-,*,/) by versions that don't allocate
new cells (a-la (reg+, reg-, reg*, reg/)). Something like

(reg+ temp_1 a b) 

would evaluate to 

SCM_REAL_VALUE(temp_1) =        
    scm_num2dbl(a, FUNC_NAME)+scm_num2dbl(b, FUNC_NAME);

in some C extension function. This would prevent the allocation of the
additional doubles. The real advantage, of course, would be in expressions
like

(let ((register-1 0.0))
   (do ((i 0 (+ i 1))
       ((> i big-huge-number))
     (set-my-double-array i
       (reg+ register-1 5.7 (reg* register-1 3.1 i))))))

where this loop sets element i of my-double-array to 3.1*i+5.7. By my
reasoning (which may be suspect) this would save me many-many cell
allocations (2*big-huge-number to be exact).

        So how far off base am I? And, does anyone have other ideas on how
to improve my floating point performance (within the guile world that is).

Thanks for any help,
Pete Christopher





reply via email to

[Prev in Thread] Current Thread [Next in Thread]