Dancing On The Ceil(ing)

OK, I’ve got my DUMMY hat on because this is going to be so ROTE to the 35-year old programmers that have been programming for 75 years. But here it goes.

I can’t believe I missed this for so many years, but consider the Floor() function for negative numbers. In the docs it says:

“Returns the value specified rounded down to the nearest whole number.”

Well, if you are sternly Spock logical like I am, this is a silly statement. Floor(-1.2) returns -2. It is NOT the nearest whole number, but since it says “down”, it returns -2. Plus, “nearest” contradicts “down” - it doesn’t matter which whole number is “nearest” numerically.

And isn’t “down” a confusing term? In my world, numbers move inward to 0, so “down” for negative numbers means -1.2 becomes -1, not -2.

Now, I know this has been discussed before…

https://forum.xojo.com/8257-returning-a-whole-integer/0

But shouldn’t some of that information go into the documentation? And I am asserting the language in the docs is confusing, and shouldn’t the Floor entry refer to Ceil (and refer to Round)? As it is the entry for Ceil is 99.99% identical to Floor,a dn neither mentions negative numbers.

okay, FIRE

Maybe the entries should say something like

Floor returns the largest integer that is less than the value pass in

Ceil gives you the largest integer that is larger than the value passed in

BUT given that this isnt the first thread about this the docs might be revised since they appear to be confusing to some
Avoiding the loaded words “up and down” would be good since they make people assume incorrect things (as you pointed out)

True… the funny thing is that so long ago - 19 years ago, I adopted REALbasic for Mac app building, and my code was in VB. First thing I did was make RB wrappers for VB functions that didn’t exist in RB. One VB function was Fix(), which strips off any reminder of a floating pointer number; that is, rounds subtractively for positive and rounds positively for a negative. I thought at the time Floor() was a direct replacement function for Fix() (like Uppercase() was for UCase()), but here we are, 19 years later I find it’s not. =) My RB/RS/Xojo programs aren’t too computational though, I rely on a C++ library for the seriosu stuff. Perhaps that’s why it’s slipped through my grasp all this time. I can blame the documentation, but I really blame myself. =)

[quote]Floor returns the largest integer that is less than the value pass in

Ceil gives you the largest integer that is larger than the value passed in[/quote]

Shouldn’t that be: Floor returns the largest integer less than or equal to the value passed in?

sure … it was just meant o be an example of what they might write instead of using ambiguous words like “up” and “down” which confused Garth

[quote=495952:@Garth Hjelte]Well, if you are sternly Spock logical like I am, this is a silly statement. Floor(-1.2) returns -2. It is NOT the nearest whole number, but since it says “down”, it returns -2. Plus, “nearest” contradicts “down” - it doesn’t matter which whole number is “nearest” numerically.

And isn’t “down” a confusing term? In my world, numbers move inward to 0, so “down” for negative numbers means -1.2 becomes -1, not -2.
[/quote]
Gravity pulls you down. If you jump out the window you may pass floor zero but that won’t help you; you carry on towards the centre of the earth, you don’t start moving upwards towards floor zero. Zero is an arbitrary point on the scale.

Further, “down” appears before “nearest”. So first it rounds downwards and then stops at the first integer encountered, -2. “Nearest” doesn’t contradict “down”, these are effected sequentially, Mr Spock.

Why should numbers “move inward toward zero”? Zero has no gravity. Zero is merely the whole-number placeholder between 1 and -1. To me, numerically down is towards a lesser amount. If I owe someone $1.20 (or the equivalent in your monetary system) and I can round it down I’ll gladly pay the $1.00. On the other hand, if they owe me then I’m at -$1.20 so I’ll gladly round down their debt amount and accept their payment to me of $2.00.

Levity aside,

[quote=495952:@Garth Hjelte]Well, if you are sternly Spock logical like I am, this is a silly statement. Floor(-1.2) returns -2. It is NOT the nearest whole number, but since it says “down”, it returns -2. Plus, “nearest” contradicts “down” - it doesn’t matter which whole number is “nearest” numerically.

And isn’t “down” a confusing term? In my world, numbers move inward to 0, so “down” for negative numbers means -1.2 becomes -1, not -2.[/quote]
seems to conflate “true” value with “absolute value”. Taking care to handle the negative aspect, Floor(|-1.2|) would, in fact, yield -1 but the value -1.2 != |-1.2|.