On Dec 31, 8:49 am, Konrad Hinsen <konrad.hin...@laposte.net> wrote:
> Suppose I write
>
> (defn foo [x]
>    (let [f (. Math log 0.5)]
>      (* f x)))
>
> Does the Clojure compiler calculate the constant expression (. Math  
> log 0.5) once, or at every function call?

Folding constants in nontrivial floating-point expressions is an
aggressive optimization that can break some subtle code.  For example,
when building LAPACK, the file that tries to determine parameters of
the floating-point units generally has to be compiled with no
optimization.  I'd much rather keep that part of the optimization
turned off, or be very selective about when it gets turned on.
Furthermore, in some cases (FFTs on the Cell processor is the modern
example, if I recall correctly), it's better to recompute constants on
the fly then to look them up in a table.

mfh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to