Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] partial eval question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrew Lenharth <andrewl@d...>
Subject: Re: [Caml-list] partial eval question
On Mon, Oct 27, 2003 at 03:39:21PM +0000, William Chesters wrote:
> And that's an improvement over
> 
>     double pow(double x, int n) {
>       double it = 1;
>       while (--n >= 0) it *= x;
>       return it;
>     }
> 
>     double pow3(double x, int n) {
>       return pow(x, 3);
>     }
> 
> in what way exactly?  (If it doesn't work for you, try
> -funroll-all-loops.)

And that's an improvement over

template <int N>
inline double pow (double x) {
  return x * pow<N-1>(x);
}
template<>
inline double pow<0> (double x) {
  return 1.0;
}

in what way exactly?  (If it doesn't work for you, try 
-O2) :)

The C example relies on a fairly smart compiler to 
do interprocedual analysis.  The C++ example 
only requires the inline keywork be honored, and you 
don't need explicit pow3 pow2, you have pow<3> pow<2> 
pow<any constant>.

Gives a bit more control over code generation.

Andrew

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners