C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Floating point template arguments.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
E. Rosten
Guest





PostPosted: Fri Jul 29, 2005 4:04 pm    Post subject: Floating point template arguments. Reply with quote



For all of you who are disapointed at the lack of floating point template
parameters: I have an implementation of floating point done entirely in
templates here:

http://mi.eng.cam.ac.uk/~er258/code/fp_template.html

so you can perform floating point arithmetic and template on the results
freely at compile time

So far basic arithmetic is implemented, as well as a few elementary
functions (exp and sqrt, though not with very good algorithms).

It is now in a usable form: othe main example uses the compile time
floating point arithmetic to generate a static Gaussian convolution
kernel. As well as being more general purpose and more easily modifiable
than a hand coded version, the automatically generated kernel runs 1%
faster (on gcc 4.0.0, x86) than the hand coded version.

It does take 7 minutes to compile, though.

-Ed

--
(You can't go wrong with psycho-rats.) (er258)(@)(eng.cam)(.ac.uk)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Edson Manoel
Guest





PostPosted: Sat Jul 30, 2005 12:34 am    Post subject: Re: Floating point template arguments. Reply with quote



Quote:
As well as being more general purpose and more easily modifiable
than a hand coded version, the automatically generated kernel runs
1% faster (on gcc 4.0.0, x86) than the hand coded version.

It does take 7 minutes to compile, though.

Congratulations... for doing something like this with template
metaprogramming requires a lot of skill!

I've already done something similar before (but using fixed point
arithmetic), and I came to the conclusion that it is better to just use
a "code generator" to do the convolution and generate the static data
in a header!

The reason for this is that:
- the "metaprogram" (i.e, the code-generating program in this case) is
clearer than a templated version;
- debugging and modifying it is simpler;
- compilation time is *way* faster =)

Edson


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
E. Rosten
Guest





PostPosted: Sat Jul 30, 2005 10:21 am    Post subject: Re: Floating point template arguments. Reply with quote



On Fri, 29 Jul 2005 20:34:27 -0400, Edson Manoel wrote:

Quote:
As well as being more general purpose and more easily modifiable
than a hand coded version, the automatically generated kernel runs
1% faster (on gcc 4.0.0, x86) than the hand coded version.

It does take 7 minutes to compile, though.

Congratulations... for doing something like this with template
metaprogramming requires a lot of skill!

Thanks.

Quote:
I've already done something similar before (but using fixed point
arithmetic), and I came to the conclusion that it is better to just use
a "code generator" to do the convolution and generate the static data
in a header!

The reason for this is that:
- the "metaprogram" (i.e, the code-generating program in this case) is
clearer than a templated version;
- debugging and modifying it is simpler;
- compilation time is *way* faster =)


Indeed, the thought had occured to me (whilst waiting for the compiler to
finish...). But it _feels_ more elegant to do it all in C++ :-)

Maybe one day, everyone will fix their implementation of the template
language, so that it is on a par with other functional languages in terms
of speed.

Ah and don't forget the hand generated code (or code made by a generator
if you like) is 1% slower!

-Ed


--
(You can't go wrong with psycho-rats.) (er258)(@)(eng.cam)(.ac.uk)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.