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.

UK Biobank leak: Health details of 500 000 people are offered for sale

https://www.bmj.com/content/393/bmj.s781
166•dberhane•3h ago•63 comments

S. Korea police arrest man over AI image of runaway wolf that misled authorities

https://www.bbc.com/news/articles/c4gx1n0dl9no
175•giuliomagnifico•4h ago•99 comments

Spinel: Ruby AOT Native Compiler

https://github.com/matz/spinel
162•dluan•5h ago•36 comments

Mounting tar archives as a filesystem in WebAssembly

https://jeroen.github.io/notes/webassembly-tar/
48•datajeroen•4h ago•11 comments

DeepSeek v4

https://api-docs.deepseek.com/
1329•impact_sy•11h ago•950 comments

US special forces soldier arrested after allegedly winning $400k on Maduro raid

https://www.cnn.com/2026/04/23/politics/us-special-forces-soldier-arrested-maduro-raid-trade
410•nkrisc•16h ago•445 comments

Show HN: How LLMs Work – Interactive visual guide based on Karpathy's lecture

https://ynarwal.github.io/how-llms-work/
150•ynarwal__•7h ago•35 comments

An update on recent Claude Code quality reports

https://www.anthropic.com/engineering/april-23-postmortem
810•mfiguiere•20h ago•620 comments

Why I Write (1946)

https://www.orwellfoundation.com/the-orwell-foundation/orwell/essays-and-other-works/why-i-write/
215•RyanShook•11h ago•51 comments

How to be anti-social – a guide to incoherent and isolating social experiences

https://nate.leaflet.pub/3mk4xkaxobc2p
115•calcifer•3h ago•101 comments

Bitwarden CLI compromised in ongoing Checkmarx supply chain campaign

https://socket.dev/blog/bitwarden-cli-compromised
807•tosh•23h ago•385 comments

GPT-5.5

https://openai.com/index/introducing-gpt-5-5/
1442•rd•20h ago•958 comments

8087 Emulation on 8086 Systems

https://www.os2museum.com/wp/learn-something-old-every-day-part-xx-8087-emulation-on-8086-systems/
12•ingve•2h ago•5 comments

Show HN: Gova – The declarative GUI framework for Go

https://github.com/NV404/gova
75•aliezsid•7h ago•14 comments

Hear your agent suffer through your code

https://github.com/AndrewVos/endless-toil
58•AndrewVos•3h ago•18 comments

MeshCore development team splits over trademark dispute and AI-generated code

https://blog.meshcore.io/2026/04/23/the-split
244•wielebny•21h ago•132 comments

Meta tells staff it will cut 10% of jobs

https://www.bloomberg.com/news/articles/2026-04-23/meta-tells-staff-it-will-cut-10-of-jobs-in-pus...
686•Vaslo•19h ago•668 comments

Familiarity is the enemy: On why Enterprise systems have failed for 60 years

https://felixbarbalet.com/familiarity-is-the-enemy/
73•adityaathalye•9h ago•39 comments

Using the internet like it's 1999

https://joshblais.com/blog/using-the-internet-like-its-1999/
190•joshuablais•18h ago•130 comments

UK Biobank health data keeps ending up on GitHub

https://biobank.rocher.lc
168•Cynddl•1d ago•41 comments

Aspartame is not that bad? (2022)

https://dynomight.net/aspartame/
72•pHequals7•2h ago•93 comments

Iran War Has Drained U.S. Supplies of Critical, Costly Weapons

https://www.nytimes.com/2026/04/23/us/politics/iran-war-cost-military.html
16•samsolomon•24m ago•2 comments

Habitual coffee intake shapes the microbiome, modifies physiology and cognition

https://www.nature.com/articles/s41467-026-71264-8
219•scubakid•10h ago•150 comments

TorchTPU: Running PyTorch Natively on TPUs at Google Scale

https://developers.googleblog.com/torchtpu-running-pytorch-natively-on-tpus-at-google-scale/
163•mji•17h ago•14 comments

Show HN: Tolaria – Open-source macOS app to manage Markdown knowledge bases

https://github.com/refactoringhq/tolaria
239•lucaronin•16h ago•106 comments

My phone replaced a brass plug

https://drobinin.com/posts/my-phone-replaced-a-brass-plug/
164•valzevul•21h ago•41 comments

Alberta startup sells no-tech tractors for half price

https://wheelfront.com/this-alberta-startup-sells-no-tech-tractors-for-half-price/
2233•Kaibeezy•1d ago•752 comments

Show HN: Agent Vault – Open-source credential proxy and vault for agents

https://github.com/Infisical/agent-vault
123•dangtony98•1d ago•43 comments

A programmable watch you can actually wear

https://www.hackster.io/news/a-diy-watch-you-can-actually-wear-8f91c2dac682
205•sarusso•3d ago•102 comments

Show HN: Honker – Postgres NOTIFY/LISTEN Semantics for SQLite

https://github.com/russellromney/honker
278•russellthehippo•1d ago•69 comments