Operator MOD - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: Operator MOD (/showthread.php?tid=1195) |
RE: Operator MOD - mnrvovrfc - 12-03-2022 Tomorrow another function or operator will be called unusable, after it has been around for a long time... RE: Operator MOD - SMcNeill - 12-03-2022 (12-03-2022, 11:56 AM)mnrvovrfc Wrote: Tomorrow another function or operator will be called unusable, after it has been around for a long time... I imagine it'll either be INT or \ After all, that backslash is supposed to represent INTEGER DIVISION, so why the heck isn't INT(x / y) the same as X \ Y ?? It's got to be BROKEN!! The only possible solution is to add a new \\ command to show that we want true integer division and not some strange sort of bankers rounded division! As it is, \ is completely unusable! Code: (Select All) PRINT 1.5 \ 1 2... 2?? 2!!??!! How the heck can you get TWO when taking the INTEGER DIVISION of 1.5 and 1?? Completely unusable! /FAINT!! Someone get on it and fix it right now!! It's wrong, and it's been wrong since the first BASIC had it producing such answers! OMG!! /FAINT AGAIN!! If this keeps us, we're all going to have to go back to programming in COBOL! RE: Operator MOD - SMcNeill - 12-03-2022 Talking about the INTEGER DIVISION symbol (the \ symbol), it reminded me of a story that my father used to tell about when his teacher was teaching them the concept of rounding numbers back in 1946 or so. "Now class," Mrs Gay told them, "when it comes to rounding, we round up if there's half, or more, of something. Otherwise, we round down." Sagely, everyone nodded and pretended to pay attention. (Just like you guys do when I go off onto one of my stories...) "Since everyone is paying such good attention, James, could you look over at the countertop and see what I baked everyone as a snack today?" "Apple pie," my dad exclaimed happily! "Now, I've got three pies here, and I'm going to cut one of them in half." Getting her knife from the top of desk, and a plate, she went over and cut the middle pie in half and carefully slid it onto the plate, before carrying the plate and one of the other pies back to her desk. "Now, I've got one and a half pies here," she informed her class, as they all grinned happily, expecting to be eating pie very soon. "Now remembering what I just told you a moment ago, Marvin, can you tell me how many pies are on my desk, if you round the figure?" "One," Marvin answered, confidently. Frowning, Mrs. Gay looked closely at the half pie she'd carried over to her desk, and then back at the half pie which she'd left sitting over on the countertop. Giving Marvin the benefit of the doubt -- maybe he thought the other pie was larger somehow -- she asked, "And how many pies are there over on the counter, rounded, would you say?" "One," Marvin answered, confidently. "Now Marvin," Mrs Gay chided, "how can they both be one, if we round up the larger half?" "Because I saw some flies over there eating earlier," Marvin assured her, smugly. "I figure there's got to be less than half, if you account for the bites they's already ate out of it!" Sometimes the logic behind rounding just doesn't seem logical. RE: Operator MOD - mnrvovrfc - 12-03-2022 On the flawed integer division, this is generated by the QB64PE compiler: Code: (Select All) S_0:; For 64-bit (in "libqb.cpp") it seems this definition is chosen: Code: (Select All) #ifdef QB64_NOT_X86 This "qbr()" is used in a lot of places such as "PALETTE" and "PSET"... quite amusing. Wait, shouldn't that huge hexadecimal number carry an "u" or "UL" or something like that? Why is it written in decimal while taking away from "f"? RE: Operator MOD - Pete - 12-03-2022 From reading the last two posts, that's why I emphasized earlier about the use of certain mathematical operators as pattern recognizers, as well as the importance to keep things as they are for the sake of backwards compatibility. (That's backwards Steve, not backwoods, unless you live in the Bronx). Oh, and the part Steve left out of his story; I have it on good authority (CNN news) that Steve's father picked his apples way too green, so there was plenty of fly **** left on that pie to make up for any of the missing filling. Pete RE: Operator MOD - Kernelpanic - 12-03-2022 (12-03-2022, 12:08 PM)SMcNeill Wrote: 2... The only explanation for me, it's rounded up to 2 by some function at compile time. Then the result is correct. PS: That's how it is - It is rounded up from 1.5. 1.4 \ 1 = 1 Code: (Select All) Print Fix(1.5) \ 1 In Julia, the first result is also a bit peculiar. How do one get 0.666? RE: Operator MOD - Pete - 12-03-2022 (12-03-2022, 05:07 PM)Kernelpanic Wrote: In Julia, the first result is also a bit peculiar. How do one get 0.666? Try worshiping Satan. Hey, it worked for the crew who created FreeBASIC. Pete RE: Operator MOD - Kernelpanic - 12-03-2022 (12-03-2022, 05:12 PM)Pete Wrote:(12-03-2022, 05:07 PM)Kernelpanic Wrote: In Julia, the first result is also a bit peculiar. How do one get 0.666? Something for hard math freaks! QB64 is more correct than Julia (see above)? Code: (Select All) julia> 1.4 \ 1 In Octave too! Is this a bug in two math programs? Code: (Select All) octave:1> 1.5 \ 1 RE: Operator MOD - DSMan195276 - 12-03-2022 (12-03-2022, 05:20 PM)Kernelpanic Wrote: In Octave too! Is this a bug in two math programs? In Octave the \operators does left division, basically dividing the thing on the right by the thing on the left. So 1.4 \ 1is the same as 1 / 1.4. RE: Operator MOD - Pete - 12-03-2022 Like my old baseball coach and math teacher used to say. Operators can be a pitch! Pete |