Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square/cubic root lookup table

I'm wondering which is the best way to create two lookups table for square root and cubic root of float values in range [0.0, 1.0).

I already profiled the code and saw that this is quite a strong bottleneck of performances (because I need to compute them for several tenths of thousands of values each). Then I remembered about lookup tables and thought they would help me increasing the performance.

Since my values are in a small range I was thinking about splitting the range with steps of, let's say, 0.0025 (hoping it's enough) but I'm unsure about which should be the most efficient way to retrieve them.

I can easily populate the lookup table but I need a way to efficiently get the correct value for a given float (which is not discretized on any step). Any suggestions or well known approaches to this problem?

I'm working with a mobile platform, just to specify.

Thanks in advance

like image 804
Jack Avatar asked Apr 18 '12 18:04

Jack


1 Answers

You have (1.0-0.0)/0.0025 = 400 steps

Just create a 400x1 matrix and access it by multiplying the float you want the square/cube to by 400.

For instance if you want to look up the square of 0.0075. Multiply 0.0075 by 400 and get 3 which is your index in the matrix

like image 77
jelgh Avatar answered Oct 12 '22 18:10

jelgh