addition bug?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cwkalish
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Thu Sep 30, 2010 2:24 am

addition bug?

Post by cwkalish » Fri Oct 25, 2013 9:46 pm

I'm having trouble with simple integer addition. When I do calculations with integers, I get a real number approximation back. e.g., (17 + 12)-30 produces something like -0.969697
do I need to do something to convert values to integers before doing calculations? It doesn't help to just round the result as I am getting results that are off by 1 that way.

It seems to work fine when I type into the message box, but in handlers I get the realvalue. I'm attaching a trace from a function that shows the error.

Thanks for any suggestions.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: addition bug?

Post by dunbarx » Fri Oct 25, 2013 10:21 pm

Hi.

You get what???

Convert values? No you don't, and setting the numberformat property does not affect the significant portion of the result.

Are you saying that if you have this in a button:

Code: Select all

on mouseUp
   answer (17 + 12)-30
end mouseUp
you do not get "-1"

Craig Newman

cwkalish
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Thu Sep 30, 2010 2:24 am

Re: addition bug?

Post by cwkalish » Sat Oct 26, 2013 10:45 pm

Sort of.
I have 3 scroll bars setting values (the thumb position). When I do addition with those values, I get approximate real results (17+12)-30 is about -1
It may be that thumbpositions are reals? I tried to attach a screenshot showing a debug trace with the first message. The values appear as integers in the trace. Rounding the thumbpositions values seems to do the trick.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: addition bug?

Post by dunbarx » Sun Oct 27, 2013 12:56 am

Ah.

Yes. The answer is no.

Though they display as integers, they are reals. There was a thread on this several months back. It is not obvious, but has become part of the LC lore. Try to find the thread, but in the meantime, the "trunc" function is your friend.

Craig Newman

Post Reply