frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Comparing floating-point numbers (2012)

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
26•sph•1y ago

Comments

LegionMammal978•1y ago
I'd argue that any equality comparison of floating-point numbers is asking for trouble, unless you're specifically working with small dyadic fractions (using exact comparison) or testing a purely heuristic 'closeness' condition (using fuzzy comparison).

Of course, inequalities show up in a lot more places, but are similarly fraught with difficulty, since mathematical statements may fail to translate to floating-point inequalities. E.g., in computational geometry, people have written entire papers about optimizing correct orientation predicates [0], since the naive method can easily break at small angles. This sort of thing is what often shows up as tiny seams in 3D video-game geometry.

[0] https://www.cs.cmu.edu/~quake/robust.html

mtklein•1y ago
My preferred way to compare floats as being interchangeably equivalent in unit tests is

    bool equiv(float x, float y) {
        return (x <= y && y <= x)
            || (x != x && y != y);
    }
This handles things like ±0 and NaNs (while NaNs can't be IEEE-754-equal per se, they're almost always interchangeable), and convinces -Wfloat-equal you kinda know what you're doing. Also everything visually lines up real neat and tidy, which I find makes it easy to remember.

Outside unit tests... I haven't really encountered many places where float equality is actually what I want to test. It's usually some < or <= condition instead.

sph•1y ago
I have built a production Javascript library with decent amounts of users that incorporates the following hack to deal with float error (avert your eyes if you're sensitive):

  // 1.2 - 1.0 === 0.19999999999999996
  // fixFloatError(1.2 - 1.0) === 0.2
  var fixFloatError = function (n) {
    return parseFloat(n.toPrecision(12));
  };
It felt correct at the time, but after reading the article, I cringe at how fundamentally broken it is. I got away with it because the library is used to convert betting odds, which are mostly small floating point numbers, so the error is often < 10^-12.

MiniMax M3.1 Flash

https://www.minimax.io/blog/minimax-m31f
338•jtg•7h ago•150 comments

I built a drone with only one motor [video]

https://www.youtube.com/watch?v=Ndftcft6XhU
324•hakonjdjohnsen•14h ago•60 comments

OpenBSD 8.0 release will have inteldrm/radeondrm/amdgpu drivers from Linux 6.18

https://bsd.network/@brynet/117407035545900963
57•doener•2h ago•9 comments

Wine ported to OpenBSD

https://marc.info/?l=openbsd-ports&m=179236125692175
482•iamnothere•10h ago•162 comments

Putting Linux on my RTX Spark laptop because I don't have a Microsoft account

https://josie.lol/blog/linux-rtx-spark
148•pfeifferj•2h ago•64 comments

RuneScape Bench: MMOs for Agents [video]

https://www.youtube.com/watch?v=cNm4zyUtWj0
135•evakhoury•2d ago•54 comments

It's still ok to enjoy programming

https://chriskiehl.com/article/it-is-still-ok-to-enjoy-programming
398•goostavos•2d ago•379 comments

Android apps running native on macOS

https://github.com/kksimp/Mac.apk
234•flocked•6h ago•108 comments

One Hash Bloom Filters

https://calabro.io/ohbf
20•jcalabro•2h ago•1 comments

Timestral: Mistral's time-series foundation models

https://mistral.ai/news/timestral/
528•groar•13h ago•97 comments

Starcraft: Ashfall

https://starcraft-shooter-2026.pages.dev/
265•debo_•22h ago•92 comments

The fire retardant in the seafood chain

https://insideclimatenews.org/news/14102026/ethoxyquin-fire-retardant-in-seafood-chain/
95•gumby•2d ago•31 comments

Drupal is now light-years ahead of its reputation

https://dri.es/state-of-drupal-presentation-september-2026
14•scottfalconer•2h ago•7 comments

Alternatives to animal testing are finally taking off

https://spectrum.ieee.org/alternatives-to-animal-testing
308•rbanffy•12h ago•91 comments

Ask HN: How to deal with shipping AI-written code you don't understand?

221•rzk•12h ago•359 comments

Agentic Monitoring

https://benjamincongdon.me/blog/2026/10/19/Agentic-Monitoring/
21•bcongdon•8h ago•2 comments

Credit where credit is due

https://thefloatingcontinent.com/blog/credit-is-due/
53•evakhoury•3d ago•34 comments

The reverts will continue until morale improves

http://peter.eisentraut.org/blog/2026/10/09/the-reverts-will-continue-until-morale-improves
176•hans_castorp•5h ago•29 comments

Evidence (YC S21) Is Hiring Software Engineers

https://evidence.dev/jobs
1•hughess•6h ago

The End of Rationing

https://sanketsaurav.com/writing/end-of-rationing
21•sanketsaurav•4h ago•10 comments

Weball: Play Katamari on Websites

https://www.funwithcomputervision.com/weball/
4•croes•1d ago•1 comments

Launch HN: Laminar (YC S24) – RL-trained model that finds errors in agent traces

44•skull8888888•7h ago•22 comments

Ukraine claims first drone evacuation of wounded soldier

https://www.nbcnews.com/world/ukraine/ukraine-first-drone-evacuation-wounded-soldier-frontlines-h...
50•yzydserd•8h ago•64 comments

Chicago O'Hare digs up 50-ton boulder under airfield, asks public for name ideas

https://simpleflying.com/chicago-ohare-digs-up-50-ton-boulder-public-names/
94•Stratoscope•21h ago•79 comments

Let's Encrypt is adding two additional remote perspectives for domain validation

https://community.letsencrypt.org/t/lets-encrypt-is-adding-two-additional-remote-perspectives-for...
237•gslin•12h ago•76 comments

Plex vulnerabilities being exploited in the wild to drop a cryptominer

http://www.boredhackerblog.info/2026/10/plex-vulnerabilities-being-exploited-in.html
138•mindracer•10h ago•63 comments

Mercury 3: Diffusion at scale

https://www.inceptionlabs.ai/blog/introducing-mercury-3
211•cmrdporcupine•6h ago•82 comments

The Annotated VT100 Firmware (2022)

https://vt100.net/dec/vt100/rom/
61•Aleksandr_NFA•21h ago•3 comments

CERN and Mistral sign a statement of intent to establish a strategic partnership

https://home.cern/cern-and-mistral-join-forces-to-accelerate-ai-for-science/
307•kensai•8h ago•57 comments

Detecting model weight tampering in GPU memory (Rome attacks)

https://stealthium.io/blog/hands-off-detecting-model-weight-tampering
15•rafaeldavidtin•9h ago•1 comments