Generally, calculators use BCD, so they work in base 10.
BCD is a pretty wasteful data representation, so computers usually work in binary.
Calculators also go to great lengths to hide those kinds of displays by using extra "hidden" digits and stuff. Computers are supposed to be programmed by people who know what they are doing.
Your calculator is also rounding digits for display purposes. It rounded 3.9999999 to 4.0000000 and then realized that it was silly to display all those zeros, so it showed 4. The Arduino did the same calculation, and got the same answer. You asked it to display the output the way you wanted to see it, not the way it wanted to show it to you.
Calculators do "school" maths eg 3/2 = 1+1/2. However computer to integer and real math (look up number theory). The too are very different!.
For example 1/0 or even 1.0/0.0 does not equal infinity, in integer or real math, it is just undefined ie (anything/0 is undefined or just not allowed. Forget what your teacher, said look it up!. Google "number theory".
Calculators are carefully designed to do their calculations with more digits of precision than the display will actually display, and then they round properly.
Computer languages in general, and the Arduino libraries in particular, ... not so much. But it calculates an ALMOST correct answer much faster than most calculators!
My advanced calculator comes up with an answer of "4", which is not 'exactly' correct. How about yours?
Calculators ARE 'computers' ... with very specific capabilities and programming. Whoever does the programming uses the resources available to determine what is shown on the display.
Blessings in abundance, all the best, & ENJOY!
Art in Carlisle, PA USA
Delta_G:
what does my calculator have that my Arduino or even my computer doesn't?
The answer is that it has different technology for a different purpose. Its job is to tell you the bleeding obvious, 8/4=2, and look like it knows what it's doing. This it does, but at the sacrifice of speed. Computers are all about speed and efficiency and I guess it is more efficient to do the deed , and, only if needed, apply the cosmetics after the event.
Back in the days of the s100 bus, I recall there was a dedicated scientific calculator chip that enabled a computer to deliver what you want to see. I imagine its validity today is the same as it was then.
Or rebooting?
Or reinstalling the operating system?
Or contacting your system administrator?
Or any of the other dumb shit that Microsoft recommends before they admit that it is their code that sucks.