.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   Attempting to create float free engine (http://forums.bots-united.com/showthread.php?t=4796)

sfx1999 29-12-2005 22:23

Attempting to create float free engine
 
Yes, I know it is difficult. I have created a float-implementation independant way of converting floats to 16:16 integers. It is not endian independant, though. Of course it doesn't matter that much, because floats are always stored the same way IIRC except on a VAX or ALPHA or something.

Anyway, I am going to be generating tables for SIN and COS and am planning to use a base two system instead of radians or degrees. How much precision will I need? I am planning to make it 4096 ints long. This way I won't have to perform a modulus operation; I can use bit manipulation instead. Is this enough?

My only other problem is square roots, that will be a pain in the ass.

If you didn't get what I meant by precision, let me elaborate. I plan to make 0 degrees 0 and 360 degrees 4096. 4096 won't exist in the table because it is redundant. Is 4096 enough, or should I go up?

DrEvil 30-12-2005 00:49

Re: Attempting to create float free engine
 
Why are you doing this? Modern hardware is very good at floating point math. I can't see any reason you'd want to do this.

@$3.1415rin 30-12-2005 10:04

Re: Attempting to create float free engine
 
I would say so too. unless you are working on a FLPT unit for some open source CPU :)

for that lookup table ... calculating the error is depending on how you calculate the values. do you just take the nearest neighbour, do you use linear interpolation, or higher order polynoms. you might wanna look up the error formula under "remainder lagrange interpolation"

sfx1999 31-12-2005 23:52

Re: Attempting to create float free engine
 
The main reason I want to do this is due to PDAs not having float support. It is kind of a proof of concept thing. Unfortunately, I don't know if they have hardware divide either, so that could hurt.

Whistler 01-01-2006 09:16

Re: Attempting to create float free engine
 
PHP Code:

// faster method to calculate 1.0/sqrt(f)
inline float InvSqrt(float f)
{
   
float half 0.5f f;

   
long lBits = *(long *)&f// evil floating point bit level hacking
   
lBits 0x5f3759df - (lBits >> 1); // WTF?
   
= *(float *)&lBits;
   
*= 1.5f half f// 1st iteration
//   f *= 1.5f - half * f * f; // 2nd iteration, this can be removed

   
return f;


also see the gcc and/or glibc source code

@$3.1415rin 01-01-2006 11:34

Re: Attempting to create float free engine
 
but that only works for 32bit float of this one very standard, dunno what sfx wants to implement ... and there should be another way to do a divide but dividing by it's root, doesnt it ?


about your precision : you just need to know your wanted precision and know the interpolation method ( I guess just linear interpolation for the sake of simplicity for now ) and then you can calculate the maximum distance between two entries for this point using this lagrange remainder.

sfx1999 02-01-2006 00:18

Re: Attempting to create float free engine
 
My precision ony can go to 1/32768, unfortunately.

Let me try to elaborate, only using 8 bits:

sign bit, 4, 2, 1, 1/2, 1/4, 1/8, 1/16
00011000

I am doing this with 32 bits, though. One thing, after you multiply, you will need to bitshift back, because the answer will be too large. You also need to shift after a divide, or else the answer will be to small. Addition and subtraction can be done normally. Doom uses this method.


All times are GMT +2. The time now is 19:48.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.