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•11mo ago

Comments

LegionMammal978•11mo 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•11mo 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•11mo 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.

How Mark Klein told the EFF about Room 641A [book excerpt]

https://thereader.mitpress.mit.edu/the-whistleblower-who-uncovered-the-nsas-big-brother-machine/
547•the-mitr•14h ago•181 comments

Meta's Big Tobacco PR Tactics

https://yadin.com/notes/toasted/
5•dryadin•40m ago•0 comments

New copy of earliest poem in English, written 1,3k years ago, discovered in Rome

https://www.tcd.ie/news_events/articles/2026/caedmons-hymn-discovery/
35•giuliomagnifico•1d ago•1 comments

For Linux kernel vulnerabilities, there is no heads-up to distributions

https://www.openwall.com/lists/oss-security/2026/04/30/10
458•ori_b•14h ago•345 comments

Opus 4.7 knows the real Kelsey

https://www.theargumentmag.com/p/i-can-never-talk-to-an-ai-anonymously
302•ilamont•1d ago•158 comments

Shai-Hulud Themed Malware Found in the PyTorch Lightning AI Training Library

https://semgrep.dev/blog/2026/malicious-dependency-in-pytorch-lightning-used-for-ai-training/
381•j12y•15h ago•129 comments

Roboticist-Turned-Teacher Built a Life-Size Replica of Eniac

https://spectrum.ieee.org/roboticist-turned-teacher-eniac-replica
23•oldnetguy•1d ago•5 comments

Maladaptive Frugality

https://herbertlui.net/maladaptive-frugality/
79•herbertl•2d ago•51 comments

Can I disable all data collection from my vehicle?

https://rivian.com/support/article/can-i-disable-all-data-collection-from-my-vehicle
599•Cider9986•10h ago•238 comments

CPanel and WHM Authentication Bypass – CVE-2026-41940

https://labs.watchtowr.com/the-internet-is-falling-down-falling-down-falling-down-cpanel-whm-auth...
86•zikani_03•8h ago•28 comments

I built a Game Boy emulator in F#

https://nickkossolapov.github.io/fame-boy/building-a-game-boy-emulator-in-fsharp/
260•elvis70•14h ago•55 comments

Softmax, can you derive the Jacobian? And should you care?

https://idlemachines.co.uk/essays/softmax
15•smaddrellmander•3d ago•0 comments

Claude Code refuses requests or charges extra if your commits mention "OpenClaw"

https://twitter.com/theo/status/2049645973350363168
1096•elmean•16h ago•601 comments

How an oil refinery works

https://www.construction-physics.com/p/how-an-oil-refinery-works
395•chmaynard•17h ago•119 comments

OpenWarp

https://openwarp.zerx.dev
73•zero-lab•5h ago•62 comments

Apple Says Mac Studio and Mac Mini Will Be in Short Supply for Months

https://www.macrumors.com/2026/04/30/mac-studio-mac-mini-constrained-months/
28•tosh•54m ago•16 comments

You can beat the binary search

https://lemire.me/blog/2026/04/27/you-can-beat-the-binary-search/
300•vok•3d ago•136 comments

New mechanical panoramic film camera from Jeff Bridges

https://wideluxx.com
127•armadsen•2d ago•61 comments

Reverse Engineering SimTower

https://phulin.me/blog/simtower
180•patrickhulin•2d ago•32 comments

Honker – Durable queues, streams, pub/sub, and cron scheduler in a SQLite file

https://honker.dev/
208•ferriswil•16h ago•53 comments

Belgium stops decommissioning nuclear power plants

https://dpa-international.com/general-news/urn:newsml:dpa.com:20090101:260430-930-14717/
792•mpweiher•18h ago•782 comments

I Got Sick of Remembering Port Numbers

https://gregraiz.com/blog/local-vibe/
69•graiz•2d ago•62 comments

Snowball Earth may hide a far stranger climate cycle than anyone expected

https://sciencex.com/news/2026-04-snowball-earth-stranger-climate.html
71•wglb•8h ago•14 comments

Full-Text Search with DuckDB

https://peterdohertys.website/blog-posts/full-text-search-w-duckdb.html
120•ethagnawl•13h ago•28 comments

10Gb/s Ethernet: what I did to get it working in my home

https://www.gilesthomas.com/2026/04/10g-ethernet-what-i-did
188•gpjt•1d ago•134 comments

Show HN: Winpodx – run Windows apps on Linux as native windows

https://github.com/kernalix7/winpodx
67•kernalix7•4h ago•33 comments

I aggregated 28 US Government auction sites into one search

https://bidprowl.com
272•scarsam•18h ago•76 comments

Does Postgres Scale?

https://www.dbos.dev/blog/benchmarking-workflow-execution-scalability-on-postgres
120•KraftyOne•12h ago•56 comments

The Church Rock Uranium Mill Spill

https://en.wikipedia.org/wiki/Church_Rock_uranium_mill_spill
86•Sir_Twist•2d ago•5 comments

Follow-up to Carrot disclosure: Forgejo

https://dustri.org/b/follow-up-to-carrot-disclosure-forgejo.html
61•homebrewer•11h ago•10 comments