News for hackers. Stuff that matters.
Re:C++ proposal: There are 8 bits in a byte by jsheard on Thursday October 17, 2024 @08:25PM (#41875200)
Maybe specifying that floats are always IEEE floats should be next? Though that would obsolete this Linux kernel classic so maybe not.

https://github.com/torvalds/linux/blob/master/include/math-e...

Re:C++ proposal: There are 8 bits in a byte by jfbastien on Thursday October 17, 2024 @10:26PM (#41875859)
Hi! I'm JF. I half-jokingly threatened to do IEEE float in 2018 https://youtu.be/JhUxIVf1qok?si=QxZN_fIU2Th8vhxv&t=3250

I wouldn't want to lose the Linux humor tho!

Re:C++ proposal: There are 8 bits in a byte by conradev on Thursday October 17, 2024 @11:46PM (#41876173)
I was curious about float16, and TIL that the 2008 revision of the standard includes it as an interchange format:

https://en.wikipedia.org/wiki/IEEE_754-2008_revision

Re:C++ proposal: There are 8 bits in a byte by tialaramex on Friday October 18, 2024 @05:27AM (#41877684)
Note that this type (which Rust will/ does in nightly call "f16" and a C-like language would probably name "half") is not the only popular 16-bit floating point type, as some people want to have https://en.wikipedia.org/wiki/Bfloat16_floating-point_format
Re:C++ proposal: There are 8 bits in a byte by adrian_b on Saturday October 19, 2024 @03:23AM (#41886241)
The IEEE FP16 format is what is useful in graphics applications, e.g. for storing color values.

The Google BF16 format is useful strictly only for machine learning/AI applications, because its low precision is insufficient for anything else. BF16 has very low precision, but an exponent range equal to FP32, which makes overflows and underflows less likely.

Re:C++ proposal: There are 8 bits in a byte by AnimalMuppet on Thursday October 17, 2024 @08:50PM (#41875351)
That line is actually from a famous Dilbert cartoon.

I found this snapshot of it, though it's not on the real Dilbert site: https://www.reddit.com/r/linux/comments/73in9/computer_holy_...

Re:C++ proposal: There are 8 bits in a byte by Jerrrrrrry on Thursday October 17, 2024 @09:53PM (#41875688)
This is the epitome, the climax, the crux, the ultimate, the holy grail, the crème de la crème of nerd sniping.

fuckin bravo

Re:C++ proposal: There are 8 bits in a byte by NL807 on Thursday October 17, 2024 @08:27PM (#41875213)
Love it
Re:C++ proposal: There are 8 bits in a byte by FooBarBizBazz on Thursday October 17, 2024 @10:03PM (#41875749)
Whether double floats can silently have 80 bit accumulators is a controversial thing. Numerical analysis people like it. Computer science types seem not to because it's unpredictable. I lean towards, "we should have it, but it should be explicit", but this is not the most considered opinion. I think there's a legitimate reason why Intel included it in x87, and why DSPs include it.
Re:C++ proposal: There are 8 bits in a byte by stephencanon on Thursday October 17, 2024 @11:04PM (#41876023)
Numerical analysis people do not like it. Having _explicitly controlled_ wider accumulation available is great. Having compilers deciding to do it for you or not in unpredictable ways is anathema.
Re:C++ proposal: There are 8 bits in a byte by bee_rider on Thursday October 17, 2024 @11:30PM (#41876108)
It isn’t harmful, right? Just like getting a little accuracy from a fused multiply add. It just isn’t useful if you can’t depend on it.
Re:C++ proposal: There are 8 bits in a byte by Negitivefrags on Friday October 18, 2024 @12:10AM (#41876269)
It can be harmful. In GCC while compiling a 32 bit executable, making an std::map< float, T > can cause infinite loops or crashes in your program.

This is because when you insert a value into the map, it has 80 bit precision, and that number of bits is used when comparing the value you are inserting during the traversal of the tree.

After the float is stored in the tree, it's clamped to 32 bits.

This can cause the element to be inserted into into the wrong order in the tree, and this breaks the assumptions of the algorithm leaidng to the crash or infinite loop.

Compiling for 64 bits or explicitly disabling x87 float math makes this problem go away.

I have actually had this bug in production and it was very hard to track down.

Re:C++ proposal: There are 8 bits in a byte by blt on Friday October 18, 2024 @12:20AM (#41876310)
dang that's a good war story.
Re:C++ proposal: There are 8 bits in a byte by ndesaulniers on Friday October 18, 2024 @12:37AM (#41876377)
Are you mixing up long double with float?
Re:C++ proposal: There are 8 bits in a byte by josefx on Friday October 18, 2024 @03:44AM (#41877176)
Old Intel CPUs only had long double, 32 bit and 64 bit floats were a compiler hack on top of the 80 bit floating point stack.
Re:C++ proposal: There are 8 bits in a byte by jfbastien on Friday October 18, 2024 @12:43AM (#41876406)
10 years ago, a coworker had a really hard time root-causing a bug. I shoulder-debugged it by noticing the bit patterns: it was a miscompile of LLVM itself by GCC, where GCC was using an x87 fldl/fstpl move for a union { double; int64; }. The active member was actually the int64, and GCC chose FP moved based on what was the first member of the union... but the int64 happened to be the representation of SNaN, so the instructions transformed it quietly to a qNaN as part of moving. The "fix" was to change the order of the union's members in LLVM. The bug is still open, though it's had recent activity: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58416
Re:C++ proposal: There are 8 bits in a byte by ptsneves on Friday October 18, 2024 @03:09AM (#41877021)
It also affected eMacs compilation and the fix is in the trunk now.

Wow 11 years for such a banal minimal code trigger. I really don’t quiet understand how we can have the scale of infrastructure in operation when this kind of infrastructure software bugs exist. This is not just gcc. All the working castle of cards is an achievement by itself and also a reminder that good enough is all that is needed.

I also highly doubt you could get a 1 in 1000 developers to successfully debug this issue were it happening in the wild, and much smaller to actually fix it.

Re:C++ proposal: There are 8 bits in a byte by Negitivefrags on Friday October 18, 2024 @06:17AM (#41877928)
If you think that’s bad let me tell you about the time we ran into a bug in memmove.

It had to be an unaligned memmove and using a 32 bit binary on a 64 bit system, but still! memmove!

And this bug existed for years.

This caused our database replicas to crash every week or so for a long time.

Re:C++ proposal: There are 8 bits in a byte by kmeisthax on Friday October 18, 2024 @01:30AM (#41876590)
What use case do you have that requires indexing a hashmap by a floating point value? Keep in mind, even with a compliant implementation that isn't widening your types behind your back, you still have to deal with NaN.

In fact, Rust has the Eq trait specifically to keep f32/f64s out of hash tables, because NaN breaks them really bad.

Re:C++ proposal: There are 8 bits in a byte by josefx on Friday October 18, 2024 @03:30AM (#41877111)
> you still have to deal with NaN.

Detecting and filtering out NaNs is both trivial and reliable as long as nobody instructs the compiler to break basic floating point operations (so no ffast-math). Dealing with a compiler that randomly changes the values of your variables is much harder.

Re:C++ proposal: There are 8 bits in a byte by meindnoch on Friday October 18, 2024 @03:24AM (#41877086)
std::map is not a hash map. It's a tree map. It supports range queries, upper and lower bound queries. Quite useful for geometric algorithms.
Re:C++ proposal: There are 8 bits in a byte by tialaramex on Friday October 18, 2024 @05:56AM (#41877815)
Rust's BTreeMap, which is much closer to what std::map is, also requires Ord (ie types which claim to possess total order) for any key you can put in the map.

However, Ord is an ordinary safe trait. So while we're claiming to be totally ordered, we're allowed to be lying, the resulting type is crap but it's not unsafe. So as with sorting the algorithms inside these container types, unlike in C or C++ actually must not blow up horribly when we were lying (or as is common in real software, simply clumsy and mistaken)

The infinite loop would be legal (but I haven't seen it) because that's not unsafe, but if we end up with Undefined Behaviour that's a fault in the container type.

This is another place where in theory C++ gives itself license to deliver better performance at the cost of reduced safety but the reality in existing software is that you get no safety but also worse performance. The popular C++ compilers are drifting towards tacit acceptance that Rust made the right choice here and so as a QoI decision they should ship the Rust-style algorithms.

Re:C++ proposal: There are 8 bits in a byte by oxnrtr on Friday October 18, 2024 @04:34PM (#41883237)
That's purely a problem of Rust being wrong.

Floats have a total order, Rust people just decided to not use it.

Re:C++ proposal: There are 8 bits in a byte by lf37300 on Friday October 18, 2024 @12:10AM (#41876272)
If not done properly, double rounding (round to extended precision then rounding to working precision) can actually introduce larger approximation error than round to nearest working precision directly. So it can actually make some numerical algorithms perform worse.
Re:C++ proposal: There are 8 bits in a byte by eternityforest on Thursday October 17, 2024 @11:57PM (#41876218)
I suppose it could be harmful if you write code that depends on it without realizing it, and then something changes so it stops doing that.
Re:C++ proposal: There are 8 bits in a byte by stephencanon on Friday October 18, 2024 @06:33AM (#41878039)
It’s absolutely harmful. It turns computations that would be guaranteed to be exact (e.g. head-tail arithmetic primitives used in computational geometry) into “maybe it’s exact and maybe it’s not, it’s at the compiler’s whim” and suddenly your tests for triangle orientation do not work correctly and your mesh-generation produces inadmissible meshes, so your PDE solver fails.
Re:C++ proposal: There are 8 bits in a byte by FooBarBizBazz on Friday October 18, 2024 @10:33AM (#41879828)
Thank you, I found this hint very interesting. Is there a source you wouldn't mind pointing me to for those "head, tail" methods?

I am assuming it relates to the kinds of "variable precision floating point with bounds" methods used in CGAL and the like; Googling turns up this survey paper:

https://inria.hal.science/inria-00344355/PDF/p.pdf

Any additional references welcome!

Re:C++ proposal: There are 8 bits in a byte by stephencanon on Friday October 18, 2024 @03:48PM (#41882842)
Note here is a good starting point for the issue itself: http://www.cs.cmu.edu/~quake/triangle.exact.html

References for the actual methods used in Triangle: http://www.cs.cmu.edu/~quake/robust.html

Re:C++ proposal: There are 8 bits in a byte by FooBarBizBazz on Friday October 18, 2024 @10:16AM (#41879704)
I get what you mean and agree, and have seen almost traumatized rants against ffast-math from the very same people.

After digging, I think this is the kind of thing I'm referring to:

https://people.eecs.berkeley.edu/~wkahan/JAVAhurt.pdf

https://news.ycombinator.com/item?id=37028310

I've seen other course notes, I think also from Kahan, extolling 80-bit hardware.

Personally I am starting to think that, if I'm really thinking about precision, I had maybe better just use fixed point, but this again is just a "lean" that could prove wrong over time. Somehow we use floats everywhere and it seems to work pretty well, almost unreasonably so.

Re:C++ proposal: There are 8 bits in a byte by stephencanon on Friday October 18, 2024 @06:58PM (#41884242)
Yeah. Kahan was involved in the design of the 8087, so he’s always wanted to _have_ extended precision available. What he (and I, and most other numerical analysts) are opposed to is the fact that (a) language bindings historically had no mechanism to force rounding to float/double when necessary, and (b) compilers commonly spilled x87 intermediate results to the stack as doubles, leading to intermediate rounding that was extremely sensitive to optimization and subroutine calls, making debugging numerical issues harder than it should be.

Modern floating-point is much more reproducible than fixed-point, FWIW, since it has an actual standard that’s widely adopted, and these excess-precision issues do not apply to SSE or ARM FPUs.

Re:C++ proposal: There are 8 bits in a byte by jcranmer on Friday October 18, 2024 @12:54AM (#41876461)
I'm literally giving a talk next week who's first slide is essentially "Why IEEE 754 is not a sufficient description of floating-point semantics" and I'm sitting here trying to figure out what needs to be thrown out of the talk to make it fit the time slot.

One of the most surprising things about floating-point is that very little is actually IEEE 754; most things are merely IEEE 754-ish, and there's a long tail of fiddly things that are different that make it only -ish.

Re:C++ proposal: There are 8 bits in a byte by chungy on Friday October 18, 2024 @01:19AM (#41876547)
The IEEE 754 standard has been updated several times, often by relaxing previous mandates in order to make various hardware implementations become compliant retroactively (eg, adding Intel's 80-bit floats as a standard floating point size).

It'll be interesting if the "-ish" bits are still "-ish" with the current standard.

Re:C++ proposal: There are 8 bits in a byte by stephencanon on Friday October 18, 2024 @09:40AM (#41879384)
The first 754 standard (1985) was essentially formalization of the x87 arithmetic; it defines a "double extended" format. It is not mandatory:

> Implementations should support the extended format corresponding to the widest basic format supported.

_if_ it exists, it is required to have at least as many bits as the x87 long double type.¹

The language around extended formats changed in the 2008 standard, but the meaning didn't:

> Language standards or implementations should support an extended precision format that extends the widest basic format that is supported in that radix.

That language is still present in the 2019 standard. So nothing has ever really changed here. Double-extended is recommended, but not required. If it exists, the significand and exponent must be at least as large as those of the Intel 80-bit format, but they may also be larger.

---

¹ At the beginning of the standardization process, Kahan and Intel engineers still hoped that the x87 format would gradually expand in subsequent CPU generations until it became what is now the standard 128b quad format; they didn't understand the inertia of binary compatibility yet. So the text only set out minimum precision and exponent range. By the time the standard was published in 1985, it was understood internally that they would never change the type, but by then other companies had introduced different extended-precision types (e.g. the 96-bit type in Apple's SANE), so it was never pinned down.

Re:C++ proposal: There are 8 bits in a byte by adrian_b on Saturday October 19, 2024 @03:17AM (#41886225)
The first 754 standard has still removed some 8087 features, mainly the "projective" infinity and it has slightly changed the definition of the remainder function, so it was not completely compatible with 8087.

Intel 80387 was made compliant with the final standard and by that time there were competing FPUs also compliant with the final standard, e.g. Motorola 68881.

Re:C++ proposal: There are 8 bits in a byte by Terr_ on Friday October 18, 2024 @01:03AM (#41876497)
> there's a long tail of fiddly things that are different that make it only -ish.

Perhaps a way to fill some time would be gradually revealing parts of a convoluted Venn diagram or mind-map of the fiddling things. (That is, assuming there's any sane categorization.)

Re:C++ proposal: There are 8 bits in a byte by speedgoose on Friday October 18, 2024 @01:06AM (#41876510)
I'm interested by your future talk, do you plan to publish a video or a transcript?
Re:C++ proposal: There are 8 bits in a byte by selimthegrim on Monday October 21, 2024 @03:20PM (#41907451)
I too would like to see it.
Re:C++ proposal: There are 8 bits in a byte by aydyn on Friday October 18, 2024 @06:02AM (#41877838)
can you give a brief example? Very intrigued.
Re:C++ proposal: There are 8 bits in a byte by Silphendio on Friday October 18, 2024 @02:27AM (#41876831)
At the very least, division by zero should not be undefined for floats.
Re:C++ proposal: There are 8 bits in a byte by seoulbigchris on Friday October 18, 2024 @04:27AM (#41877394)
Which one? Remember the decimal IEEE 754 floating point formats exist too. Do folks in banking use IEEE decimal formats? I remember we used to have different math libs to link against depending, but this was like 40 years ago.
Re:C++ proposal: There are 8 bits in a byte by mu53 on Friday October 18, 2024 @07:55AM (#41878545)
Java is big for banks, and `BigInteger` is common for monetary types.
Re:C++ proposal: There are 8 bits in a byte by quietbritishjim on Friday October 18, 2024 @06:59AM (#41878213)
Nothing prevents banks (or anyone else) from using a compiler where "float" means binary floating point while some other native or user-defined type supports decimal floating point. In fact, that's probably for the best, since they'll probably have exacting requirements for that type so it makes sense for the application developer to write that type themselves.
Re:C++ proposal: There are 8 bits in a byte by seoulbigchris on Friday October 18, 2024 @11:42AM (#41880459)
I was referring to banks using decimal libraries because they work in base 10 numbers, and I recall a big announcement many years ago when the stock market officially switched from fractional stock pricing to cents "for the benefit of computers and rounding", or some such excuse. It always struck me as strange, since binary fixed and floating point represent those particular quantities exactly, without rounding error. Now with normal dollars and cents calculations, I can see why a decimal library might be preferred.
Re:C++ proposal: There are 8 bits in a byte by stephencanon on Friday October 18, 2024 @09:42AM (#41879403)
Binding float to the IEEE 754 binary32 format would not preclude use of decimal formats; they have their own bindings (e.g. _Decimal64 in C23). (I think they're still a TR for C++, but I haven't been keeping track).
Re:C++ proposal: There are 8 bits in a byte by heinrich5991 on Friday October 18, 2024 @05:37AM (#41877730)
Permalink (press 'y' anywhere on GitHub): https://github.com/torvalds/linux/blob/4d939780b70592e0f4bc6....
Re:C++ proposal: There are 8 bits in a byte by crote on Friday October 18, 2024 @11:07AM (#41880114)
That file hasn't been touched in over 19 years. I don't think we have to worry about the non-permalink url breaking any time soon.