Page 1 of 2
Small floating point numbers
Posted: Thu Sep 15, 2016 8:13 pm
by matteus
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
Posted: Fri Sep 16, 2016 11:37 am
by Stef
Re: Small floating point numbers
Posted: Fri Sep 16, 2016 11:55 pm
by Miquel
"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.
Re: Small floating point numbers
Posted: Mon Sep 19, 2016 4:58 pm
by matteus
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
Posted: Mon Sep 19, 2016 6:11 pm
by matteus
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
Posted: Mon Sep 19, 2016 6:56 pm
by matteus
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.
Re: Small floating point numbers
Posted: Mon Sep 19, 2016 7:03 pm
by Stef
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)
Should be equivalent :
Code: Select all
u16 v = fix16ToRoundedInt((fix16Sqrt(intTofix16(u16Popularity + u16EnergyCommitedPerTourDate)) * 100) / 12);
But it would be better to use fix16 type variable directly when you need it.
You also need to enable the maths table in SGDK library, change following line in config.h from SGDK:
Re: Small floating point numbers
Posted: Mon Sep 19, 2016 7:13 pm
by matteus
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
Re: Small floating point numbers
Posted: Mon Sep 19, 2016 7:14 pm
by matteus
Code: Select all
main.c|| undefined reference to `sqrttab16'|
main.c|| undefined reference to `sqrttab16'|
Re: Small floating point numbers
Posted: Tue Sep 20, 2016 1:28 pm
by Stef
Did you recompiled the library with the
change i mentioned above ?
Re: Small floating point numbers
Posted: Tue Sep 20, 2016 1:55 pm
by matteus
yes I've changed the flag, I tried recompiling the libraries as well
Re: Small floating point numbers
Posted: Tue Sep 20, 2016 5:57 pm
by Stef
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 ?
Re: Small floating point numbers
Posted: Tue Sep 20, 2016 6:09 pm
by matteus
I use code::block
Re: Small floating point numbers
Posted: Tue Sep 20, 2016 8:20 pm
by Stef
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
Posted: Wed Sep 21, 2016 9:25 pm
by matteus
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)) ===|