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.

CFTC declares market emergency, orders Kalshi to continue to operate in New York

https://www.cftc.gov/PressRoom/PressReleases/9281-26
87•michaefe•1h ago•48 comments

WorldClaw Agentic 3D open-world generation at scale

https://tencent-hunyuan.github.io/Hunyuan3D-WorldClaw/
107•EwanG•3h ago•38 comments

Compression is prediction

https://ngrok.com/blog/compression-is-prediction
242•nikolay•5h ago•102 comments

Nvidia Nemotron 3.5 Lightning and NeMo Switchyard

https://blogs.nvidia.com/blog/nemotron-lightning-switchyard-rtx-dgx/
176•droidjj•5h ago•89 comments

Mojo 1.0

https://www.modular.com/blog/modular-26-5-mojo-1-0-is-here
283•dayanruben•8h ago•128 comments

Stealing Reasoning Traces from Proprietary LLM APIs

https://stolen-thoughts.com/
485•quantumgarbage•12h ago•203 comments

OpenAI’s head of ethics leaves less than a year after joining

https://www.ft.com/content/e49dfb75-f841-4466-a577-f7aaff8779a0
271•ilamont•12h ago•343 comments

Making holograms with a pen plotter

https://blog.jordan.matelsky.com/Penplotter-holography/
111•DemiGuru•6h ago•11 comments

Show HN: iPhone app takes simultaneous images from 2 lenses, fuses into 1 photo

https://photosynthesis.camera
198•sajomes•3d ago•204 comments

Show HN: Line9 – A Mermaid rendering engine with its own layout

https://line9.ai/diagram
19•jumpalongjim•5d ago•3 comments

Grok Bot

https://x.ai/bot
128•rvz•7h ago•116 comments

US hires over 2k video gamers as air traffic controllers

https://www.cbsnews.com/news/video-gamer-air-traffic-controllers-faa-recruitment-sean-duffy/
64•shagie•1h ago•48 comments

Go is an ideal language for AI-assisted software engineering

https://developers.googleblog.com/why-go-is-an-ideal-language-for-ai-assisted-software-engineering/
255•0xedb•8h ago•313 comments

Show HN: Tamron Lens Utility Alternative on Linux

https://github.com/yikerman/tamron-lens-control
18•xiaoyu2006•4d ago•0 comments

Suzanne: AI tool for designing and manufacturing physical products

https://www.suzanne3d.com/
36•Samanthajeanneb•3h ago•26 comments

Retire the Abstractions

https://hazyresearch.stanford.edu/blog/2026-08-05-retire-the-abstractions
4•convexstrictly•6d ago•0 comments

pg_clickhouse v0.10: Subquery pushdown and 1000x faster TPC-H queries

https://clickhouse.com/blog/pg_clickhouse-whats-new-july-2026
32•saisrirampur•3h ago•2 comments

How we used to get jobs: A newspaper classifieds story

https://ironicsans.ghost.io/how-we-used-to-get-jobs/
107•speckx•7h ago•89 comments

England set to be one of the first countries to eliminate hepatitis C

https://www.bbc.com/news/articles/c75gk620r22o
486•stevekemp•12h ago•349 comments

Jolt: Clojure compiler implemented with Chez Scheme

https://jolt-lang.github.io
144•mark_l_watson•3d ago•53 comments

RSI Simulator

https://www.paradigm.xyz/writing/rsi-simulator
30•ckraeuter•8h ago•12 comments

Nvidia's Risky Business

https://stratechery.com/2026/nvidias-risky-business/
290•jonbaer•15h ago•138 comments

Manus will return to operating as an independent company

https://manus.im/blog/a-note-to-our-users
131•thm•11h ago•68 comments

Show HN: Git-knife – Edit commit messages, authors, and dates like a spreadsheet

https://github.com/TheRealYT/git-knife
128•YonathanTesfaye•10h ago•85 comments

CSS properties you should know for better text designs

https://master.dev/blog/typographic-css-tricks/
73•ibobev•8h ago•7 comments

London Underground begins scanning passengers' faces

https://www.btp.police.uk/news/btp/news/england/btp-expands-live-facial-recognition-lfr-trial-int...
216•BlueBerry2001•15h ago•252 comments

Emergent Introspective Awareness in Large Language Models

https://arxiv.org/abs/2601.01828
23•doener•4h ago•9 comments

OpenSSH 10.5/10.5p1

https://www.openssh.org/releasenotes.html#10.5
99•voxadam•7h ago•32 comments

The Hat and the Spectre – Recent Groundbreaking Discoveries in Mathematics

https://momath.org/the-hat/
14•vismit2000•3d ago•2 comments

Apple Silicon and macOS VMs: Faster LLM Inference with llama.cpp

https://github.com/trycua/cua/blob/main/blog/gpu-passthrough-macos-vms.md
286•frabonacci•10h ago•43 comments