Operator MOD
#61
Tomorrow another function or operator will be called unusable, after it has been around for a long time...
Reply
#62
(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!
Reply
#63
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.  Tongue
Reply
#64
On the flawed integer division, this is generated by the QB64PE compiler:

Code: (Select All)
S_0:;
do{
tqbs=qbs_new(0,0);
qbs_set(tqbs,qbs_add(qbs_str((int64)(qbr( 1.5E+0 )/  1 )),qbs_new_txt(" ")));
if (new_error) goto skip1;
makefit(tqbs);
qbs_print(tqbs,0);
qbs_print(nothingstring,1);
skip1:
...


For 64-bit (in "libqb.cpp") it seems this definition is chosen:

Code: (Select All)
#ifdef QB64_NOT_X86
int64 qbr(long double f) {
    int64 i;
    int temp = 0;
    if (f > 9223372036854775807) {
        temp = 1;
        f = f - 9223372036854775808u;
    } // if it's too large for a signed int64, make it an unsigned int64 and return that value if possible.
    if (f < 0)
        i = f - 0.5f;
    else
        i = f + 0.5f;
    if (temp)
        return i | 0x8000000000000000; //+9223372036854775808;
    return i;
}
...


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"?
Reply
#65
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 Big Grin
If eggs are brain food, Biden takes his scrambled.
Reply
#66
(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 Exclamation
Code: (Select All)
Print Fix(1.5) \ 1
Print Using "##"; 1.5 \ 1
Print
Print 1.5 / 1

In Julia, the first result is also a bit peculiar. How do one get 0.666?

[Image: Julia-MOD-Problem2022-12-03.jpg]
Reply
#67
(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 Big Grin
If eggs are brain food, Biden takes his scrambled.
Reply
#68
(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?

Try worshiping Satan. Hey, it worked for the crew who created FreeBASIC.

Pete Big Grin

Something for hard math freaks!  Big Grin QB64 is more correct than Julia (see above)? 
Code: (Select All)
julia> 1.4 \ 1
0.7142857142857143

In Octave too! Is this a bug in two math programs?  Huh
Code: (Select All)
octave:1> 1.5 \ 1
ans = 0.6667
octave:2> 1.4 \ 1
ans = 0.7143
octave:3> mod(1.4, 1)
ans = 0.4000
octave:4> 1.4 / 1
ans = 1.4000
octave:5>
Reply
#69
(12-03-2022, 05:20 PM)Kernelpanic Wrote: In Octave too! Is this a bug in two math programs?  Huh
Code: (Select All)
octave:1> 1.5 \ 1
ans = 0.6667
octave:2> 1.4 \ 1
ans = 0.7143
octave:3> mod(1.4, 1)
ans = 0.4000
octave:4> 1.4 / 1
ans = 1.4000
octave:5>

In Octave the
\
operators does left division, basically dividing the thing on the right by the thing on the left. So
1.4 \ 1
is the same as
1 / 1.4
.
Reply
#70
Like my old baseball coach and math teacher used to say. Operators can be a pitch!

Pete Big Grin
Reply




Users browsing this thread: 33 Guest(s)