Closed TechnVision closed 1 year ago
Tagging subscribers to this area: @dotnet/area-system-numerics See info in area-owners.md if you want to be subscribed.
Author: | TechnVision |
---|---|
Assignees: | - |
Labels: | `area-System.Numerics`, `untriaged` |
Milestone: | - |
The example you provided correctly rounds 99.50 to 100
Math.Round(decimal)
uses MidpointRounding.ToEven
rounding mode by default, you can use an overload that accepts custom rounding mode and pass MidpointRounding.AwayFromZero
.
@KeterSCP
@TechnVision that's not the code you shared in your reproduction example - there you have 99.50.
As mentioned above by @EgorBo, in .NET default rounding is performed to the nearest even
value. If you want another strategy, you should specify this explicitly by passing MidpointRounding
parameter
I'm a Maths teacher. If the default behaviour is to "round" off 0.5 to the nearest even number then the default behaviour is against the rules of Maths and is wrong. I imagine that's why the issue was raised (there are other issues with Maths at MS which I'd like to have addressed, but don't know who to direct it to - apparently nobody at all there knows how to expand brackets). 0.5 should ALWAYS be rounded up, that is the rule in Maths. If a user has entered 0.5, then that could've already been rounded off from something like 0.51243217352, but now .NET is randomly "rounding" that down - that is in fact truncation, not rounding, and no rounding function should have that behaviour, only truncating functions. Even 8.500000000000000000000 should be rounded up for this precise reason. You shouldn't presume to know the accuracy of the entered number, just follow the rules of Maths.
If the default behaviour is to "round" off 0.5 to the nearest even number then the default behaviour is against the rules of Maths and is wrong
Wikipedia has a nice section explaining this in more detail and why it is important: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even
Mathematics has many different rules, scenarios, and considerations and this is carefully considered and designed to provide the greatest default accuracy given the constraints and limitations of the systems we have to work with.
It is likewise not specific to Microsoft. It is the default behavior for most major programming languages and computer hardware around the world. Designed by other mathematicians and statisticians who are experts in their field and have done years of research, collaboration, and peer review on the subject.
Ultimately, we are not working with math as you would on paper. We do not have the flexibility of the human brain, we do not have infinite precision and the ability to represent data arbitrarily.
We have a finite set of bits that can represent a finite amount of data. That data is itself representing something which might be infinitely precise or which may require infinite precision due to it being irrational.
Computers then must account for this to avoid introducing greater than necessary error, just as you would when using mathematics in most practical fields, such as engineering or architecture. There is also a level of tolerance given to account for fluctuations, imprecisions, and other error that might be introduced.
Wikipedia has a nice section explaining this in more detail and why it is important
Wikipedia doesn't know how to expand brackets either (nor how Terms work), so there's that.
Designed by other mathematicians and statisticians who are experts in their field
Can you cite any Mathematicians who have said this? All I see is a reference to IEEE, which isn't a Mathematical body. It looks to me like, just as it is with expanding brackets, these systems have been written without checking with actual Mathematicians.
It doesn't apply to only IEEE, as covered by the Wikipedia page it's also known as (among other names):
convergent rounding, statistician's rounding, Dutch rounding, Gaussian rounding, odd–even rounding, or bankers' rounding.
If you'd like more information on why IEEE 754 went the way it did, I'd suggest you download the specification to see a list of its own citations and people who worked on it. Both in the most recent and the overall historical specifications from 1985 and 2008.
Regardless, however, this is never going to change for .NET. It won't change for C, Rust, Java, Python 3, Go, Swift, etc. It likewise won't change the default behavior in hardware for CPUs (x86, x64, Arm32, Arm64, RISC-V, etc) nor will it change it in GPUs and so on.
This is how computers work. It is the industry standard. It is done for good reason and a person not agreeing with the behavior does not make that behavior incorrect nor does it negate the 50+ year history and general consensus on being correct.
If you don't like it, we have APIs (such as Math.Round) that will allow you to customize the behavior based on your exact needs. The same is true in most other languages and they often provide similar functionality to deviate from the standard behavior of round ties to even.
It doesn't apply to only IEEE, as covered by the Wikipedia page it's also known as (among other names):
convergent rounding, statistician's rounding, Dutch rounding, Gaussian rounding, odd–even rounding, or bankers' rounding.
None of which had any references (only IEEE did), and I can tell you as a Statistician I've never heard of Statistician's rounding. Did you know the Wikipedia page on "implicit multiplication" never mentions Terms or The Distributive Law even once?
a person not agreeing...does not make that behavior incorrect
I'm not "a person" - I'm a Maths teacher, with Maths textbooks which specify why that behaviour is wrong mathematically.
general consensus on being correct
The general consensus has led to a situation where literally only 1 e-calculator (MathGPT) correctly expands brackets - literally every other e-calculator (including every MS product which does calculations, like Excel) incorrectly interpret bracketed terms (which leads to people saying "But the Windows calculator says...", and then I have to explain why the Windows calculator is wrong. Welcome to why this has got my back up - I'm wondering how many other places MS has implemented wrong Maths).
The onus is not on us to satisfy you. It's on you to put forth a good enough case to change the literal industry standard.
@SmartmanApps You being unaware of other rounding algorithms doesn't make them wrong or invalid. They exist for a reason. One of the reasons being accumulation of error which happens to be extremely relevant when dealing with floating point math which operates on base-2 and not base-10.
Likewise, the order of operations is not as universal as you may think. While some countries teach PEMDAS, others teach BEDMAS, BIDMAS, or others. They don't necessarily agree on priorities of certain operations such as implicit multiplication. There are expressions which work universally across most of these systems provided you use explicit parentheses to disambiguate. Similarly, if you want to disambiguate which rounding algorithm you want to use, you have the choice.
The onus is not on us to satisfy you. It's on you to put forth a good enough case to change the literal industry standard.
I already said...
If a user has entered 0.5, then that could've already been rounded off from something like 0.51243217352, but now .NET is randomly "rounding" that down... You shouldn't presume to know the accuracy of the entered number, just follow the rules of Maths
If you're happy to accept that the industry accepts wrong Maths then there's nothing I can say to convince you.
with Maths textbooks which specify why that behaviour is wrong mathematically.
Fwiw, I checked my graduate books on maths and stats, and I could find nothing indicating this is wrong mathematically.
Could you link your sources?
I can tell you as a Statistician I've never heard of Statistician's rounding.
Not sure what to tell you? Wikipedia has citations going back over 100 years, most notably
The origin of the terms unbiased rounding and statistician's rounding are fairly self-explanatory. In the 1906 fourth edition of Probability and Theory of Errors[38] Robert Simpson Woodward called this "the computer's rule" indicating that it was then in common use by human computers who calculated mathematical tables. Churchill Eisenhart indicated the practice was already "well established" in data analysis by the 1940s.[39]
[38] - Probability and theory of errors. 1906. [39] - Churchill Eisenhart (1947). "Effects of Rounding or Grouping Data". In Eisenhart; Hastay; Wallis (eds.). Selected Techniques of Statistical Analysis for Scientific and Industrial Research, and Production and Management Engineering. New York: McGraw-Hill. pp. 187–223. Retrieved 2014-01-30.
I'm not "a person" - I'm a Maths teacher, with Maths textbooks which specify why that behaviour is wrong mathematically.
We have several team members with their PhD or Masters in Mathematics, Statistics, Computer Science, and so on. Likewise this is true for many of the people that work on international standards such as IEEE 754:1985, 2008, and 2019; various programming language standards, and so forth.
Being a maths teacher doesn't make you automatically correct in all things math related. If you asked 200 different maths teachers a question, you'd get several different answers and some of it would depend on the depth of their background and even country of origin. There isn't one universal math standard, there is just general consensus on some points and many places where ambiguities may exist and are intentionally avoided accordingly.
The general consensus has led to a situation where literally only 1 e-calculator (MathGPT) correctly expands brackets - literally every other e-calculator (including every MS product which does calculations, like Excel) incorrectly interpret bracketed terms (which leads to people saying "But the Windows calculator says...", and then I have to explain why the Windows calculator is wrong. Welcome to why this has got my back up - I'm wondering how many other places MS has implemented wrong Maths).
That might imply that the others aren't correct and that the standard is changing.
Math is not, nor has it even been, set in stone. That's why we have proofs, that's why different books will disagree on how to expand something like 3y/2x-1
, because it is technically ambiguous (and with no well defined standard) as to what is the denominator. You will get many different people claiming different answers accordingly.
The most common two patterns (but there are others) of the above are notably:
(((2 * x) / 3) * y) - 1
((2 * x) / (3 * y)) - 1
And different places may teach different rules for which is correct. That's why being explicit can be important.
If a user has entered 0.5, then that could've already been rounded off from something like 0.51243217352, but now .NET is randomly "rounding" that down... You shouldn't presume to know the accuracy of the entered number, just follow the rules of Maths
The user has then performed two operations and already caused a loss in precision.
You could inversely argue that if a user had 5.45
and rounded it to 1 fractional digit, using your rules (making it 5.5
) and then rounded again (now becoming 6
) that it is less correct. With IEEE 754 rules it becomes 5.45
-> 5.4
-> 5
.
You can find examples for both rounding modes where some will result in more accurate and others in less accurate answers.
The entire point of round to even
is that it removes the majority of bias for most cases, especially for binary based rounding modes where there is at least a 0.5 ULP of error.
Given 1000 random floats, rounded, and then summed. round to even
will on average produce the more accurate result, accordingly.
If you're happy to accept that the industry accepts wrong Maths
Nothing appears to be wrong here. All the papers I can find on precision, rounding, errors, and whatnot do not seem to agree with you at all.
So far every source I've actually checked recognizes and explains the issue, and the pros/cons of the possible varying strategies. It's only your posts which contain absolutes about what maths says, but without a single reference.
For all I know, you simply misread or misinterpreted something you wrote a long time ago. Without citations and sources, this is no better than another random person coming, saying that are an expert and insisting things work the opposite way you want them. Both are equally not useful.
will on average produce the more accurate result, accordingly.
A default which produces more accurate answers on average seems very much like the desired place to be.
If we ever changed this, it would certainly result in many apps now producing worse results on average, which would be an enormous negative impact to both programers and their users.
I'm going to close as resolved . Thanks for the report though.
Likewise, the order of operations is not as universal as you may think. While some countries teach PEMDAS, others teach BEDMAS, BIDMAS, or others.
Oh here we go. Yes, it IS universal. The acronyms aren't the rules - they are ways to remember the rules. See my thread - has textbook references and everything Order of operations thread index
@SmartmanApps can you list your textbook references for:
with Maths textbooks which specify why that behaviour is wrong mathematically.
I would be happy to go read them and see which cases they are addressing, and if they make any counterpoints to the cases the default here aims to do well overall with.
We have several team members with their PhD or Masters in Mathematics,
Yes, I've seen those type of people getting order of operations wrong too, because they've forgotten their High School Maths. I've never seen a High School teacher get it wrong.
Math is not, nor has it even been, set in stone. That's why we have proofs, that's why different books will disagree on how to expand something like
3y/2x-1
, because it is technically ambiguous (and with no well defined standard)
The defined standard can be found in literally any Year 7-8 Maths textbook. We've had the same rules for at least 400 years. See my thread, complete with textbook references Order of operations thread index
Just checked with one of my DnD buddies. Math teacher in this area (greater seattle school district). He says he teaches it one way, but there isn't consensus on this, and it is ambiguous. He teaches the ambiguity and even tests kids to point out why the ambiguity matters. So perhaps this is just something specific to your district, home, or upbringing? :)
My math degree didn't go into this aspect of notation. But we certainly covered some of this other stuff. I'd be happy to look at your references on the rounding topic to see if that adds anything interesting to the discussion. We have a good math library here at UW (and good libraries in MS itself), that we can dive into :)
He says he teaches it one way, but there isn't consensus on this, and it is ambiguous. He teaches the ambiguity and even tests kids to point out why the ambiguity matters. So perhaps this is just something specific to your district, home, or upbringing?
Ask him to check the syllabus. I've taught both Australian and U.K. syllabus, and have looked at the syllabus from some other countries too - as far as I can see it's the same in every syllabus (well, it'd be a problem if different countries did Maths differently! Just look at what happened with that NASA mission because of Imperial/Metric confusion - fortunately wasn't a manned flight!). I've run into people previously who said it was taught differently in their country, and when I've checked the syllabus it wasn't different, so if they were taught differently then their teacher wasn't following the syllabus. And even if that did happen (the teacher didn't follow the syllabus), that doesn't mean there's ambiguity - it just means some teachers aren't following the syllabus! (though I'm still sceptical of that claim, as I've never seen a High School Maths teacher get it wrong)
See my thread, complete with textbook references Order of operations thread index
You can arbitrarily define the rules for ambiguous cases but that doesn't make it an universally accepted standard.
In fact, once you stop being U.S. centric, you would realise that other countries teach this differently and acknowledge the ambiguities. If I were to strictly go with the Czech text book approach then you first calculate the brackets from inside out. Then you end up with the ambiguous implicit vs. explicit multiplication, which - for the purpose of elementary school math - is treated equally. Then you apply the "multiplication and division" have same priority rule and you process them left to right.
You may disagree with it but that's all you can do. It's not mathematically wrong. It's just not universally defined and not universally taught the same in every country. Once we go beyond the basics we are thought that this is not well defined, what is the more likely intention, and how to write the expressions in a way that is not ambiguous (according to the rules understood by majority of people).
We've had the same rules for at least 400 years.
Here's what is effectively a blog post, from a professor at Harvard covering some of these ambiguities and why they exist: https://people.math.harvard.edu/~knill/pedagogy/ambiguity/
Or how about this paper published on a government website from several professors at Purdue: https://files.eric.ed.gov/fulltext/EJ1169645.pdf
or from Notre Dame: https://ndpr.nd.edu/reviews/representation-and-productive-ambiguity-in-mathematics-and-the-sciences/
or https://scholarworks.umt.edu/cgi/viewcontent.cgi?article=1186&context=tme from the University of Montana
Many of these then have their own further citations that go even more in depth into other sources of ambiguities both modern and historical.
We could go on for hours providing counter examples of why you think the rules are set in stone and where I provide counters showing they aren't and they never have been.
But, at the end of the day, .NET (and most computers) work this way. It isn't going to change and arguing about it won't be productive. Computers in general will continue disagreeing with your stance and people will continue to be taught the way that everything is standardizing on, which is that 2(x+y)
is shorthand for 2 * (x + y)
. They will rely on this more and more as computers make it the de-facto source of truth for doing fact checking. People will either adapt to this, or they'll end up being left behind.
well, it'd be a problem if different countries did Maths differently
Different countries absolutely do math differently. This was very evident when i was getting my degree in it and working with different students and teachers from all over the world. :)
Again though, i'd still want to see your references (esp. on things like rounding). So far, despite a few requests, nothing has been supplied. As i've been able to find a lot of references in the other direction, my presumption is to assume that that is the consensus i should go with, and that you're possibly just mistaken or misinformed. If you do want to add that stuff at some point, I'll go look into it. Thanks!
See my thread, complete with textbook references Order of operations thread index
You can arbitrarily define the rules for ambiguous cases but that doesn't make it an universally accepted standard.
I see you didn't read the thread. There are textbook references in there. It's literally the standard.
In fact, once you stop being U.S. centric
In fact, I'm in Australia, and have taught the U.K. syllabus too.
If I were to strictly go with the Czech text book approach
Give me a reference/screenshot of a Czech textbook. Happy to look at it.
It's just not universally defined and not universally taught the same in every country
Until you can show me a contrary example, yes it is universal. I've even seen someone on a forum specifically set out to find contrary examples and admitted he couldn't find any.
well, it'd be a problem if different countries did Maths differently
He just did.
I've even seen someone on a forum specifically set out to find contrary examples
I'm still waiting for you to provide your examples for the statements you made earlier... :-/
Happy to look at it.
Please see https://github.com/dotnet/runtime/issues/92849#issuecomment-1741838524
You are making the claims. It's not on us to prove you wrong. It's on you to prove yourself right, and to acutally back up your statements with evidence if you want us to make any changes here. We're not going to do it just because you emphatically insist you are correct.
Here's what is effectively a blog post, from a professor at Harvard
I already addressed that previously...
We have several team members with their PhD or Masters in Mathematics,
Yes, I've seen those type of people getting order of operations wrong too, because they've forgotten their High School Maths. I've never seen a High School teacher get it wrong.
Read through them and see if they mention Terms or The Distributive Law even once. Welcome to why they think it's "ambiguous". Now tell them to pick up any old Year 7 Maths textbook.
Until you can show me a contrary example,
You yourself said in https://github.com/dotnet/runtime/issues/92849#issuecomment-1741838036
The general consensus has led to a situation where literally only 1 e-calculator (MathGPT) correctly expands brackets - literally every other e-calculator (including every MS product which does calculations, like Excel) incorrectly interpret bracketed terms (which leads to people saying "But the Windows calculator says...", and then I have to explain why the Windows calculator is wrong. Welcome to why this has got my back up - I'm wondering how many other places MS has implemented wrong Maths).
Which is to say, that computers and electronic calculators in general don't agree with your stance. Considering that a large population of the world carries around such a device in their pocket, I'd say there is a de-facto ambiguity ;)
This is likewise not Microsoft specific, see also Linux, iOS, Android, MacOS, various graphing or scientific calculators (Sharp vs Texas Instruments vs Casio vs ...), and so on. It's not consistent and that is definitive proof of ambiguities
I already addressed that previously...
Basically, your argument is: "You can't show me a case where i'm wrong."
Shows case.
"But everyone who doesn't agree with me is wrong. And that's just a case of this".
Again, the onus is on you to defend your position. As i've stated, actually going and looking into the literature on things like rounding I cannot find anything that backs up your position. Note: a "Year 7 Maths textbook" is def not sufficient against actual research papers on this topic that are actually going in depth onto the issues. A year 7 textbook is what we teach children as a simplistic way to handle basic things. In your gradeschool syllabus, you might go by the rule that you teach them simplistic approximations that are easy for them to understand. However, in the far more interesting and advanced domains that computers have to occupy, the domain is much more rich and varied.
If you want to argue that it's appropriate to teach children a particular rounding method as a default, that's fine. But this is not a programming language for children. It's one for professionals solving real world use cases that need far more appropriate solutions.
--
Note: there are programming language directed at being teaching tools for children. In such a domain, i might agree on a different set of defaults. But i also think it's probably good to not sugar coat this domain too much, and to allow any programmer, of any capability, to start understanding the complexity here.
Give me a reference/screenshot of a Czech textbook. Happy to look at it.
https://www.matematika.cz/poradi-matematickych-operaci/ ... is this good enough for you or does it not go into enough detail? It specifies the rules we are taught in elementary school and how to apply them. It explicitly avoid the "implicit multiplication" case and always uses the explicit .
in place of it. Effectively, it leaves the implicit multiplication undefined at that point. The top rules are almost verbatim repeated in every text book but details and examples may differ.
We have syllabus under the name "Osnovy matematiky" which doesn't actually go into the detail aside from mentioning "Pořadí početních výkonů" (order of operations). The details are then provided in individual text books that are sanctioned but written by authors not affiliated with the government. There's not a single source of truth. I am not aware of any of these books being publicly available online.
Until you can show me a contrary example,
You yourself said in #92849 (comment)
I was referring to textbooks. Teachers know better than to use e-calculators.
This is likewise not Microsoft specific, see also Linux, iOS, Android, MacOS, various graphing or scientific calculators (Sharp vs Texas Instruments vs Casio vs ...), and so on. It's not consistent and that is definitive proof of ambiguities
People doing things wrong doesn't prove the rules are ambiguous, only proves that people aren't following the rules.
Also it's Texas Instruments Vs. literally every other brand... and it's even in the Texas Instruments manual as to why they give the wrong answer (they follow the Primary school rule, which of course doesn't work once you have coefficients of bracketed terms).
As for MS specific, yes they SPECIFALLY just make the coefficient disappear, literally (other ones make different mistakes - Google adds brackets in the wrong place for example). If I type 8/2(2+2) into the Windows calculator, it gives me the answer for 8/(2+2). Excel won't even let you type it in without a multiply. There's no "industry standard" other than "we don't know how to do this so we're gonna make up our own rules". Even within MS you have different people doing it different ways. Only MathGPT actually made the effort to make sure that answers are correct (and I gave them positive feedback about that, of which they were most appreciative).
Appreciate the effort, but...
It specifies the rules we are taught in elementary school
...which only applies to bracketed terms that don't have a coefficient (more precisely the coefficient is 1). In year 7 we teach The Distributive Law, and introduce bracketed expressions with a non-1 coefficient. Again, I cover all of this in my thread Order of operations thread index i.e. the Primary School rule is superseded in High School, just like the "rule" that "there is no such thing as a square root of a negative number" is superseded in University (which I also discussed in my thread).
I was referring to textbooks.
RIght. And textbooks are not in agreement either. There are varying rules they apply, often depending on which system is taught and the varying beliefs of various authors on what is the best and clearest system for people to use.
You pointing to the specific grade7 textbook you use to teach has no bearing. It's one approach. You might feel like it's the best approach, and one you wish was universally agreed upon for all domains. But that's not the case. Literally links have been provided showing this.
--
Finally, at this point, i'm just going to assume you're unwilling to actually produce links backing up your statements on rounding. I'm uncertain why, given your certainty that it was established as the only true way for math to work. But c'est la vie. Given the absence of any actual evidence presented, I'll stick with the default position of:
As such, we will not change anything.
In year 7 we teach The Distributive Law
Yaay? As i said, elementary schools teach things so elementary school students can understand. They are not some sort of universal truth that applies to the complex domains we're discussing the global ecosystem dotnet has to work within. If you want to be convincing, you'll need to actually deal with the topic at hand, which requires references and consensus that goes all the way through the mathematical sphere, and is not just limited to grade-school mathematics in your single textbook.
I already addressed that previously...
Basically, your argument is: "You can't show me a case where i'm wrong."
Shows case.
You know 2 wrongs don't make a right, right? A blog post by someone who ignores what's actually taught in Maths textbooks doesn't constitute a contradiction of what's actually taught in Maths textbooks. If I say "there's no such thing as the sun!", does that now make it ambiguous as to whether the sun exists or not? A blog post isn't a Maths textbook. My thread even talks about Lennes' letter, which was a University person doing this exact thing more than 100 years ago! (he also didn't mention Terms or The Distributive Law - common theme there)
Again, the onus is on you to defend your position. As i've stated, actually going and looking into the literature on things like rounding I cannot find anything that backs up your position. Note: a "Year 7 Maths textbook" is def not sufficient against actual research papers on this topic that are actually going in depth onto the issues.
Well, I was going to look it up, but if that's going to be your attitude then there's no point. I'm glad you posted this before I wasted my time looking it up. BTW it's not "my position", it's the position of Maths textbooks the world over, and MathGPT for one went to the effort to make sure their results were correct.
Primary School rule is superseded in High School
...which is exactly what I said earlier:
Once we go beyond the basics we are thought that this is not well defined, what is the more likely intention, and how to write the expressions in a way that is not ambiguous (according to the rules understood by majority of people).
You kept bringing up "Year 7 Maths textbook". I have no frame of reference for that since our school system is organized differently. I assumed that refers to elementary school (in our system) where we also learn the distributive law.
Primary School rule is superseded in High School,
How should I understand "superseded" in this context? Are you saying that it changes the rules or that it extends them? Because we most certainly still keep the primary school rule unchanged. We just extend it for additional concepts like functions.
just like the "rule" that "there is no such thing as a square root of a negative number" is superseded in University
I think we are finally getting somewhere. Some of these rules are domain specific (!). What is rule for real numbers may not be rule for imaginary numbers. In exactly the same way, what is common [elementary school] rounding convention for real numbers doesn't necessarily apply to the domain of floating point numbers.
You know 2 wrongs don't make a right, right?
You literally said that this doesn't exist. Links showing it exists proves you are incorrect here. You may continue to think that all these cases are wrong, but clearly you cannot put forth the position that this is universal or correct, or that other deep experts in this field are all in agreement. That's not the case.
Well, I was going to look it up, but if that's going to be your attitude then there's no point.
Oh well. If you are unwilling to provide evidence beyond broad claims that don't stand up to scrutiny, then we'll stick with the default staying the same here.
it's the position of Maths textbooks the world over,
Not that i can see at all. I went and looked and found nothing backing up your position on this.
I asked numerous times, and you did not seem willing at all to actually point to anything backing this. When i look though, i can find literally dozens of papers on the topic, spanning decades (honestly, i didn't even bother going further when they go back practically 100 years). This seems to be topic well versed with experts who have given strong numerical, analytical, intuitive, and practical reasons why it is sensible to have all these rounding systems, and what should go into how to pick one.
If you're not willing to engage on that, but simply insist you are right because a 7th-year math textbook says something, then there's no way to progress on this.
A blog post by someone who ignores what's actually taught in Maths textbooks doesn't constitute a contradiction of what's actually taught in Maths textbooks
There were several links to papers from professors with Masters and PhDs in Mathematics from respected Universities provided above, all clearly discussing this ambiguity.
k. My thread even talks about Lennes' letter, which was a University person doing this exact thing more than 100 years ago! (he also didn't mention Terms or The Distributive Law - common theme there)
The common theme seems to be that not everyone agrees. There are many people, professors and respected experts in the field of mathematics, that disagree with your point and that have been linked. Both modern and historical (going back 100 or more years).
But because they don't match your view they are "wrong" and you're "right".
what is common [elementary school] rounding convention for real numbers doesn't necessarily apply to the domain of floating point numbers.
Precisely. I can't even find a single elementary school book that covers these types of numbers. Not a single one. And i've been looking for a while, including those that are particularly about teaching kids about computers and programming. This entire topic seems to be one that the domain is implicitly feeling is just too subtle and complex to be taught to children.
RIght. And textbooks are not in agreement either.
Yes they are. No-one has yet cited any contrary textbook.
You pointing to the specific grade7 textbook you use
I never did that. I said literally any Year 7-8 Maths textbook - they ALL say the same thing. I have more than a dozen textbooks, and they all say the same thing.
Literally links have been provided showing this.
Links which say "Hey, look at B", ignoring the existence of A, does NOT show anything is contrary to A. They need to discuss A if they feel there's issues with A, but none of them ever do.
Finally, at this point, i'm just going to assume you're unwilling to actually
I wasn't unwilling, I just hadn't got to it yet - have you not noticed I've been busy writing replies? - but since then you said you won't believe a textbook anyway, so there's no point.
In year 7 we teach The Distributive Law
Yaay? As i said, elementary schools teach things so elementary school students can understand. They are not some sort of universal truth
No, but The Distributive Law, taught in Year 7, most certainly IS a universal truth.
not just limited to grade-school mathematics in your single textbook.
Again, literally every Year 7-8 Maths textbook, of which I own several.
@SmartmanApps i tried very hard to steelman your argument here. I went looking for you since you have not been willing to link to anything backing up your position. I looked in my own books. I looked deeply online for papers on these topics. I looked to even see if there was information about FP and the realm of student teaching, and i could find nothing supporting your position.
To the best of my undrestanding, reading this thread, all i can glean is that you think that just because your mathbook/syllabus tends to teach rounding in a particular way, for real numbers, to children of a certain age, that that means that that is the way all numbers should be rounded in every domain by default by all systems. Absolutely nothing i've found puts forth this position. Indeed, all i've found is support around the idea that we simplify complex topics to made them digestible by varying groups with varying levels of expertise.
So, in a case like this, your syllabus has a simplified system that works well for novices like your students. But .net is not a system for novices. It's a real world system that solves real world complex programs, with a deep need for varied analytical options for the problems that arise with numeric representation systems. As such, it does not simplify in the way you do for your children. It exposes and makes rational decisions for the needs of the experts in these complex domains.
I wasn't unwilling, I just hadn't got to it yet - have you not noticed I've been busy writing replies? - but since then you said you won't believe a textbook anyway,
a textbook is not truth. A textbook is a particular author's idea of how to teach particular math concepts to a particular audience.
Please point to any year 7 textbooks discussing floating point math, or even getting into complex compound errors arising from rounding issues. I have looked, and i can't find a single one.
Again, literally every Year 7-8 Maths textbook, of which I own several.
Please link to a single one. I'm happy to go see if i can find it in the local math library. I very much want to see what they say on the topic of rounding, how it applies to limited precision domains, and what metrics they are using to justify that their approach to rounding is the only acceptable way to do things by default.
No-one has yet cited any contrary textbook.
It is your claim that this is universal. And you have not cited anything yet. Again, you think the onus is on us to show that you're wrong. That's not how debate or change happens here. If you think you're right, you can't just say "every book i know says this, prove me wrong!". If you want change to happen, it's you that has to supply the evidence that what you are saying is actually true, and that universal consensus exists here.
--
Finally, i should be as plain as possible. Even if literally every year 7 book agrees with you that the best way to teach rounding to year-7 students is a particular way, that has no relevance here. We're not a programming language/runtime for year 7 students. We're a programming language for industry professionals in a wide variety of domains, who have much more real world, complex, and varied needs around numeric precision than a grade 7 student has when they are learning basic mathematical concepts.
Just as you have recognized that grade 7 stuff is superseded by more advanced and subtle mathematics as you get more into maths, the same applies here.
This is why, for example, we don't just limit ourselves to integers (which we would need to if we were trying to only give you the maths you get when you're in grade 1), etc. The maths we provide are advanced and complex to deal with the intersection of teh real world, the realities of computing, and the needs of advanced users working in advanced domains.
If you want to create a programming language for year 7 students, go right ahead :) And you can def make it follow the math rules you feel are best for that audience. But that's not .net, c# or this runtime :)
You kept bringing up "Year 7 Maths textbook". I have no frame of reference for that since our school system is organized differently.
Sorry, I don't know what you call it there - year 7, high school, 1st form,...
How should I understand "superseded" in this context? Are you saying that it changes the rules or that it extends them? Because we most certainly still keep the primary school rule unchanged.
"B" for Brackets, which in Primary School means "inside the Brackets" is replaced in High School with "solve Brackets". i.e. if there are still brackets there, then you're not done with solving brackets yet. If you do 2(2+2)=2(2), then you haven't finished solving Brackets yet - you have to Distribute. Every single MS product I have tried (at least 3) breaks this rule in one way or another (in one case the number literally disappears!). Again, read my thread - I cover all of this.
I think we are finally getting somewhere. Some of these rules are domain specific (!). What is rule for real numbers may not be rule for imaginary numbers. In exactly the same way, what is common [elementary school] rounding convention for real numbers doesn't necessarily apply to the domain of floating point numbers.
0.5 isn't a floating point number.
0.5 isn't a floating point number.
It is, definitionally: https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/lexical-structure.md#6454-real-literals
If no Real_Type_Suffix is specified, the type of the Real_Literal is double
The language says explicitly that it is an instance of a double
which is defined here: https://learn.microsoft.com/en-us/dotnet/api/system.double?view=net-7.0
Represents a double-precision floating-point number.
Note that the language itself even defines the rounding mechanisms used when a particular literal cannot be precisely represented in the target representation. .Net (and every other programming language) then define the semantics of operations on such representations.
And, as Tanner already mentioned:
We have a finite set of bits that can represent a finite amount of data. That data is itself representing something which might be infinitely precise or which may require infinite precision due to it being irrational.
Computers then must account for this to avoid introducing greater than necessary error, just as you would when using mathematics in most practical fields, such as engineering or architecture. There is also a level of tolerance given to account for fluctuations, imprecisions, and other error that might be introduced.
C#, .Net and programming languages in general are not maths systems. They are computer control systems. If you want a math system, use one of the in specific languages dedicated to that task.
A blog post by someone who ignores what's actually taught in Maths textbooks doesn't constitute a contradiction of what's actually taught in Maths textbooks
There were several links to papers from professors with Masters and PhDs in Mathematics from respected Universities provided above, all clearly discussing this ambiguity.
None of which addressed what's in textbooks. Every High School Maths teacher knows it's not ambiguous - we all teach it, sometimes multiple times a year. University professors do not - they teach complex numbers and matrix multiplication and things like that.
k. My thread even talks about Lennes' letter, which was a University person doing this exact thing more than 100 years ago! (he also didn't mention Terms or The Distributive Law - common theme there)
The common theme seems to be that not everyone agrees.
No, the common theme is they ignore the definitions of Terms and The Distributive Law, then treat things that are covered by those as though they are "multiplication" (having totally bypassed solving Brackets and Terms). By Lennes' own admission, not a single textbook did it the way the thought it should be done, but somehow he managed to miss that he was misunderstanding it all himself in the first place.
There are many people, professors and respected experts in the field of mathematics, that disagree with your point and that have been linked.
But they DON'T disagree with Terms and The Distributive Law - that's precisely the point! They literally ignore those 2 rules, then claim "it's ambiguous", "no convention". No, it's not, pick up literally any Year 7-8 Maths textbook - it's all in there, the defined standard.
But because they don't match your view they are "wrong" and you're "right".
They don't match MATHS TEXTBOOKS.
None of which addressed what's in textbooks.
A textbook is not truth. This has been addressed. It's the view of the author of that textbook as to what is an appropriate concept to teach to a particular audience.
No, the common theme is they ignore
Right. Because they do not agree. Because this is not a topic of consensus. And your particular view on what is right, is just that your view. It's fine to have that view. But it is not a universal truth. Nor is it particularly relevant when deciding what view to take for advanced users far above the 7th grade maths level.
They don't match MATHS TEXTBOOKS.
Right. Because they don't agree. A math textbook doesn't define the truth. It defines what a particular author (or body of authors) thinks abstracts a particular section of math appropriately for a particular audience. My math textbooks were routinely superseded as i went up the education ladder to get my degrees in mathematics. The idea that someone would point at a textbook (let alone a year 7 one) as dictating the only truth on a mathematical topic is just silly.
Ok. Just checked with a math teacher relative of mine in vienna. They don't teach it that way either. They have their own system, and it can lead to a different interpretation of some of these constructs. He has no idea where you're getting the idea that there is some fundamental truth on this. He says it's also a case of different systems picking what they think is appropriate for their student body, teaching that, and giving the students the tools to better understand this space and how it can be ambiguous.
Pointing at year-7 mathbooks is particularly silly as we are not creating systems for year-7 students. If we were, your argument would have weight. But we are not. We're creating languages, runtimes, and tools for users working in far more complex and advanced domains, and who have to work with those domains given the practical limitations of how computers work. Within that domain, there are far more research and understanding that warrants the default behaviors taken here. And that research and development has been in practical problem solving for this real world domain, not just about what is simple and effective to teach to a year-7 student.
Description
As title says Math.Round fails to round 0.50 values be it decimal or double data typed, it rounds these values but returns lower values rather than it should add value 1.
For Ex. if I have to round 99.50 and put Math.Round around it then it will return 99 whereas it should return 100.
Reason: in Excel and in SQL server too its returned 100.
Reproduction Steps
Math.Round(99.50M, 0) // 100 is expected. Math.Round(99.49M, 0) // 99 is expected and is Okey. Math.Round(99.51M, 0) // 10 is expected and is Okey.
Expected behavior
Math.Round(99.50M, 0) // 100 is expected.
Actual behavior
Math.Round(99.50M, 0) // 99 is return
Regression?
No response
Known Workarounds
having to write logic for exact 0.50 values while rounding values
Configuration
VS22 Community version along side .Net7, on Win11
Other information
No response