News for hackers. Stuff that matters.
Re:Why Is Python So Popular in 2025? – The PyCharm Blog by worik on Wednesday October 01, 2025 @02:37PM (#45441465)
>>> 0.2 + 0.1 > 0.3

    True
That is false. What is it that is "...is much harder to demonstrate in other languages?

I am missing something

Re:Why Is Python So Popular in 2025? – The PyCharm Blog by librasteve on Wednesday October 01, 2025 @04:00PM (#45442641)
lol, here it is in the https://raku.org repl…

  Welcome to Rakudo™ v2025.06.1.
  Implementing the Raku® Programming Language v6.d.
  Built on MoarVM version 2025.06.
  
  To exit type 'exit' or '^D'
  [0] > 0.1 + 0.2 > 0.3
  False
Re:Why Is Python So Popular in 2025? – The PyCharm Blog by Jtsummers on Wednesday October 01, 2025 @02:44PM (#45441569)
> That is false.

What's false about it? That is the result if you're using IEEE floating point arithmetic.

Re:Why Is Python So Popular in 2025? – The PyCharm Blog by tialaramex on Wednesday October 01, 2025 @03:05PM (#45441864)
It's the result if your programming language thinks 0.2 + 0.1 means you want specifically the 64-bit IEEE floating point binary arithmetic.

But, where did we say that's what we want? As we've seen it's not the default in many languages and it isn't mandatory in Python, it's a choice, and the usual argument for that choice would be "it's fast" except, Python is slow, so what gives ?

Re:Why Is Python So Popular in 2025? – The PyCharm Blog by Jtsummers on Wednesday October 01, 2025 @03:19PM (#45442044)
You aren't answering my question. I asked worik why they're claiming that something that happens is false. It's insane to claim that reality isn't reality. Run that in a Python REPL and that is the result you get.
Re:Why Is Python So Popular in 2025? – The PyCharm Blog by leephillips on Wednesday October 01, 2025 @03:21PM (#45442078)
Interesting observation about Python providing the worst of all possible worlds: unintuitive arithmetic without any of its speed advantages.

But in answer to “where did we say that's what we want?” I would say, as soon as we wrote the expression, because we read a book about how the language works before we tried to use it. Αfter, for example reading a book¹ about Julia, we know that 0.1 + 0.2 will give us something slightly larger than 0.3, and we also know that we can type 1//10 + 2//10 to get 3//10.

[1] https://lee-phillips.org/amazonJuliaBookRanks/

Re:Why Is Python So Popular in 2025? – The PyCharm Blog by tialaramex on Wednesday October 01, 2025 @04:22PM (#45442960)
> I would say, as soon as we wrote the expression, because we read a book about how the language works

I'm comfortable with that rationale in proportion to how much I believe the programmer read such a book.

I haven't taken the course we teach say, Chemists, I should maybe go audit that, but I would not be surprised if either it never explains this, or the explanation is very hand-wavy, something about it not being exact, maybe invoking old fashioned digital calculators.

The amusing thing is when you try to explain this sort of thing with a calculator, and you try a modern calculator, it is much more effective at this than you expected or remember from a 1980s Casio. The calculator in your modern say, Android phone, knows all the stuff you were shown in school, it isn't doing IEEE floating point arithmetic because that's only faster and you're a human using a calculator so "faster" in computer terms isn't important and it has prioritized being correct instead so that pedants stop filing bugs.

Re:Why Is Python So Popular in 2025? – The PyCharm Blog by zahlman on Thursday October 02, 2025 @04:43PM (#45455308)
> unintuitive arithmetic without any of its speed advantages.

Using floating-point in Python is still much faster than using an exact type in Python.

  $ # At this scale, we need to be aware of and account for the timing overhead
  $ python -m timeit 'pass'
  50000000 loops, best of 5: 8.18 nsec per loop

  $ # The variable assignment defeats constant folding in the very primitive optimizer
  $ python -m timeit --setup 'x = 0.1; y = 0.2' 'x + y'
  10000000 loops, best of 5: 21.2 nsec per loop

  $ python -m timeit --setup 'from decimal import Decimal as d; x = d("0.1"); y = d("0.2")' 'x + y'
  5000000 loops, best of 5: 62.9 nsec per loop

  $ python -m timeit --setup 'from fractions import Fraction as f; x = f(1, 10); y = f(2, 10)' 'x + y'
  500000 loops, best of 5: 755 nsec per loop
Re:Why Is Python So Popular in 2025? – The PyCharm Blog by worik on Wednesday October 01, 2025 @10:32PM (#45445830)
> What's false about it?

Mathematics. IEEE floating point arithmetic gets it wrong!

Another example of why we should use integer algorithms where ever possible.