_Round () issue - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: _Round () issue (/showthread.php?tid=389) Pages:
1
2
|
RE: _Round () issue - SMcNeill - 05-13-2022 Isn't INT the equivalent of _FLOOR? Or is there a difference? INT(-2.5) = -3, same as floor, unless it got broke somewhere. RE: _Round () issue - TarotRedhand - 05-13-2022 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 RE: _Round () issue - SMcNeill - 05-13-2022 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. RE: _Round () issue - bplus - 05-13-2022 (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" RE: _Round () issue - SMcNeill - 05-13-2022 What are you expecting? Maybe try FIX instead of INT. I'm not certain what results you're shooting for. RE: _Round () issue - bplus - 05-13-2022 Expected RoundNeg##(n, 1) to round negs like pos and then add a - sign to the calc. RE: _Round () issue - SMcNeill - 05-13-2022 (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) RE: _Round () issue - dcromley - 05-13-2022 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() |