Timeline for Why was BASIC's INT() a floor, and not a truncate?
Current License: CC BY-SA 4.0
29 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 11, 2024 at 21:09 | comment | added | Mark Ransom | @MauryMarkowitz thanks for the link. As I strongly suspected, the processor doesn't have any native support for floating point. So there almost certainly was a floating point library that they utilized. | |
| Sep 11, 2024 at 13:58 | comment | added | Maury Markowitz | @MarkRansom - yes : bitsavers.org/www.computer.museum.uq.edu.au/pdf/… | |
| Sep 10, 2024 at 23:09 | comment | added | Mark Ransom | @supercat without knowing the instruction set or available floating point libraries for early BASIC implementations, it's impossible to know how hard it was either way. Is there a spec for the original machine Dartmouth used? | |
| Sep 10, 2024 at 14:33 | comment | added | supercat | @MarkRansom: Awhile ago I was figuring out how to rework Applesoft's "INT" function to handle common scenarios more quickly, and it turns out that finding the floor of a negative number takes a fair amount more work than truncating toward zero, which made me very aware that the decision wasn't based upon ease of implementation. | |
| Sep 10, 2024 at 0:18 | comment | added | Mark Ransom | @supercat that's what I meant by "defensible". I still hold that it's non-intuitive, but in the end it's all arbitrary anyway. | |
| Sep 9, 2024 at 22:54 | comment | added | supercat | @MarkRansom: For many applications, it's useful having a convert-to-integer function such that INT(X+1)=INT(X)+1 holds for all X. The floor behavior also allows INT(X+0.5) to implement a form of rounding which upholds the aforementioned property. While truncation is easier to implement, floor is much more broadly useful. | |
| Oct 20, 2023 at 14:21 | history | edited | Maury Markowitz | CC BY-SA 4.0 | added 154 characters in body |
| Oct 9, 2023 at 16:11 | comment | added | Mark Ransom | @AndrewMorton I think most people's definition of "integer part" will be the part prior to the decimal point. Your definition is logically defensible, but I don't think many people expect "-4" to be the integer part of "-3.". It's especially confusing that -3.2 and -3.0 will convert to integer differently. | |
| Oct 8, 2023 at 22:37 | history | edited | Peter Cordes | edited tags | |
| Oct 7, 2023 at 14:07 | comment | added | Andrew Morton | @another-dave I should have written a non-negative decimal part. | |
| Oct 7, 2023 at 12:44 | comment | added | dave | @AndrewMorton - but just as readily, -3.2 = (integer part) + (decimal part) = (-3) + (-0.2). | |
| Oct 7, 2023 at 12:36 | comment | added | dave | @gidds - The BBC BASIC definition could have used some proof-reading (by them, not you: "returns a whole number smaller than the number supplied". OK, so clearly INT(9) can return 8 or 7 or 6 or ... but it definitely cannot return 9. | |
| Oct 6, 2023 at 17:49 | comment | added | Andrew Morton | If you see a number as being made of (integer part) + (decimal part) and call truncation the removal of the (decimal part), it makes sense. E.g. 3.2 = (3)+(0.2); -3.2=(-4)+(0.8). | |
| Oct 6, 2023 at 17:33 | comment | added | supercat | @gidds: It's too bad people aren't taught consistent set of distinct meanings for "larger", versus "higher", or "smaller" versus "lower". Describing -1.5 as being both larger and lower than -1.2 would facilitate a lot of discussions regarding integer arithmetic. | |
| Oct 6, 2023 at 16:19 | comment | added | Mark Ransom | I couldn't remember how it worked on the HP 2000 I learned BASIC on, so I looked it up: The INT function is a numeric-valued function which returns the integer part of the numeric expression. The integer part of a number is that integer less than or equal to the number. For example, INT(3.5) = 3 but INT( -3.5) = -4. I don't think I ever used it on negative numbers. That quoted bit seems self-contradictory in its definition of "integer part". | |
| Oct 6, 2023 at 13:00 | comment | added | gidds | FWIW, BBC BASIC also uses floor. The manual says: “This converts a number with a decimal part to a whole number. This function always returns a whole number smaller than the number supplied. Thus INT(23.789) gives 23 whereas INT(-13.3) returns -14.” (my emphasis) | |
| Oct 6, 2023 at 7:26 | history | became hot network question | |||
| Oct 6, 2023 at 2:17 | comment | added | dave | Again FWIW, in the interest of a survey of contemporary languages, FORTRAN II seems to say it truncates towards zero when assigning a REAL value to an INTEGER, but the manual neglects to show an example with a negative value. FORTRAN IV uses the word 'truncate' but again fails to give a negative example. | |
| Oct 6, 2023 at 1:00 | comment | added | Raffzahn | @JonCuster there isn't as much variation as one may assume from the question - all BASIC I can remember use the same interpretation of flooring. | |
| Oct 6, 2023 at 0:35 | answer | added | Raffzahn | timeline score: 35 | |
| Oct 6, 2023 at 0:23 | comment | added | Jon Custer | I gave up a long time ago wondering why different dialects or languages implemented functions slightly differently. Just had to be careful. | |
| Oct 6, 2023 at 0:01 | comment | added | dave | Is this related to whether your language defines a 'modulo' versus 'remainder' function or operator? | |
| Oct 5, 2023 at 23:54 | comment | added | dave | The language doesn't (entier is the only standard transfer function) but an implementation might. | |
| Oct 5, 2023 at 23:54 | comment | added | Raffzahn | Point was to add this information to the question, improving it. | |
| Oct 5, 2023 at 23:48 | comment | added | Maury Markowitz | Not familiar with Algol really, but it also has a INTEGER, which appears to truncate. | |
| Oct 5, 2023 at 23:44 | comment | added | dave | FWIW, the Algol 60 Revised Report defines the standard function entier(E) as returning 'the largest integer which is not greater than E', i.e., it's floor. | |
| Oct 5, 2023 at 23:39 | comment | added | Maury Markowitz | In Atari/Commodore/HP/etc, INT(1.5) = 1, INT(-1.5) = -2. That seems like not what the user would expect. Early Dartmouth, up to 4 IIRC, INT(-1.5)=-1, which seems like what you want. | |
| Oct 5, 2023 at 23:30 | comment | added | Raffzahn | Mind to add examples for either? Also would it be possible to describe the difference you see between them (in context of BASIC)? Doing so might already reveal a very plausible reason :) | |
| Oct 5, 2023 at 23:26 | history | asked | Maury Markowitz | CC BY-SA 4.0 |