Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 15th Oct 2017 01:02
I sort of feel stupid for even starting a thread like this but I cant figure out what is going wrong and was hoping perhaps someone could explain this little quirk to me...

print 999 / 1000

Instead of printing .999, it instead prints 0. I thought perhaps it was a data type error so I assigned it to a variable which was a double float and yet it is still giving a value of 0. What am I doing wrong?

I have everything I need setup for my crude Neural Network to be up and running and as soon as I attempted to test it for some reason it kept returning .5 and I couldn't figure out why. I need to initialize the weights with random numbers between 1 and 0 so I just decided to initialize the weight as such

Weight# = RND(1000) / 1000

Which I assumed should give me a decimal between 1 and 0 down to three digits. However it returns 0 and I can not figure it out for the life of me. I know it has to be something simple so what am I missing.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 15th Oct 2017 02:28 Edited at: 15th Oct 2017 02:31
It is getting implicitly converted to integer because you are not using a decimal.

Try print 999.0 / 1000.0

Keep in mind though that there will always be some issues with floating point precision. That is just the nature of floats
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 15th Oct 2017 03:53 Edited at: 15th Oct 2017 03:56
I was having an issue earlier this week with calculating font kerning (spacing between characters). I was implementing a centered text command and I was getting all sorts of rounding errors until I dealt with this issue.
DB Pro likes to round down. So 10.1 will round down to 10 as an integer. This is bad when spacing characters and you end up with some characters jumbled due to missing pixels.

So I have taken to rounding up. I think there is a CEIL and FLOOR command for this.
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 15th Oct 2017 15:47
ceil: rounds a float value up and returns a float value
floor: rounds a float value down and returns a float value
int: returns a float value as an integer value, omitting any floating point numbers

the reason why Weight# = RND(1000) / 1000 does not work is because the programm looks at RND(1000) and sees it as an integer. let's say it returned 260. so it devides 260/1000. both are integer so the return value is integer (0.26 -> 0) and after that it will look at Weight#=0
if you do somthing like (0.0+RND(1000))/1000 then it will look at 0.0+RND(1000), so float + int = float, 260.0/1000 -> float/int=float, Weight#=0.26
the first value in an calculation must be a float for the calculation to return a float. order of operations do matter.

i made a very simple function that takes a value and returns it as a float:
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 04:27
Ortu nailed it, thanks everyone. That is such a silly thing man that drove me nuts for a couple hours last night and I couldn't figure out why the program was misbehaving. Why is DBPro have so many strange quirks like this. Has anyone compiled a list perhaps of oddities in DBPro? I wish I had written it down but there was something when I first started working on this a month or two ago in which the greater and less then symbols reversed if I had a specific line of code before it. It literally swapped < for > and to get it to work I would have to use the < symbol if I wanted to say greater then. That was a bug, a down right bug however Im sure different people know of odd quirks, If I started a thread on the topic does anyone have anything to add to list or quirks? I just dont have enough time in working with DB to really compile it myself but im sure everyone working together could come up with a good list that could help beginners out such as making sure they know 999.0 is a totally different number to the compiler then 999.

Login to post a reply

Server time is: 2024-03-03 14:01:52
Your offset time is: 2024-03-03 14:01:52