11 ms·
Math.Pow(-1, 2) == -1 in Windows 11 Insider build
- smidgeon 1y agoOff by 2, not so bad
- tempodox 1y agoShould we be surprised that Microsoft doesn't know maths? Was the code for that generated by an LLM?
- fn-mote 1y agoI really want to know how this could have passed CI testing. (Comments blame it on UCRT, not .NET but… that doesn’t matter much to me.)
- TZubiri 1y ago(Please hold while we transfer you to the UCRT department, your call is very important to us)
- dist-epoch 1y agoMaybe this is a new optimization, and AI wrote the tests.
- AndroTux 1y ago“Oh, I can see the test is failing. Let me fix this by adjusting the test to expect the currently returned value.” This is unfortunately an actual quote I got from Claude Code after having it write a unit test for me. It ended up mocking the entire method it was supposed to test, resulting in the unit test essentially only testing itself.
- cjbgkagh 1y agoSounds very human. I experienced some junior devs who grew up with TDD and would often just tweak their code to pass their tests without stopping to understand their code at a fundamental level - essentially development through trial and error. Since they were also the ones writing the tests the core assumptions went into both and because they did so without thinking they were more likely to have errors. The test being wrong was more than likely and in those cases it would make sense to fix the test output.
- pydry 1y agoTDD only really works if the test in some sense mirrors the specification. Sometimes people manage it in which case it resembles a mini superpower but mostly they do not. If it mirrors the spec then few people would change it to be wrong to make the test work.
- cjbgkagh 1y agoAFAIK TDD culturally occurred at the same time as the push for 100% test coverage. So we would end up with code bases that were 90% test code and 10% actual code, every individual method had many tests. This meant for every code change there was a 10x test change so test timelines dominated dev timelines, there was a push at the time to expand the test org to be 2x the size of the dev org. AFAIK at MS that was abandoned and the test org was folded into the dev org and now the devs are expected to write and maintain their own tests. I have only seen TDD used poorly, as a crutch, an alternative to thinking deeply about the problem space. If it can be done well I have not personally seen it. Perhaps SQLite, but such projects are an oddity. To me tests at the spec level are largely user acceptance tests which are indeed very useful.
- deleted 1y ago[deleted]
- gosub100 1y agoMaybe its a bug in their telemetry? They have to pass the parameters to azure to data-mine customer activity and azure accidentally returned the incorrect result.
- sksrbWgbfK 1y agoI would definitely expect some kind of test like -1^2 == 1 for such an important SDK, even more if it impacts C++ too. Well, they hopefully have now written this test.
- debo_ 1y agoI've heard people moan that software is getting exponentially worse. Maybe they're right after all /joke
- H8crilA 1y agoAn exponentially astute observation.
- lucaslazarus 1y agoClearly the issue is real and not imaginary
- sksrbWgbfK 1y agoYou're joking but we went from the Ada "contracts and pre/post conditions" to the ReactJS monstrosities instead on improving the whole thing and being more strict.
- monkeyelite 1y ago
- deleted 1y ago[deleted]
- Aardwolf 1y agoThis happens in both C# and C++ according to the report, but what's the link between OS and compiler here? As far as I remember from days when I used Windows, the version of your visual studio (which has the compiler and standard libraries) was not related to the build of your operating system
- dwattttt 1y agoMicrosoft moved to a Universal CRT (UCRT) around Windows 10, both C# and C++ are calling into the OS UCRT there.
- AnimalMuppet 1y agoOne bug to rule them all...
- snickerbockers 1y agoProbably isn't a link between the OS and compiler. the OS kernel is responsible for saving and restoring the floating-point environment every time there's a context switch, my hypothesis is that something went wrong there.
- TZubiri 1y agoSide note. One of the advantages of using proprietary packaged software is supposed to be a unified support and product. In this case the maintainer redirects the issue to some other team and passes the ball as if it were an open source project with 50 dependencies with thin responsibilities "no, if there's an issue with a button, you should report it to GUI-button, we do GUI-form and we just pass the button generation to their library"
- RajT88 1y agoMicrosoft is a many headed beast. Finding the right contact even for employees inside the beast is challenging and a skill all its own.
- nottorp 1y agoI'm more used to hear this kind of 'it's not our fault' crap from state bureaucracies not companies that want me to pay them...
- msk-lywenn 1y agoWhen a company has its street named after themselves and a fleet of buses to carry employees to the company, one can start considering Microsoft as a state with all the necessary bureaucracy.
- Uvix 1y agoFor stuff where they take money, like Azure, Microsoft has clearer lines of support. .NET and Windows are loss leaders.
- Someone 1y agoI disagree with the comment “Both Math.Pow and std::pow invokes the pow function in UCRT, which is shipped with Windows. The issue should be reported to MSVC instead” It’s not the job of a bug reporter to figure that out and to verify that nothing goes wrong in setting up stuff for invoking that function or in getting its output back into the C# world. That’s even more true because the dynamic nature of .NET code makes it far from easy to verify by inspection that that function is just calling the pow function in UCRT. The C# compiler might do constant folding wrong and there might be several ways in which the runtime compiles the CLR code (fast compilation to start running it quickly, slower compilation that produces faster code later if it turns out to be called a lot, etc)
- coldpie 1y agoWhat do you disagree with, exactly? The bug is in an underlying library, so it should be reported to that library. That all seems correct to me, I don't see what there is to disagree with there. The problem with the comment is it does not make ownership of the next steps clear. The maintainer should've either taken the ball ("I will report this to...") or made it clear that the reporter should hold the ball ("We can't fix this here. You should report it to..."). Instead they used the passive voice ("The issue should be reported to..."), which means no one owns it, which means it won't be done, which is a bad way to handle a bug report.
- snickerbockers 1y ago>The bug is in an underlying library they didn't test that they just assumed that since they call a library function the library function must be the root-cause. This is classic bug-punting.
- Y_Y 1y agoIf you can't hunt it, punt it!
- snickerbockers 1y ago
- nkrisc 1y agoLooks like complex numbers are much simplified on Windows 11.
- nottorp 1y agoThey convert the arguments to complex, do it right and the error is at the back conversion step!
- The_suffocated 1y agoNo idea why this happened. Perhaps Math.Pow(x,y) was implemented as 2**(y*log2(x)) without writing special code to deal with the case where x is negative real and y is integer?
- rich_sasha 1y agoIn fairness, the general power function might well be complicated. Dealing with fractional base and exponent, signs (-1^2 makes sense but -1^0.5 doesn't in real numbers). I don't know how that works in code but I can see how this gremlin sneaks in. I don't see how it gets past the test suite though.
- AlienRobot 1y agoHow did this happen? This feels like the easiest function in the world to write a unit test for?
- octocop 1y agoThis. It's like the first example you see when you start learning about unit tests as a concept.
- deleted 1y ago[deleted]
- comrade1234 1y agoHow does the OS still function with a basic bug like this?
- wat10000 1y agoWhat critical OS functionality would this break?
- vermilingua 1y agoI don’t think there is much systems code that needs an exponent of -1, maybe none that needs exponents at all (aside from 2^n, which has opcodes, not C functions)
- terminalbraid 1y agoThe bug is for an exponent of 2. The base is -1.
- Dylan16807 1y agoThey mean power of -1.
- CodesInChaos 1y agoMost critical OS functionality will use integers, not floats. And I'd expect most programmers to write squaring a float as `x * x`.
- dvh 1y agoThere was an article some time ago where someone ran doom with progressively more incorrect value of pi
- mmis1000 1y agoDue to how windows manage dependencies, you can have different versions of same library all the way back to windows xp days. It's not necessary other software on the computer will hit the bug on this version of library.
- waldrews 1y agoThe good thing is, if (-1)^2=-1, we can prove anything! NP=P, every program halts, axiom of choice - math just becomes so much easier.
- Ragnarork 1y agoJoke aside, is there a field (or sub-fields) of mathematics that just... studies what breaking some axioms would do and where would it lead? This seems both completely stupid but also potentially fascinating at the same time.
- debo_ 1y agoThe mathematics equivalent of the any% speedrun community?
- mafuy 1y agoYes. Prominent example is the axiom of choice. There was a LOT of discussion about it by mathematicians. https://plato.stanford.edu/entries/axiom-choice/ https://plato.stanford.edu/entries/axiom-choice/ For instance, with it, you can double the volume of a body by looking at it from a weird angle.
- SetTheorist 1y agoThat's a very misleading description of Banach-Tarski. You need to break up the body into a few (very weird) pieces and maneuver them (via only rigid motions - rotations and translations).
- SetTheorist 1y agoParaconsistent logic looks into logical systems that allow contradictions. A lot of set-theory research is looking into the consequences of various axiomatic assumptions.
- monkeyelite 1y agoIt’s not sub-field. It’s a technique. You relax or change axioms defining your thing and see what happens.
- jasonthorsness 1y agoFrom the response it is already fixed; no details on cause unfortunately: “This uCRT bug has been already reported through another channel a week ago and it got fixed since (OS #58189958: pow(-1, 2) returns -1). It might take a while to be available in the public insider builds”
- Alifatisk 1y ago> If you need to contact us better, joining the osu! Discord server would be best I really dislike how Discord is slowly eating up the web and being used as the primary channel for communication, when most of the community resources resides in their Discord, it makes it hard for me to find relevant information through the web thanks to Discords lock-in
- jjice 1y agoDiscord also has a kind of culture I don't love connecting to for misc environments. I'm sure most are fine, but I've joined software related discords where people are having oddly NSFW chats. They've always been in different channels, but why does this software project need a NSFW channel? I think it's _too_ social for bug reports and questions. I'd prefer a forum or GitHub issues for that kind of thing. Or maybe I'm just getting old.
- deleted 1y ago[deleted]
- chiffaa 1y agoosu! does have a very active github + active official forums, but I assume Joehu suggested Discord because messengers allow for quicker turnaround in cases where publicly documenting the issue and the resolution of it isn't necessary (which is the case here as the issue is on the Microsoft side of things)
- layer8 1y agoFrom the most recent issue comment: “This uCRT bug has been already reported through another channel a week ago and it got fixed since (OS #58189958: pow(-1, 2) returns -1). It might take a while to be available in the public insider builds”.
- haunter 1y agoTIL osu is open source
- on_the_train 1y agoSince this seems to be in ucrt and hence a much more widespread problem, it would be nice to know the CRT/Windows versions affected
- Qem 1y agoReminds me of this 2005 paper: https://www.sciencedirect.com/science/article/abs/pii/S0167947304002026 https://www.sciencedirect.com/science/article/abs/pii/S01679...
- briansm 1y agoReminds me of the Pentium FDIV bug from 1994.... a half-billion-dollar 'ouch' for Intel were many hard lessons were learned. Surely math libraries and optimizations have been a solved problem for the last 20+ years.
- CodesInChaos 1y agoI'm surprised that an optimizing compiler lets this case even hit the general `pow` runtime function. I'd have expected it to replace this call by `x * x` so it doesn't hit the expensive general `pow` function. I find it strange as well that no unit test caught this. Squaring a negative number is definitely a case I'd expect to be covered. Perhaps compiler optimization made this case work in the unit test, allowing the runtime function to break? And then it broken in .net where the JIT compiler is dumber than the C++ compiler?
- shthed 1y agoAnyone got a link to the actual OS bug that caused this? I would love to see an explanation of how it happened and what the code looked like.
- gloosx 1y agoSo they are vibecoding MSVC now? Sweet.
- amai 1y ago30% of all code by Microsoft is written by AIs: https://techcrunch.com/2025/04/29/microsoft-ceo-says-up-to-30-of-the-companys-code-was-written-by-ai/ https://techcrunch.com/2025/04/29/microsoft-ceo-says-up-to-3... So that is the result.
- deleted 1y ago[deleted]