Isn't INT the equivalent of _FLOOR? Or is there a difference?
INT(-2.5) = -3, same as floor, unless it got broke somewhere.
INT(-2.5) = -3, same as floor, unless it got broke somewhere.
_Round () issue
|
Isn't INT the equivalent of _FLOOR? Or is there a difference?
INT(-2.5) = -3, same as floor, unless it got broke somewhere.
05-13-2022, 01:07 PM
(This post was last modified: 05-13-2022, 01:09 PM by TarotRedhand.)
They're similar but _FLOOR should return a floating point number. Also for negative numbers the results are different. Take -99.5 for example. INT would return -99 whereas a _FLOOR function would return -100.0. At least that is my understanding. Hint - I haven't tried this out, just did a quick read.
TR
05-13-2022, 01:21 PM
No, honestly, they're *exactly* the same thing. Let me share some code for you.
First, the BAS code: Code: (Select All) A = Int(-99.5) And then, if you look in internal/temp, you can see where this code is translated in c-code: Code: (Select All) *__SINGLE_A=floor( -99.5E+0 ); If you notice, INT translates directly into floor. INT is the BASIC equivalent of floor. It translates one-on-one to the other, and that's why we don't have a _FLOOR command -- BASIC already has INT.
05-13-2022, 01:55 PM
(05-13-2022, 10:49 AM)SMcNeill Wrote:(05-13-2022, 01:08 AM)bplus Wrote:(05-13-2022, 12:45 AM)dcromley Wrote: > bplus: "Luke explained it as bankers rounding, so that not every 5 is rounded up but every other 5 is." I tried that last night it was a mess! Today I try removing neg sign, doing the calc and then putting the sign back in, interesting it fails or does bankers rounding! Not what I expected. Code: (Select All) Print "N", "Round", "Round Sgn", "Round Neg"
b = b + ...
05-13-2022, 02:09 PM
What are you expecting? Maybe try FIX instead of INT. I'm not certain what results you're shooting for.
05-13-2022, 06:03 PM
Expected RoundNeg##(n, 1) to round negs like pos and then add a - sign to the calc.
b = b + ...
(05-13-2022, 06:03 PM)bplus Wrote: Expected RoundNeg##(n, 1) to round negs like pos and then add a - sign to the calc. Like this? Code: (Select All) Screen _NewImage(1024, 720, 32) If that's not what you're looking for, you'll need to spell it out with some numbers and what you expect to see them become. +0.75 = +1 +0.5 = +1 +0.25 = 0 -0.25 = 0 -0.5 = -1 -0.75 = -1 Or this formula as well, if you prefer: Code: (Select All) Function Round## (num As _Float, toDecPlace As _Unsigned _Byte)
05-13-2022, 09:28 PM
(This post was last modified: 05-17-2022, 09:31 PM by dcromley.
Edit Reason: added toLng - correct k1 to k0
)
I thought Int() was working differently on Wednesday than on Friday, but my thread-starting program was incorrect. ! I deleted that. Gad!
I think this is correct (as I thought on Wednesday) and interesting: FWIW, this clearly shows the up and downs: (trust me): Code: (Select All) _Title "SCREEN256" I never even considered the FIX function. From the Wiki: The INT function rounds a numeric value down to the next whole number. The FIX function rounds a numerical value to the next whole number closest to zero. The _ROUND function rounds to the closest even .. numerical value. And I'm quite sure (?) that Javascript says FLOOR() = INT() |
« Next Oldest | Next Newest »
|