Strange INT behavior

Blitz3D Forums/Blitz3D Beginners Area/Strange INT behavior

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

"Ceiling and Floor are the proper commands for rounding; that they aren't working the way you expect is probably due to how they behave with negative numbers. For example, -2.0 is lower than -1.1 so Floor#(-1.1) will give you -2.0; if you wanted/were expecting -1.0 (ie. simply replacing everything after the decimal point with 0) you have to use an If statement to check the value first and then use Floor or Ceiling as appropriate."


Ugh! I'll have to remember that. That sucks.

So we can't count on Int(-256.56) to return -256, and we can't cound on floor(-256.56) to return -256, and we obviously don't want to have to use an IF statement every time we do a math operation.

I wonder what Blitz does if you go a = -256.56. Does it round up/down, or does it just round down? I guess I'll have to test it...

Oh wonderful. It rounds both up and down like Int(). WHY MARK?! WHY?! WHY MUST YOU TORMENT ME SO?!

Converting to int should discard the remainder. That allows such wonderful constructs as:

A# = B# - Int(B#)

Which would give you the fractional part of a number and which I used to use constantly, before Blitz.

And:

A# = Int(B#)

Which of course would give you the integral part of the number only.

But how do I do these with this weird setup? I can't think of a way without using if statements.



[edit]

Actually, I just realised that with negative numbers you want floor() to round "up".

Here's why. Imagine you have a grid, with each tile being 1 unit wide. So you have a tile start at 0, 1, 2, 3, 4, etc.

Now, if you go leftwards, you hit negative tile starting locations... -1, -2, -3...

Now imagine you have a point at 0.5. If you want to find out which tile that is at, you use floor() and that rounds it down to 0. So you know you're at the tile that starts at 0.

But what if you have a point at -0,5? Well, rather than it rounding "down" to 0, which would be wrong in this case, you want it to round "up" to -1.

So floor really does "round down" properly because -1 is less than -0.5.

Hey I never said I got A's in algrebra. :-) (Actually, I got F's!)

[/edit]