PDA

View Full Version : Wondering about 'gazintas'



LCSims
19-03-2015, 05:07
Hello to all,

So I'm still around and working, though at a much slower pace and with similar results. I have a situation that confuses my worn-out brain and hope someone might shed some light on the results of the below;



Dim num1 As Double Value = 28.144074074073
Dim div1 As Double Value = 2.8125
Dim result1 As Integer
Dim result2 As Double

result1 = num1 \ div1
result2 = num1 / div1

MsgBox 0, result1 + $CRLF + result2



When using Operator (/) I'm expecting to see 10, but am getting 9. Doing 10 x 2.8125 = 28.125, which goes into num1 10 times and change. But I'm getting 9. Why am I getting 9?!?

I don't have any ideas. I can work around it, if I know why it's giving me 9. At least I hope I can??? :D



And the thread title is in recognition to Jethro Bodine of The Beverly Hillbillies and him learning about math, specifically division. As in 4 gazinta 12 three times, 5 gazinta 30 six times...

Thanks for any assistance.

ErosOlmi
19-03-2015, 08:13
Ciao,

I'm confused too.
For math operations I'm using the operator that compiler (Power Basic) I use to create thinBasic gives to me.
Doing the same example directly into the compiler gives the same results that thinBasic does.

It seems num1 is truncated before making integer division but I'm not really sure.

I can easily fix it avoiding to internally use integer division making floating point division and truncating the result at the end but I asked to compiler forum to see if someone has a reason why this is happening.
I will wait a little to see if I get a reply.

Ciao
Eros

ErosOlmi
19-03-2015, 10:10
Ok, the reason is that operands are rounded before integer division takes place:

28.144074074073 rounded = 28
2.8125 Rounded = 3
28 \ 3 = 9

I will check if I mentioned this to thinBasic manual.


Sent from my iPhone using Tapatalk

LCSims
19-03-2015, 18:01
Thank you for taking a look, Eros.

The Help file mentions that the result will be an integer and refers to the division items as "numbers", same as the long division. Thus my confusion.

I end up taking the result and making it a string, so I can code to read the long division left of the decimal place to get the same data.

Lance