Small floating point numbers
Moderator: Stef
Small floating point numbers
I've a few numbers that are .8, 1.2, etc and was wondering how I'd use those in the SGDK?
Re: Small floating point numbers
"Serious" games usually use fixed points instead of floating points in game logic because they are way faster. You should use them for things like "position" and "speed", there is a notable difference in response. The big handicap is you no longer have so many decimals, but is strange to use them in great amount in games. So no big deal about not having floating points after all.
HELP. Spanish TVs are brain washing people to be hostile to me.
Re: Small floating point numbers
It's based on old ZX spectrum basic which seems to allow for float point numbers in some weird way!
Re: Small floating point numbers
if anyone knows how you'd write this without floating point as an SGDK equivalent I'd be very impressed (grateful)!
Code: Select all
round((sqrt(u16Popularity + u16EnergyCommitedPerTourDate) * 1000) / 120)
Re: Small floating point numbers
Having had a good look at the maths support I don't think it's possible for me to do with fix16 via the math functions as u16Popularity goes up to 100 and u16EnergyCommitedPerTourDate goes up to 1000.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Small floating point numbers
Should be equivalent :matteus wrote:if anyone knows how you'd write this without floating point as an SGDK equivalent I'd be very impressed (grateful)!
Code: Select all
round((sqrt(u16Popularity + u16EnergyCommitedPerTourDate) * 1000) / 120)
Code: Select all
u16 v = fix16ToRoundedInt((fix16Sqrt(intTofix16(u16Popularity + u16EnergyCommitedPerTourDate)) * 100) / 12);
You also need to enable the maths table in SGDK library, change following line in config.h from SGDK:
Code: Select all
MATH_BIG_TABLES 1
Re: Small floating point numbers
Thanks! and this one
u16Happiness = u16Happiness + Round(((u16Popularity * 10) / 1000) / 4)
I'm guessing I don't need to change as a standard int will just truncate? lol
u16Happiness = u16Happiness + Round(((u16Popularity * 10) / 1000) / 4)
I'm guessing I don't need to change as a standard int will just truncate? lol
Re: Small floating point numbers
Code: Select all
main.c|| undefined reference to `sqrttab16'|
main.c|| undefined reference to `sqrttab16'|
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Small floating point numbers
Did you recompiled the library with the
change i mentioned above ?
Code: Select all
MATH_BIG_TABLES 1
Re: Small floating point numbers
yes I've changed the flag, I tried recompiling the libraries as well
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Small floating point numbers
If you correctly recompiled the library with MATH_BIG_TABLE enabled (set to 1) then you should not meet this error.
How are you compiling your project, command line ? code::block ?
How are you compiling your project, command line ? code::block ?
Re: Small floating point numbers
I use code::block
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Small floating point numbers
Did your libmd.a file was correctly regenerated ? try to remove it before compiling the library so you will be sure it will be correctly rebuild
Re: Small floating point numbers
I've deleted it and get the error
||=== Build: release in MegaRockBandManager (compiler: Sega Genesis Compiler) ===|
sgdk\lib\libmd.a||No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|
||=== Build: release in MegaRockBandManager (compiler: Sega Genesis Compiler) ===|
sgdk\lib\libmd.a||No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|