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.

Jensen Huang resigns

https://apnews.com/article/nvidia-megaspeed-china-singapore-huang-5403f152a601cf82ce939f1d24fffa0f
2437•lldb•7h ago•2366 comments

Ask HN: Microsoft/Azure Outage?

383•nazgulsenpai•3h ago•192 comments

Rust 1.100

https://blog.rust-lang.org/2026/11/12/Rust-1.100.0/
138•mbStavola•3h ago•93 comments

Gemini 4 Hydrogen and Orchestrator

https://antigravity.google/blog/gemini-4-hydrogen-in-google-antigravity/
166•jonbaer•2h ago•31 comments

Dwarf planet candidate appears which takes roughly 280 years to orbit our sun

https://www.smithsonianmag.com/smart-news/astronomers-found-a-mysterious-object-orbiting-far-beyo...
104•cybermango•2h ago•45 comments

Show HN: My $300 embroidery machine needed a subscription, so I built my own app

https://github.com/simpsoka/zigzag
182•simpsoka•4h ago•74 comments

22-Year-Old PostgreSQL Bug Turned into Remote Code Execution

https://mehmetince.net/part-3-6-how-i-ended-up-turning-a-22-year-old-postgresql-type-confusion-pr...
72•ozirus•3h ago•10 comments

I'm making LLMs work on small and old devices

https://github.com/hyperionaidev/smolmaxxing/
217•mrashad74•6h ago•78 comments

Foundation Models Framework (macOS)

https://developer.apple.com/foundation-models-framework/
7•kermatt•25m ago•0 comments

Abandoned Quake 4 expansion finished by modders and now playable

https://www.moddb.com/mods/openq4/downloads/openq4-0141-windows-x64
208•klaussilveira•7h ago•75 comments

Data centers need power – lower income, rural residents pay the price

https://news.cornell.edu/stories/2026/11/data-centers-need-power-lower-income-rural-residents-pay...
102•PaulHoule•1h ago•96 comments

Relax: JIT compiler for Rust to reduce build times

https://makepad.github.io/relax/
67•adamnemecek•1d ago•27 comments

Gemini 4 Hydrogen

https://blog.google/innovation-and-ai/models-and-research/gemini-models/introducing-gemini-4-hydr...
376•dvaplima•3h ago•247 comments

Distributed Ray Tracer

https://ray.hatchet.run
17•juliusgeo•2h ago•1 comments

Talking Zen 6 with Mike Clark at AMD In-Depth

https://chipsandcheese.com/p/talking-zen-6-with-mike-clark-at
154•dverlaeckt80•7h ago•2 comments

Show HN: Kapso – Iterative learning from enterprise data

24•alireza_msh•3h ago•9 comments

Why Writing Correct Software Is Hard

https://pron.github.io/posts/correctness-and-complexity
332•AriFordsham•11h ago•148 comments

Words of warning about radiocarbon dating medieval human bones

https://www.nature.com/articles/s40494-026-02958-x
32•gumby•23h ago•3 comments

Show HN: AgentRun – open-source, Self-improving Managed Agents

https://github.com/Parcha-ai/agentrun/blob/main/README.md
54•miguelrios•3h ago•7 comments

Pulling the Lever in a Subway Problem

https://www.jefftk.com/p/pulling-the-lever-in-a-subway-problem
32•NaOH•1d ago•37 comments

ExcalidrawZ: Local Native Excalidraw on macOS/iOS

https://github.com/chocoford/ExcalidrawZ
88•Qision•6h ago•23 comments

Adapting CPython for Yk

https://tratt.net/laurie/blog/2026/adapting_cpython_for_yk.html
15•frostbyte7•8h ago•0 comments

Our software engineering interviews are changing a little

https://blog.janestreet.com/software-engineering-interviews-are-changing-a-little/
135•maitland•7h ago•119 comments

Socratic Tutor

https://github.com/janestreet/agent_skills/blob/master/socratic-tutor/SKILL.md
630•tosh•2d ago•144 comments

AWS Lambda Web Functions keep billing memory ~7 minutes after the last request

https://www.easel.sh/blog/lambda-web-functions-idle-memory
58•seanw265•4h ago•26 comments

Singapore Says U.S. Not Helpful on Investigation into Suspected Spy's Company

https://www.nytimes.com/2026/11/12/business/nvidia-megaspeed-alice-huang.html
110•tedd4u•3h ago•35 comments

Nintendo Takes Down Emulators and Firmware in Massive GitHub DMCA Sweep

https://www.ign.com/articles/nintendo-takes-down-switch-emulators-and-mod-chip-firmware-in-massiv...
221•CharlesW•5h ago•146 comments

Anthropic IPO

https://ipo.anthropic.com/us/
729•josephljohnston•9h ago•739 comments

A live tree of systemd jobs on the boot console

https://codeberg.org/wvhulle/bootvine
335•orhunp_•3d ago•129 comments

Libreagi – Save OSS Models

https://libreagi.com/
104•satuke•7h ago•21 comments