Skip to main content
gamedev.net
🔒 Locked

math optimizations

Started by vaneger 15 replies 650+ views
Original Post
vaneger
vaneger
where is the best place to find math tricks that help make code faster, also is there a good site that teaches better algorithim creation?
SebTheGameDeveloper
SebTheGameDeveloper
Did you try book "Game programming Gems" ? I found there a few very good math tricks. ( e.g. very fast float to int casting )
OmniBrain
OmniBrain
go to your favoured book store and check for "game programming gems", edited by Mark DeLoura (3 was by Dante Treglia).
if i remember correctly those math tricks were in the first book.
here is the amazon-link to the first book of the "game programming gems".

[edited by - OmniBrain on February 25, 2003 5:20:49 AM]
-----The scheduled downtime is omitted cause of technical problems.
DarkPixel
DarkPixel
The best place to find what you''ve been searching for is a
good math book !

Remember that nearly every math function can
be written with Taylor series ! It''s the best optimization that
you can get !

It''s basically what you''ll find in Game
Programming Gems
!

There is no problem, only solutions...
OmniBrain
OmniBrain
i am at home now with my beloved books and checekd it. it is in GPG II where you find the math tricks.

and DarkPixel: no. they do not use Taylor series. (at least i haven''t seen any when i checked)
they show some bit-modifying with ieee-floatpoints, like the fast invsqrt(), some sin/cosin-tables and the like.
-----The scheduled downtime is omitted cause of technical problems.
DarkPixel
DarkPixel
I''m sorry, it seems i was wrong ...

Anonymous Poster is right ! Taylor isn''t always the best
optmization, but in many cases its still a good and fast approximation...
...If you want more info on ''Taylor Series'' you can check
2.3 Polynomial Approximation to Trigonometric Functions in the
Game Programming Gems book on page 161.






There is no problem, only solutions...


There is no problem, only solutions...
YoshiN
YoshiN
The infinite taylor series for sin(x) for a = 0 is equivalent to sin(x) (in that the radius of convergence is infinite). That said taylor series are not an optimization, they are used for approximation / an easier way to calculate difficult functions. Also, you can''t find the tayler series of a function that is not differentiable (or continuous but that''s a given).
-YoshiXGXCX ''99
bjmumblingmiles
bjmumblingmiles
I know its not really an optimization, but I hardcoded my lookup tables to keep imports down. I successfully made a simple wireframe 3d program in 2k!

look_sin[1] = 0.0174519f;
look_sin[2] = 0.0348985f;
look_sin[3] = 0.0523344f;

etc....the reason for the size is actually because I Ignored Default Libraries, then made my own CRT...i called it the anemicCRT, because all it has is memory functions (new, delete, heap management)

Brian
Brian J
bjmumblingmiles
bjmumblingmiles
I know its not really an optimization, but I hardcoded my lookup tables to keep imports down. I successfully made a simple wireframe 3d program in 2k!

look_sin[1] = 0.0174519f;
look_sin[2] = 0.0348985f;
look_sin[3] = 0.0523344f;

etc....the reason for the size is actually because I Ignored Default Libraries, then made my own CRT...i called it the anemicCRT, because all it has is memory functions (new, delete, heap management)

Brian
Brian J
DDnewbie
DDnewbie
Hi,

A better option than Taylor series is Fourier series.
You can truncate the fourierserie when you have an approx that you''re happy with.

regards


/Mankind gave birth to God.
/Mankind gave birth to God.
Dobbs
Dobbs
Fourier series would be better for approximating periodic functions over their entire domain but that doesn''t necessarily make them better in general.
DDnewbie
DDnewbie
Hi,

Well, you can use fouriertransforms for aperiodic functions instead.




/Mankind gave birth to God.
/Mankind gave birth to God.
ragonastick
ragonastick
I believe the CORDIC algorithm is used for Sin/Cos stuff (that is, by the processor)

Fourier series are nice, but for optimisations... they might be a bit of a handful given their insane number of trig functions

I think a solid grounding in maths is what you need for doing that type of optimisation, but in general, if the success of your program depends on a line level (as opposed to algorithm level) optimisation, then you are probably doing something wrong.

Trying is the first step towards failure.
Trying is the first step towards failure.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.