|
Fantastic!!
I'm actually literally LOLing.
|
|
|
|
|
Bewdy, had hoped I wouldn't be the only one prepared to admit it.
|
|
|
|
|
|
|
It is hard to say 'wrong' or 'right'...
The Euclidean way is much more perfect (consistent) and fits better math as science, however Donald Knuth promoted an other way (called floored division), which found to be better for computer science and used by most languages today...
Modulo operation - Wikipedia[^] - there is a nice table on the left side about programming languages...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: It is hard to say 'wrong' or 'right'
Yes, I agree... except of course the one that returns -1 is right.
Just kidding. I really do agree.
Kornfeld Eliyahu Peter wrote: Donald Knuth promoted an other way (called floored division), which found to be better for computer science and used by most languages today.
Very interesting and I agree that this version is better for computer science.
|
|
|
|
|
raddevus wrote: Python and Ruby are garbage languages and I'm sure this will be their end.
I would also include some others like Javascript, but at least it knows its math and so it lives on (for now).
-1%20 = 19 is so counter intuitive, I don't know how they reached that conclusion, however, we can see here that in Python the result of a modulo(%) operation has to be of the same sign and strictly smaller than the second operand.
Edit:
And so python says
print 1%-20; = -19.
print -1%-20; = -1. (finally)
Someone needs to go back to the math class they hated.
I am not the one who knocks. I never knock.
In fact, I hate knocking.
modified 30-Aug-17 4:50am.
|
|
|
|
|
GKP1992 wrote: -1%20 = 19 is so counter intuitive,
I agree. It is interesting that a small number of languages use this different way which is maybe more loyal to math.
|
|
|
|
|
Well done
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.
|
|
|
|
|
|
Same discussion here, see answer 2:How to implement a circular counter?[^]
For me the result of c# (-1) is also more intuitive if I look e.g. x % 2 around Zero...
1 % 2 = 0 * 2 rem: 1
0 % 2 = 0 * 2 rem: 0
-1% 2 = 0 * 2 rem: -1
... which for me does Show a Kind of symetrie. I agree, a very unscientific Argumentation
Bruno
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Someone pointed out this in the link you posted:
Quote: Please note that C# and C++'s % operator is actually NOT a modulo, it's remainder.
Could it be that this is true? In that case making assumptions can have unexpected consequences. I'm going to look what the MSDN has to say about that...
There you go:
Quote: % Operator (C# Reference)
The % operator computes the remainder after dividing its first operand by its second. All numeric types have predefined remainder operators.
The user can't update the up: we update it for them (Choice in the CP poll)
|
|
|
|
|
To make it even worse, it's not even the same in all languages, and to make that even worse there are languages that didn't even make a choice which way to do it (you have already guessed which languages that were).
There's a nice list at the right side of the relevant wikipedia page, which is interestingly the Modulo operation page while the point is that in most languages it's really the remainder operation.
This is all bullshit and programming sucks.
|
|
|
|
|
|
|
|
I don't think this is really wrong.
This is probably due to confusion between modulo and remainder.
There seems to be the same for positive numbers.
But for negative numbers, there are different.
Remainder work as expected.
But modulo work as following: returns the difference of the first number, and the biggest integer (possibly negative) multiple of the second number that is less than the first number.
So in our example: -1 - -20 = 19
That's why lot of programming languages have 2 "modulo" operators, one for modulo operations and one for remainder operations.
|
|
|
|
|
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.fmod(-1,20)
-1.0
>>>
modified 31-Aug-17 9:14am.
|
|
|
|
|
Having given this some thought... I have come to the conclusion that the argument that the remainder must never be negative must make sense only to they who realllllly don't like improper fractions and consider negative fractions to be improper.
But I have not found anything explaining why someone would feel that way. I have a guess, but no way to confirm it.
modified 2-Sep-17 13:05pm.
|
|
|
|
|
Former Chairman of Federal Reserve to Speak at Blockchain Conference
In 2013, Bernanke wrote that virtual currencies “could have a long term promise”, and addressed his thoughts to congress. However, more recently in 2015, Bernanke also said that there were some “serious problems” with virtual currencies, including issues with anonymity and the lack of stability.
OK, no more blockchain posts for a while now, at least from me
|
|
|
|
|
next Tuesday, 50 leaders representing the business, technology, government, academia, arts and non-profit sectors arrive on Sir Richard Branson’s private island to spend three packed days discussing blockchain technology for the third annual Blockchain Summit....“We’re trying always to invite the biggest thinkers of this world and discuss how we can use this technology to really do good,” said Bitfury chief executive Valery Vavilov.
On Sir Richard Branson's Necker Island, Bitfury Hosts Third Annual Blockchain Summit
And elsewhere, 5000000 people around the world are trying to figure out how to use blockchain to do really evil things.
|
|
|
|
|
Actually, the title is a little misleading. I accidentally ran across something that will crash the compiler process which runs separately from the IDE. It's not that big a deal but it seems to be repeatable. This will happen when you put an invalid entry in the initialization list of a class constructor. For example :
class DerivedClass()
: BaseClass( defaultArg )
, m_ValidMember( 0 )
, m_InvalidMember( 0 ) {
}
As anyone else run across something like this or other ways to cause mayhem with VS17?
|
|
|
|
|
Just one?
(yes, I know the title is misleading, but I couldn't resist.)
|
|
|
|
|
|
What, you expect MS to stop working on the next half-baked version to fix an old bug???
Since VS2010 they've stopped doing that, 13 is relatively stable (but has issues ms simply ignored because they were rushing out 15), 15 has even more issues ms simply ignores because they are already working on the next.
You can bet on the next version (VS2019?) still having that exact same problem.
Once upon a time ms [mostly] finished software before release, but since the new mgmt that is no longer the case - and that's across the entire product range. A bad habit they took from google.
Just be happy ms/google etc don't build planes or self driving cars and ... oh elephant
signature upgrading ... please wait.
|
|
|
|