frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

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•12mo 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.

Project Gutenberg – keeps getting better

https://www.gutenberg.org/
827•JSeiko•13h ago•184 comments

Ploopy Bean: a trackpoint for every computer

https://ploopy.co/shop/bean-pointing-stick/
49•jibcage•3d ago•18 comments

I believe there are entire companies right now under AI psychosis

https://twitter.com/mitchellh/status/2055380239711457578
1089•reasonableklout•9h ago•500 comments

Additive Blending on the Nintendo 64

https://phoboslab.org/log/2026/05/n64-additive-blending
73•ibobev•15h ago•7 comments

The bird eye was pushed to an evolutionary extreme

https://www.quantamagazine.org/how-the-bird-eye-was-pushed-to-an-evolutionary-extreme-20260513/
62•sohkamyung•1d ago•13 comments

The main thing about P2P meth is that there's so much of it (2021)

https://dynomight.net/p2p-meth/
91•tomjakubowski•6h ago•85 comments

England Runestones

https://en.wikipedia.org/wiki/England_runestones
19•cl3misch•2d ago•2 comments

SQL patterns I use to catch transaction fraud

https://analytics.fixelsmith.com/posts/sql-fraud-patterns/
72•redbell•6h ago•15 comments

Naturally Occurring Quasicrystals

https://johncarlosbaez.wordpress.com/2026/05/14/naturally-occurring-quasicrystals/
83•lukeplato•1d ago•6 comments

Research on mildew contamination affecting the sound quality of analog tapes

https://www.nature.com/articles/s40494-026-02592-7
6•crousto•1d ago•0 comments

A 0-click exploit chain for the Pixel 10

https://projectzero.google/2026/05/pixel-10-exploit.html
353•happyhardcore•16h ago•167 comments

How to Write to SSDs [pdf]

https://www.vldb.org/pvldb/vol19/p1469-lee.pdf
77•matt_d•7h ago•6 comments

NYT and Vaping: How to Lie by Saying Only True Things (2022)

https://gwern.net/vaping
66•Ariarule•5h ago•13 comments

I Bought a “Junk” PSP From Japan

https://gardinerbryant.com/i-bought-a-junk-psp-from-japan-heres-how-it-went/
28•Kate0CoolLibby•3d ago•10 comments

California bill would require patches or refunds when online games shut down

https://arstechnica.com/gaming/2026/05/bill-to-keep-online-games-playable-clears-key-hurdle-in-ca...
411•Lihh27•10h ago•256 comments

The sigmoids won't save you

https://www.astralcodexten.com/p/the-sigmoids-wont-save-you
179•Tomte•19h ago•176 comments

ESP-EEG is an affordable 8-channel biosensing board

https://www.autodidacts.io/cerelog-esp-eeg-affordable-openbci-like-board/
37•surprisetalk•2d ago•13 comments

Show HN: Epiq – Distributed Git based issue tracker TUI

https://ljtn.github.io/epiq/
36•jolaflow•5h ago•12 comments

Erlang/OTP 29.0

https://www.erlang.org/news/188
160•pyinstallwoes•6h ago•20 comments

I designed a nibble-oriented CPU in Verilog to build a scientific calculator

https://github.com/gdevic/FPGA-Calculator
96•gdevic•12h ago•33 comments

Orthrus-Qwen3: up to 7.8×tokens/forward on Qwen3, identical output distribution

https://github.com/chiennv2000/orthrus
33•FranckDernoncou•7h ago•3 comments

Image-blaster: Creates 3D environments, SFX, and meshes from a single image

https://github.com/neilsonnn/image-blaster
147•MattRogish•14h ago•28 comments

The Zulip Foundation

https://blog.zulip.com/2026/05/15/announcing-zulip-foundation/
245•boramalper•11h ago•62 comments

U.S. DOJ demands Apple and Google unmask over 100k users of car-tinkering app

https://macdailynews.com/2026/05/15/u-s-doj-demands-apple-and-google-unmask-over-100000-users-of-...
399•tencentshill•12h ago•271 comments

'No way to prevent this,' says only package manager where this regularly happens

https://kevinpatel.xyz/posts/no-way-to-prevent-this/
283•alligatorplum•5h ago•122 comments

Show HN: Watch a neural net learn to play Snake

https://ppo.gradexp.xyz/
136•c1b•1d ago•33 comments

ASCII by Jason Scott

https://ascii.textfiles.com/
171•bookofjoe•15h ago•22 comments

Radicle: Sovereign {code forge} built on Git

https://radicle.dev/
229•KolmogorovComp•17h ago•78 comments

ABC News has taken all FiveThirtyEight articles offline

https://twitter.com/baseballot/status/2055309076209492208
300•cmsparks•10h ago•141 comments

Waymo updates 3,800 robotaxis after they 'drive into standing water'

https://www.cnbc.com/2026/05/12/waymo-recalls-3800-robotaxis-after-able-drive-into-standing-water...
176•drob518•11h ago•171 comments