r/programming • • Mar 07 '19

calc.exe is now open source; there’s surprising depth in its ancient code

https://arstechnica.com/gadgets/2019/03/calc-exe-is-now-open-source-theres-surprising-depth-in-its-ancient-code/
242 Upvotes

118 comments sorted by

81

u/[deleted] Mar 07 '19

IT'S NOT CALC.EXE!

28

u/TheBestOpinion Mar 07 '19

65

u/tracernz Mar 07 '19

arstechnica.com/gadget...

The source code is for the near-unusable Windows 10 calculator, not the nice calc.exe from previous editions.

40

u/Dunge Mar 07 '19

near-unusable? I love it

25

u/tracernz Mar 07 '19

The binary view is now hidden behind the keypad (takes many more clicks to do things you typically do, like shift/rotate/xor and manually flipping bits), half the real-estate is wasted on a "Memory" view I don't want, I now need multiple clicks to choose the word size, it's ugly...

45

u/elastic_psychiatrist Mar 08 '19 edited Mar 08 '19

takes many more clicks to do things you typically do, like shift/rotate/xor and manually flipping bits

Literally 99.9% of users of the calculator have no idea what any of this means.

45

u/JoseJimeniz Mar 08 '19

Which is why it's awesome when you set the calculator to Programmer mode it is unusable for 99% of programmers.

You think a company of programmers would have some programmers around who would realize how programmers would use a calculator.

8

u/[deleted] Mar 08 '19

Well, the ux team as most of the times has no idea how to make anything usable except for most basic users

3

u/idonteven93 Mar 08 '19

If the UX Team fucked this up, they really didn’t put it through a serious round of A/B testing... Just means that the UX team was bad, not all UX People in general.

6

u/Jestar342 Mar 08 '19

Just like those who fail to recognise there is/was no A/B testing for the native calculator app, and that throwing it around like a buzzword replacement for "doing some research" makes you look silly, you mean?

10

u/tracernz Mar 07 '19

Actually rotate is completely gone! *facepalm*

3

u/Genion1 Mar 08 '19

It's not gone. Click the up arrow below the left shift. all-the-facepalm

6

u/tracernz Mar 08 '19

That makes the usability point nicely. ;)

17

u/GYN-k4H-Q3z-75B Mar 07 '19

What's wrong with the Windows 10 calculator? It works great for me.

16

u/numpad0 Mar 08 '19

Store apps takes forever to load and UI tends to be sparse regardless of circumstances in comparison with Win32 apps

13

u/examinedliving Mar 08 '19

I’ve never seen a usable store app

2

u/[deleted] Mar 08 '19

Only two I’ve ever downloaded and used was Netflix and the Atmos enabler.

-10

u/smutching Mar 08 '19

"5+5" enter

Some random fucking menu and not the answer

19

u/[deleted] Mar 08 '19

???

I've never had this issue.

1

u/smutching Mar 12 '19

You haven't used the windows 10 calculator then :)

Enter is often bound to the history button instead of the equal sign

0

u/[deleted] Mar 08 '19

[deleted]

3

u/[deleted] Mar 08 '19

Maybe there's like a way to set it in the options menu or something, I dunno. Because I've never had that happen. The W10 calculator is kinda shit, but that's mostly in its advanced features. I've never had an issue when doing basic arithmetic, it does exactly what I'd expect.

2

u/Haatveit88 Mar 08 '19

I use it many times a day and that has never happened. I just hit Win key, type "cal", hit enter, and instantly am doing the calculations using numpad. Never had issue with needing to use any menus or anything at all.

7

u/[deleted] Mar 07 '19

It got worse after Windows XP, those guys have no idea about usability.

20

u/Xeverous Mar 08 '19 edited Mar 08 '19

The Windows Calculator app is a modern Windows app written in C++ that ships pre-installed with Windows.

Actually not in the C++, but managed C++ fork that uses ^ pointers, C# keywords and does not compile anywhere else than with specific settings in Visual Studio.

3

u/accidentalginger Mar 08 '19

That would be managed C++, and has nothing to do with WinRT

1

u/Xeverous Mar 08 '19

ty, edited

82

u/Acceptable_Damage Mar 07 '19

Microsoft's embrace and adoption of open source software has continued with the surprising decision to publish the code for Windows Calculator

I'm so hyped. Now that we have a crappy calculator, it will finally be the year of the Linux desktop.

10

u/maccio92 Mar 07 '19

What's crappy about it?

18

u/Acceptable_Damage Mar 08 '19

Not much apart from the fact that it's kinda ugly, but that doesn't matter.

I was mainly exaggerating for the sake of the comment. My actual point: There are like 10 projects that have made calculators that work just as well. Having the source code of another calculator is not very useful and the article makes it look like Microsoft just made a huge collaboration to open source.

15

u/abelincolncodes Mar 08 '19

Their calculator is actually pretty interesting in that it uses rational numbers for most calculations instead of just floating point arithmetic. This helps keep precision for operations like 1/3 + 1/3 + 1/3, which in a naive calculator wouldn't be 1 because of floating point errors.

I'm sure other calculator projects exist that do the same, but the arithmetic engine (not the ui) in calc has been in use for decades by millions of people. It's probably a pretty good reference of what to do when writing a calculator

22

u/zvrba Mar 08 '19

Having the source code of another calculator is not very useful

If you had read the MS blog post, you'd figure out their intention was to release a project demonstrating the use of UWP apis, azure pipelines, etc... THAT is its usefulness.

18

u/MacHaggis Mar 08 '19 edited May 16 '25

busy scary overconfident wakeful axiomatic consist seemly plant lunchroom hurry

This post was mass deleted and anonymized with Redact

12

u/schmidthuber Mar 08 '19

Only for processing all of the telemetry data it collects

0

u/Shift84 Mar 08 '19

Honestly, just ready the headline it sounds like a gee whiz thing from the jump.

0

u/Iamsodarncool Mar 08 '19 edited Mar 09 '19

There are like 10 projects that have made calculators that work just as well.

Any recommendations?

4

u/JW_00000 Mar 08 '19

Gnome Calculator, KCalc, Qalculate

1

u/Iamsodarncool Mar 09 '19

Qualculate looks awesome, thank you!

3

u/monitorius1 Mar 07 '19

Startup time?

14

u/Dunge Mar 07 '19

Takes less 100ms for me to open it..

22

u/H_Psi Mar 07 '19

[laughs in dc]

3

u/monitorius1 Mar 08 '19 edited Mar 08 '19

Takes up to 4 seconds to open it for me (cold) and up to a second (warm). I have a calculator button on the keyboard, so delay is very noticeable.

6

u/numpad0 Mar 08 '19

How long does it take to open calc.exe? 10ms?

1

u/oblio- Mar 08 '19

Yes, calc.exe is much faster. Now I can't show off my mad calculatoring reflexes which I regularly hone by playing Counter Strike...

2

u/jcelerier Mar 08 '19

Is this satire

-2

u/phunphun Mar 08 '19

You must have an SSD.

1

u/[deleted] Mar 08 '19

Better support for brackets wouldn't hurt

1

u/nalimixam Mar 08 '19

I don't like that it hasn't a moveable cursor in the input field. Fir example, when I paste in decimal numbers that are using a comma instead of a dot, that comma is removed and I have to delete the last digits to re enter a dot...

57

u/shevy-ruby Mar 07 '19

"calc.exe is now open source; there's surprising depth in its ancient code"

Well ... surprising depth hmmm...

That - or perhaps the folks writing articles at arstechnica are just very easily impressed.

26

u/feelingfeel Mar 07 '19

in other words: 80085

32

u/Nemesis_Ghost Mar 07 '19

Did you RTF? It's not just a simple arithmetic application. It actually tries to store the numbers as rational instead of just floating point values. That's a bit more complex that what you'd expect from an ancient application, and really improves the accuracy of its calculations.

51

u/[deleted] Mar 07 '19

It’s actually exactly what i’d expect. It’s a calculator app, that’s about the only thing it has to get right

44

u/Creshal Mar 07 '19

That's exactly what I'd expect from an ancient application that dates back to the days where floating-point calculations were something you had to buy a coprocessor for.

That the first versions didn't and used floating point anyway is even more interesting.

0

u/[deleted] Mar 07 '19

[deleted]

4

u/Creshal Mar 08 '19

If it's slow anyway, you might as well go with the more accurate method.

64

u/Beaverman Mar 07 '19

I mean, that's what i would expect from a calculator application. If someone gave me a calculator with floating point precision, i'd be pretty disappointed.

5

u/[deleted] Mar 08 '19

That's a bit more complex that what you'd expect from an ancient application, and really improves the accuracy of its calculations.

No, it isn't. If anything that's exactly how it should be done, and that's how it's always been done.

What you're describing is dead trivial.

-3

u/SuperSuperUniqueName Mar 08 '19 edited Mar 08 '19

I might be wrong, but numbers are stored as floating point nowadays

edit: This StackOverflow thread has pretty comprehensive coverage of both sides. It seems that most advocates for non-floating point money cite minor deviations in floating-point calculations (remedied by rounding); significant deviations tend to emerge when dealing with larger sums. So I can see why you would choose either side.

13

u/meltingdiamond Mar 08 '19

I hope you don't store money in a float, that is the cause of many well known problems for decades.

4

u/CornedBee Mar 08 '19

I might be wrong, but numbers are stored as floating point nowadays

If your world is JavaScript, sure.

0

u/[deleted] Mar 08 '19

[deleted]

2

u/Genion1 Mar 08 '19

They are still floating points. You just have more ways to specify them. You just have some integer operations. The result will still be stored in double precision floating point format. That's why the integer range in js is 52 bit, though bitwise integer operations work with 32-bit numbers and truncate your number into that range before roundtripping back to floats.

7

u/[deleted] Mar 08 '19

Again, especially for money: never should floating point be used. For many reasons, outside of just IEEE's semantics.

If you're relying on SO to support your argument then you aren't arguing anything. You're just parrotting information.

0

u/SuperSuperUniqueName Mar 09 '19

I'm not really trying to argue, just found something and linked it. I take no stance on the issue. I'm sorry if you felt attacked.

1

u/[deleted] Mar 09 '19

I'm not really trying to argue, just found something and linked it. I take no stance on the issue. I'm sorry if you felt attacked.

The fact that you linked something which tries to contradict it is basically a form of contesting it, irrespective of your actual intent.

That said, I don't care if you try to argue lol. It just means more fun for me.

1

u/SuperSuperUniqueName Mar 09 '19

Honestly, it feels like you're looking to argue. I made an innocuous comment that only drew aggression.

If you feel like arguing, I suggest you take it out on someone else.

1

u/[deleted] Mar 10 '19 edited Mar 10 '19

Honestly, it feels like you're looking to argue

I'm not looking to argue. But I'm also not going to refrain from calling out bullshit when I see it. It's perfectly reasonable to have this opinion. Actually, it's moral.

I made an innocuous comment that only drew aggression.

You made a comment which voiced an opinion that's wrong. I'm not holding it against you as a person, but what you posted is wrong. Simple as that.

Really, though, it sounds like you're getting defensive and trying to play some kind of victim card here, despite the fact that you were the one who took initiative to post something incorrect.

Using statements like "it seems" aim to question the original sentiment. That's fine if you choose to make those. Hell, it's fine if you even attempt to contradict it further. But to deny the fact that you are trying to argue is ridiculous. You put out the information. You didn't just ask a question, you went for information and you took the time to post something as a challenge. If you were actually "not really trying to argue", you wouldn't have done that. Plain and simple.

If you feel like arguing, I suggest you take it out on someone else.

I see. So, you're insinuating that I'm attempting to vent some kind of unrelated frustration here. Are you going to deny that too?

Like, honestly, what you're doing is not honing up to your actions. You must be like 19 or something.

1

u/SuperSuperUniqueName Mar 10 '19

It's possible to provide contradicting facts without argument. Sure, I agree that my opinion is wrong. But you are reinforcing my claim that you are trying to argue by actively refuting my comment. No new facts have been introduced for several comments now and nothing productive has come of it, so I suggest that you save us both some time and don't reply.

→ More replies (0)

1

u/[deleted] Mar 08 '19

umm, no. For very specific applications only.

42

u/[deleted] Mar 07 '19

ITT people are hard to please

4

u/jesus_is_imba Mar 08 '19

More like the guy who wrote TFA is easy to please.

4

u/cowmonaut Mar 08 '19

Sorry to be the one to inform you, but that *is* calc.exe. Its always been used as a means of testing/demoing new features/ideas and like in every iteration of Windows before it it was changed with Windows 10. Check out the source code, its still got its skeletons from '95 at its core.

3

u/rap2h Mar 08 '19

This project collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. Telemetry is disabled in development builds by default, and can be enabled with the SEND_TELEMETRY build flag.

Source: https://github.com/Microsoft/calculator#data--telemetry

-3

u/Creshal Mar 07 '19

This project collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. Telemetry is disabled in development builds by default, and can be enabled with the SEND_TELEMETRY build flag.

Telemetry inside a fucking calculator. And then they have the audacity to lie in your face and say "Your privacy is important to us".

7

u/OffbeatDrizzle Mar 07 '19

The day I stopped using windows was the day the fucking calculator asked me to rate it on the app store

-8

u/Free_Math_Tutoring Mar 07 '19

Well, it's important to them in the same way that locks are important to burglars. /s

0

u/[deleted] Mar 07 '19

[deleted]

11

u/TheCodexx Mar 08 '19 edited Feb 05 '26

5

u/Hacnar Mar 08 '19

People don't want stuff sending back information

You say that, but all they complain about is MS software doing it. I don't remeber seeing complaints about non-MS software using telemetry, despite most of the software from this decade using it. That makes me think that it's just a masked MS hate. People don't really care about telemetry, they just like to flame MS.

5

u/JnvSor Mar 08 '19

I don't remeber seeing complaints about non-MS software using telemetry

Ubuntu's Unity, Valve's Steam, surely you've heard one or two people complaining about tracking on the internet?...

3

u/[deleted] Mar 08 '19

Never really heard anyone bitching about Steam tracking. DRM tho...

0

u/JnvSor Mar 08 '19

VAC pokes through your browser history looking for websites with known hacks IIRC

1

u/Hacnar Mar 08 '19

Nope, haven't heard or seen a single complaint about either of them. This is actually a nice example of the amount of complaining about MS products vs other software.

0

u/[deleted] Mar 08 '19

[deleted]

1

u/Hacnar Mar 08 '19

I don't browse many specific subreddits, so it's likely that i missed such discussions.

I bet that many communitites discuss similar issues when they arise, but it rarely leaves those communities, whereas with MS, people bring it up every time MS is mentioned anywhere, even if it's completely offtopic.

1

u/TheCodexx Mar 08 '19

They complain when Microsoft doesn't because most other software has the common courtesy to ask "Do you mind if we send some data back?", and they give you a box to check. Microsoft makes you jump through hoops to not even turn all of it off.

It doesn't help that Microsoft can push basically anything onto the average user and not face any consequences. Apple, too. And Google. And all of them are tracking lots of things, if you let them. But Microsoft is the only one with a major desktop operating system, and Apple probably has put minimal effort into OSX telemetry, which just leaves... Linux, where most software is open source and the community in general views user rights as a priority over all else.

Microsoft is taking the blame because they're the biggest target and their implementation for telemetry is totally broken. Sending back crash reports is one thing, but passively gathering usage data without asking or allowing me to disable it is too much.

-21

u/[deleted] Mar 07 '19

It's a calculator.

A fucking calculator.

12

u/circlebust Mar 08 '19

You'll still want some basic usage statistics, like whether people are actually using function X, selecting option Y, or even know that panel Z exists.

0

u/[deleted] Mar 07 '19

[deleted]

-21

u/[deleted] Mar 07 '19

It needs blockchain and should be in the cloud, duh.

-50

u/Creshal Mar 07 '19

If you work on a large project at pretty much any software dev firm, you will be gathering usage statistics to figure out how people are using your application and where it needs improving.

And violate their privacy in the process, because all of these tools are atrocious and leak data everywhere. Yes.

Besides, it's a fucking calculator.

9

u/tenfingerperson Mar 07 '19

Some people are so fucking stupid it almost hurts

0

u/anonveggy Mar 09 '19

You don't want calculator to be able to send Microsoft error messages when being used in weird localization settings where a user might be able to enter letters masked as numbers?

Then don't you ever get to complain about any software with bad translation / globalization ever again.

1

u/Creshal Mar 09 '19

No, I want this to be covered by automated testing. Microsoft has all the localization files already anyway.

Then don't you ever get to complain about any software with bad translation / globalization ever again.

Bullshit. Telemetry is just the lazy way out for devs too incompetent to properly test their shit.

1

u/anonveggy Mar 09 '19

Automated testing doesn't magically report edge cases you didn't know about. You cannot automatically test every scenario there is. Stuff changes and with it comes bugs.

0

u/[deleted] Mar 07 '19

[deleted]

53

u/chucker23n Mar 08 '19

“0.5% of our users use the unit conversion features. Maybe we need to make them more prominent, or they’re just not worth much investment for now.”

“Ever since we redesigned the binary UI, it’s usage went up. Looks like we’re on the right track there!”

“Looks like 35% haven’t just tried the dark mode but also stuck to it. Worth it!”

“Average startup duration is above 3s now. That’s really slow, folks, and I worry it discourages usage and makes us look bad. Can we lazy-load some features?”

Simple. No PII required at all, and a way to help make an informed decision about your roadmap.

0

u/[deleted] Mar 08 '19

[deleted]

1

u/6501 Mar 09 '19

If Microsoft were to do that I'm pretty sure the significantly easier way would be to just update the OS to report the file structure of the entire OS, file formats used, names of files, system time, default DNS server, organization or domain the computer is a part of etc. Also since the GDPR exists companies don't want to take extra data they don't need as the GDPR puts a lot of restrictions on data & how you collect & use the data.

24

u/csjerk Mar 07 '19

Besides multiple numeric modes (standard, scientific, programmer, and date differences) it has converters for 13 different classes of units (temperature, area, speed, etc.), including a currency converter that retrieves live exchange rates from the network.

There's plenty of features there to make it worth instrumenting.

1

u/[deleted] Mar 10 '19

"This guy calculated 9*7 twice in the last 15 minutes. Better show him some Zune ads."

-1

u/mmstick Mar 08 '19

It collects all inputs given to the calculator to calculate, whether it's an invalid query or not. You could type your password into it, and your password would been sent to Microsoft.

7

u/examinedliving Mar 08 '19

Maybe... but what’s it a password to? How do they know? Do they store it? I hate data collection on principle, but I think you’re safe here

8

u/delrindude Mar 08 '19

Hating data collection on principle

How do you improve software then? You need some kind of data collection.

4

u/examinedliving Mar 08 '19

I don’t know if my principle is right. I’m a sodtware developer after all. It’s just of those feelings that’s stuck around for whatever reason

-2

u/mmstick Mar 08 '19

Improving software doesn't require data collection. Certainly not involuntary data collection.

How do you improve software? Actually use and test your own software, receive and respond to bug reports created by your users, and use the best software practices. Test-driven development is a thing, as are automated fuzzers, or simple code reviews.

3

u/delrindude Mar 08 '19

If all you depend on is bug reports then you are already behind for feature development. (Hint: bug reports are data collection as well)

-2

u/mmstick Mar 08 '19 edited Mar 08 '19

Individual data points may not look scary, but that quickly escalates once you start combining those individual data points together, which is trivial to do for a company like Microsoft, which already receives massive amounts of data points from each of it's users.

If they are collecting all inputs from a calculator, imagine what else they're tracking in the rest of their OS and surrounding applications. You're submitting enough data that all of those unrelated data points can easily be associated with each other. Then they're no longer unrelated data points.

If you log into a Microsoft account from the same connection that sent that single data point from the calculator, you now have two data points which can be associated as belonging to the same person. Who is to say it stops there?

Search results in the start menu, queries in the browser, the Cortana assistant that sends microphone data to the cloud, and she knows what sort of data mining possibilities are there as the system builds indexes from all the personal files and documents on your system.

7

u/SuperSuperUniqueName Mar 08 '19

This response makes no sense. Finding meaningful patterns in random datapoints (especially simple numbers) based on an extraordinarily vague constraint of "passwords" is not trivial. Even if you were able to sort out 100% of all datapoints that are passwords, Microsoft would be unable to do anything with them because:

  1. They don't know what service it's for, what your username is, security questions, etc.

  2. Microsoft probably doesn't engage in petty criminal activity.

1

u/mmstick Mar 08 '19 edited Mar 08 '19

Any system which makes a connection to a server can easily be tracked. It's not that big of jump to know what MAC addresses, email accounts, user names, search entries, etc. are originating at which IP addresses at a given time.

If you want to turn unrelated data into related data, merely start collecting and associating all data points whose sources originated from the same locations during those times. Easily done when you are in a position to receive a lot of data points.

Microsoft is in that kind of position, as are Apple and Google. Considering Microsoft was caught and publicly admits to incorporating back doors into their platform for the US government, bending over for them to allow them to collect any data they want, and the types of hacking tools that the NSA had, this really shouldn't be that surprising.

The more unrelated data that's collected, the more accurate the predictions can be made on that data. With enough data collected, they can actually make reasonable estimates about what data is yours and what isn't, as your data patterns are as unique as fingerprints.

This is rife for abuse, and you're the product of the system, should you choose to be a part of it.

1

u/SuperSuperUniqueName Mar 08 '19

That's under the assumption that Microsoft is able to comb out the aformentioned passwords from calculator data. The vast majority of passwords cannot be represented in simply numeric form.

Perhaps something sinister is going on above us, but I hardly think it's relevant to calculator usage tracking.

1

u/mmstick Mar 08 '19 edited Mar 08 '19

Calculator can accept non-numeric inputs, and invalid inputs are still sent through the telemetry to Microsoft.

That said, passwords being in the calculator input was just an example. Do you think it would be useful to know what numbers that CEOs and their accountants are typing into a calculator?

There's a lot that can be learned from a series of inputs. A bit of search queries here, a little calculating there, a few emails here, and some spreadsheets there. Collecting a timeline of data inputs is simple. You have the data, know when that data was received, and from which address it originated from. You only need to mine that data.

There are numerous applications on Windows with telemetry that sends text inputs, even audio recordings, to their services. The point is that if they've gone through the effort of doing this in something as trivial as a calculator, then there's a precedence that they're doing this in every one of their products.

1

u/SuperSuperUniqueName Mar 08 '19

Thing is, it would take Microsoft manual, one-on-one efforts to reliably identify personal information, especially with increased security measures today. It's reasonable to assume that it's unlikely Microsoft is tracking individual people's passwords, etc., simply because your regular Joe is of no interest to them. Maybe high-profile targets , but they know about this too.

1

u/zerexim Mar 08 '19

What about calc.exe from Win7?

0

u/owen800q Mar 08 '19

Any volunteers have a plan to migrate this calculator to Linux platforms? Rewrite the part of GUI with QT or gtk? The programmer mode is really useful loll

15

u/tracernz Mar 08 '19

The programming mode in gnome-calculator is already superior...

5

u/owen800q Mar 08 '19

BUT the key thing that I want right now is that there's a selector for what width you want to work at (8/16/32/64 bits) and it will do everything in that width.

3

u/tracernz Mar 08 '19

Ah, you're right, that is missing! That would be a worthy addition.

The MS one doesn't support 8-bit sadly, and it's no longer a single click to select word size in the Win 10 calc.

5

u/tracernz Mar 08 '19

Turns out gnome-calculator does support word size, but it's hidden in the preferences dialog! Options are 8/16/32/64.

0

u/[deleted] Mar 07 '19

[deleted]

3

u/DestroyedByLSD25 Mar 08 '19

1989? That is ancient

0

u/[deleted] Mar 09 '19

[deleted]

3

u/favorited Mar 09 '19

It's C++/CX, a Microsoft-specific language extension for C++ which integrates with the Windows Runtime. The ^ is called "hat" and it represents a smart pointer which uses the runtime to do automatic memory management.

It will (in theory) eventually be replaced by C++/WinRT, which lets you get the Windows Runtime integration using standard ISO C++.

0

u/[deleted] Mar 09 '19

[deleted]

1

u/favorited Mar 09 '19

You're welcome. When I built a Windows PC last year I decided to learn Windows development (hadn't even played with it in over a decade) and was very surprised that there was no real support for using plain-old-c++ in Windows app development... Luckily that's changing.