News for hackers. Stuff that matters.
Re:Aztec monks with 1/55 HP no longer die when picking up or... by carlmr on Saturday April 15, 2023 @10:16AM (#35580820)
>It's 2023: I'm still surprised that so many new languages/platforms still only provide only basic integer and IEEE-754 types for numerics: Rust, C#, Java, Swift and others still lack built-in, runtime-provided, nor even standard-library-provided rational types

C# has the base-10 high accuracy decimal type: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Re:Aztec monks with 1/55 HP no longer die when picking up or... by colejohnson66 on Saturday April 15, 2023 @10:42AM (#35581035)
There are two problems with the `decimal` type: it's not IEEE-754 compliant, and it is 16 bytes, which prevents atomic reads/writes (without locks).

This is a problem in one of my company's applications, as we have a background thread doing work entirely with `decimal` objects, but to provide a readout for the GUI necessitates a lock on every write (even if never read), and another for the read by the GUI. There's barely any overhead (nanoseconds worth), but the logic to work around it is a pain, and, if you forget to actually use a lock, good luck with that bug.

.NET 8, however, will introduce[0][1] proper IEEE-754 decimal float types, including `Decimal32` and `Decimal64` which will allow atomic reads/writes.

[0]: https://github.com/dotnet/runtime/issues/81376

[1]: https://github.com/dotnet/runtime/issues/79004