News for hackers. Stuff that matters.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by wheybags on Tuesday January 31, 2023 @04:28AM (#34593117)
Part of me wonders if binary floating point was a mistake. If we had invested the same effort into hardware optimising some kind of BCD based floating point format, where would we be now? The amount of confusion caused for new programmers by the way floats can't represent "simple" values like 0.1 perfectly is immense. Would also make round tripping through text formats like json "just work", as opposed to the mess we have now.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by TazeTSchnitzel on Tuesday January 31, 2023 @05:25AM (#34593465)
The confusion around 0.1 might be a good thing, it makes you learn early on that floats approximate a number to its significant digits and are not real numbers.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by wheybags on Tuesday January 31, 2023 @06:47AM (#34593940)
People are used to approximations, but they are used to decimal approximations. "I can't represent 1/3 as a decimal" is expected, "I can't represent 1/10 as a decimal" is surprising.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by DerekL on Tuesday January 31, 2023 @04:59PM (#34602867)
Making computers use more memory, use larger chips, and consume more power just to make one thing easier for novice programmers is a bad trade-off. Decimal floating-point types could be implemented in software for those who really want it.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by bcrl on Wednesday February 01, 2023 @08:26PM (#34620792)
By that reasoning we shouldn't be using higher level languages like Python and Java that use more memory, and consume more power for the same workload as code written in assembly. 6502 assembly FTW!
Re:Understanding the x86's Decimal Adjust after Addition (DA... by CamperBob2 on Tuesday January 31, 2023 @11:15AM (#34597069)
Well, they are real numbers, just not always the ones you want.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by jonstewart on Tuesday January 31, 2023 @05:25AM (#34593469)
But we also have, e.g., fairly accurate weather models now, enabled by supercomputers running lots of floating point math.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by jimktrains2 on Tuesday January 31, 2023 @11:06AM (#34596910)
Wouldn't we have the same if history tilted the way the grandparent post is asking about?
Re:Understanding the x86's Decimal Adjust after Addition (DA... by flohofwoe on Tuesday January 31, 2023 @06:23AM (#34593802)
If only humans had 8 or 16 fingers instead of 10 ;)
Re:Understanding the x86's Decimal Adjust after Addition (DA... by ElectricalUnion on Tuesday January 31, 2023 @08:41AM (#34594869)
This reminds me of this: https://news.ycombinator.com/item?id=12720638

> Fun fact: you can count to hexadecimal on the fingers of one hand.

> The way it works is that each of your four fingers has four well-defined places on them: the three joints, plus the tip. You use your thumb to point at one of these. The first finger represents 1-4, the second 5-8, the third 9-12, the fourth 13-16. You count up and down by moving your thumb.

(...)

> As a special bonus: if you point to the fleshy pads of the fingers instead of the joints, you can use the same system for base 12.

Re:Understanding the x86's Decimal Adjust after Addition (DA... by dgacmu on Tuesday January 31, 2023 @09:10AM (#34595177)
Tough call deciding between this and just using your fingers as a 5 bit binary counter. Incrementing is sure a lot faster with this method at the cost of a bit.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by tengwar2 on Thursday February 02, 2023 @08:19AM (#34626118)
The difficulty with that is that your ring finger is not completely independent of your pinkie due to the way the tendons are connected.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by otabdeveloper4 on Tuesday January 31, 2023 @07:01AM (#34594027)
Floats represent real numbers, not "values". (Whatever those are.)

Please teach new programmers the number type stack first.

Re:Understanding the x86's Decimal Adjust after Addition (DA... by msm_ on Tuesday January 31, 2023 @07:52AM (#34594449)
How do they represent real numbers? If anything, they represent rational numbers.

Also I think your answer is unnecessarily nitpicky. Sentence 'floats can't represent "simple" values like 0.1 (...)' is perfectly clear to everyone on HN, I hope. In fact, I disagree that changing "values" here to a more precise mathematical term would improve anything.

Re:Understanding the x86's Decimal Adjust after Addition (DA... by astrange on Tuesday January 31, 2023 @08:00AM (#34594510)
> How do they represent real numbers? If anything, they represent rational numbers.

That's an interesting philosophical question. Does M_PI represent a rational number?

(M_PI isn't mentioned in my copy of the C spec, unless I just can't find it.)

Re:Understanding the x86's Decimal Adjust after Addition (DA... by wadd1e on Tuesday January 31, 2023 @08:06AM (#34594561)
does it not have to represent a rational approximation of Pi? Real numbers in the set theoretic sense are defined as limits of Cauchy sequences[0], and since we can't quite store an infinite sequence, it has to be a finite approximation due to the limitations of the real world.

[0]: https://en.wikipedia.org/wiki/Cauchy_sequence

Re:Understanding the x86's Decimal Adjust after Addition (DA... by astrange on Tuesday January 31, 2023 @10:05AM (#34595906)
It does after it's assigned to a variable, but maybe it doesn't before that.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by CamperBob2 on Tuesday January 31, 2023 @11:20AM (#34597143)
Rationals are a subset of the reals.
Re:Understanding the x86's Decimal Adjust after Addition (DA... by otabdeveloper4 on Wednesday February 01, 2023 @01:36AM (#34607225)
No current computing architecture provides primitives for dealing for rational numbers. (Which is why you need to roll your own implementation in software, so nobody bothers.)

But we have great native support for approximating real numbers instead. (Because computing is designed first and foremost to make numerical methods efficient.)

Re:Understanding the x86's Decimal Adjust after Addition (DA... by otabdeveloper4 on Wednesday February 01, 2023 @01:31AM (#34607204)
Floats are designed to be computationally and mathematically efficient approximations of the real numbers.

The exist so that trigonometry and logarithms work properly in numerical methods. (A vastly more important problem than getting '0.1' to print pretty on the screen.)

There is no such thing as a 'value' in mathematics, and fixating on 0.1 in particular is pointless.

tldr - everyone should learn the math behind this first.

Re:Understanding the x86's Decimal Adjust after Addition (DA... by ajross on Tuesday January 31, 2023 @10:50AM (#34596637)
Responses to this are IMHO unfair. In fact this isn't an inherently terrible or infeasible idea. Transistor costs for 4-bit BCD run just about at the ln(16)/ln(10) level you'd expect, and just a few gates of depth per digit are needed for the carry detect (something that can easily be folded into the carry lookahead optimizations all modern adders need anyway). Hardware multipliers would need more work, you can't make a Dadda/Wallace tree with anything but binary adders, but I'm sure there's a clever generalization.

The one thing you'd lose would be two's complement trickery. Addition and subtraction in BCD actually are fundamentally different algorithms, so that's something to worry about. But then signedness mismatches are themselves a historical footgun, so you could spin this away too, I think.

But... beyond that this could absolutely be done. And it's also true that a lot of traditional bugs with FPU/brain precision mismatch would be fixed in the process.

I don't know that it's an architecture I'd pick, but it's not something to reject out of hand either. It's worth discussing and not downvoting.