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.

OpenAI and Hugging Face address security incident during model evaluation

https://openai.com/index/hugging-face-model-evaluation-security-incident/
1102•mfiguiere•12h ago•750 comments

Kimi K3 Is Competitive with Fable; Kimi K3 and Fable Is SoTA

https://fireworks.ai/blog/kimik3-fable
591•piotrgrabowski•10h ago•327 comments

Original Apollo 11 Guidance Computer source code for command and lunar modules

https://github.com/chrislgarry/Apollo-11
63•noteness•3h ago•16 comments

Intel Starts Shipping High-NA EUV Silicon

https://morethanmoore.substack.com/p/intel-starts-shipping-high-na-euv
54•zdw•3d ago•8 comments

Show HN: ReadKinetic – a free, local-first speed reader for your own books

https://www.readkinetic.com/app/
59•SamuraiLion•2h ago•21 comments

Advertise in ChatGPT

https://ads.openai.com/
721•montecarl•13h ago•503 comments

FreeInk: Open ecosystem for e-readers

https://freeink.org/
548•FriedPickles•14h ago•117 comments

Late.sh – a command-line Clubhouse for computer people

https://late.sh/
148•itherseed•6h ago•50 comments

Judge approves $1.5B Anthropic settlement for pirated books used to train Claude

https://apnews.com/article/ai-anthropic-copyright-settlement-claude-books-bartz-74b140444023898ae...
335•BeetleB•13h ago•257 comments

Gemini 3.6 Flash, 3.5 Flash-Lite, and 3.5 Flash Cyber

https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-3-6-flash-3-5-flas...
682•logickkk1•17h ago•519 comments

A digestion of the Jacobian conjecture counterexample

https://terrytao.wordpress.com/2026/07/21/a-digestion-of-the-jacobian-conjecture-counterexample/
254•jeremyscanvic•11h ago•90 comments

Show HN: A new kind of FPS aim trainer

https://openaim.pramit.gg/
33•pmazumder•3h ago•18 comments

LG to ban residential proxies from smart TV apps

https://krebsonsecurity.com/2026/07/lg-to-ban-residential-proxies-from-smart-tv-apps/
252•DemiGuru•6h ago•220 comments

Atomically Thin Materials Significantly Shrink Qubits

https://spectrum.ieee.org/2d-hbn-qubit
4•Jimmc414•4d ago•0 comments

Ten Steps Towards Happiness (2015)

http://hintjens.com/blog:99
120•emerongi•7h ago•41 comments

Long presumed dead, a thriving coral reef is discovered in West Africa

https://e360.yale.edu/digest/benin-coral-reef
344•speckx•17h ago•73 comments

Jack Dorsey launches Buzz to combine team chat, AI agents and Git hosting

https://runtimewire.com/article/jack-dorsey-block-buzz-team-chat-ai-agents-git
313•ryanmerket•15h ago•268 comments

"Drawing" the Mona Lisa with GPT-5.6, Claude, Gemini, and Grok

https://www.tryai.dev/blog/ai-drawing-arena-colored-pencils-claude-gpt-grok
190•hershyb_•11h ago•71 comments

Apple defeats liability for not scanning iCloud for CSAM

https://blog.ericgoldman.org/archives/2026/07/apple-defeats-liability-for-not-scanning-icloud-for...
408•speckx•18h ago•379 comments

It's a shame what's happened to radio

https://blog.jimgrey.net/2026/07/21/its-a-shame-whats-happened-to-radio-3/
102•sonicrocketman•9h ago•94 comments

ScreenWall – Turn old phones into synced widgets for your space

https://screenwall.app/
11•buibuibui•4d ago•2 comments

Map of the world's great castles and fortresses

https://thecastlemap.com/
248•marklit•16h ago•160 comments

Laguna S 2.1

https://poolside.ai/blog/introducing-laguna-s-2-1
308•rexledesma•15h ago•58 comments

Gemini last models: temperature, top_p, and top_k are deprecated and ignored

https://ai.google.dev/gemini-api/docs/latest-model
78•greatgib•11h ago•26 comments

'VPNs are lawful technical tools,' says EU Court in landmark copyright ruling

https://www.techradar.com/vpn/vpn-privacy-security/vpns-are-lawful-technical-tools-says-eu-court-...
540•healsdata•13h ago•90 comments

I graded 36 popular MCP servers on agent usability. A third got a D or F

https://tengli.dev/posts/mcp-servers-failing-agents.html
7•tengbyte•2h ago•0 comments

The Birth of Prolog (1996)

https://dl.acm.org/doi/10.1145/234286.1057820
97•Jtsummers•4d ago•12 comments

Show HN: Justif – Knuth-Plass justification and microtypography for the web

https://justif.lyall.co/
143•lyall•4d ago•23 comments

My USB Drive Has a Hidden Encrypted Vault

https://rootkitlabs.com/2026/06/22/I%27m-Building-a-Secure-USB-Drive/
229•machinehum•2d ago•137 comments

Tesla Balance Bike

https://shop.tesla.com/product/balance-bike-for-kids
11•surprisetalk•4h ago•14 comments