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.

Formalizing Fermat's Last Theorem

https://www.anthropic.com/research/formalizing-fermats-last-theorem
266•jlebar•2h ago•147 comments

Discovery of a new OpenAI agent message board

https://collusion.wiki/
1284•moultano•9h ago•1038 comments

Shutting down our public encrypted DNS

https://mullvad.net/en/blog/shutting-down-our-public-encrypted-dns-servers-and-sponsoring-quad9-i...
131•mywacaday•2h ago•33 comments

Can AI design circuit boards yet?

https://eebench.org/blog/can-ai-design-circuit-boards-yet/
44•iopapa•1h ago•27 comments

Show HN: Open-Source eInk Bike Computer

https://opentrailpaper.com
163•stingrae•3h ago•54 comments

Government Rails Site Hit Hours After CVE Patch

https://rietta.com/blog/ruby-on-rails-cve-exploited-hours-after-patch/
37•rietta•1h ago•9 comments

An open DNS recursive service for free security and high privacy

https://quad9.net/
13•mooreds•44m ago•2 comments

The Rust React Compiler is now native in Vite

https://blog.master.dev/react-now-rusted-all-the-way-out/
64•acusti•3h ago•12 comments

IBM Bob

https://bob.ibm.com/
185•artpar•8h ago•223 comments

deSEC – Free Secure DNS

https://desec.io/
81•gurjeet•5h ago•30 comments

Solving the Jane Street reverse engineering challenge

https://jestoph.com/2026/09/04/jane-street-challenge.html
354•anitil•10h ago•81 comments

Adult Film Producer Unmasks Prolific 'John DOE' Torrent Pirate as Meta Executive

https://torrentfreak.com/adult-film-producer-unmasks-prolific-john-doe-torrent-pirate-as-meta-exe...
218•speckx•4h ago•122 comments

Project HydraFusion: Frontier quality via multi-model orchestration

https://github.blog/ai-and-ml/github-copilot/project-hydrafusion-frontier-quality-via-multi-model...
44•qainsights•4h ago•26 comments

Show HN: TERMy – A fast terminal assistant that does not use LLMs

https://github.com/gioblu/NPC-Forge/blob/main/docs/development.md
63•gioscarab•11h ago•23 comments

How to Create a Tor Exit Node

https://madpsy.uk/how-to-create-a-tor-exit-node/
6•Eridanus2•41m ago•0 comments

Corporate America is getting hooked on open-source AI

https://www.nytimes.com/2026/09/04/technology/open-source-ai-anthropic-openai.html
217•aaraujo002•5h ago•198 comments

People that worked on the same idea for decades

https://nityasnotes.com/writing/decades/
34•sebg•1d ago•16 comments

Deadpan Photography: Enjoying the Pretence

https://photoni.st/index.php/2026/07/12/deadpan-photography-enjoying-the-pretence/
8•NaOH•3d ago•4 comments

Elevator of the Year: Modernization of the Metropolis Trust Building

https://www.starelevator.com/projects/star-elevator-modernization-of-the-metropolis-trust-building
131•palashawas•3d ago•47 comments

Fermat's Last Theorem in Lean 4

https://github.com/anthropics/fermats-last-theorem
11•aaraujo002•2h ago•3 comments

Getting Started with AT Protocol

https://bnb.im/posts/atproto-essential-resources/
64•evakhoury•3d ago•22 comments

Ok, but does it scale?

https://spacetimedb.com/blog/how-does-spacetime-scale
98•theanonymousone•8h ago•61 comments

SubImage (YC W25) Is Hiring a Founding Engineer in SF

https://www.ycombinator.com/companies/subimage/jobs/NCTFgKK-founding-engineer
1•alexchantavy•8h ago

The Two Abstractions of System Design: Hide or Reduce

http://muratbuffalo.blogspot.com/2026/05/the-two-abstractions-of-system-design.html
92•ubolonton_•2d ago•10 comments

Qwen 3.8 27B available on Cerebras at 1500 tokens/s

https://inference-docs.cerebras.ai/models/overview
675•altertable•1d ago•221 comments

GPT-6 Astra

https://openai.com/index/gpt-6-astra/
2128•kibae•1d ago•1934 comments

Google AI Mode shows same products 21.6% more expensive than traditional search

https://productrise.app/blog/google-ai-mode-prefers-more-expensive-products
349•DeepLogin•8h ago•70 comments

Arrested for a Late Manuscript: Seicho Matsumoto's 'Tokyo Express'

https://www.millersbookreview.com/p/arrested-for-a-late-manuscript-seicho-matsumoto-tokyo-express
14•benbreen•1d ago•4 comments

The largest electric aircraft just flew [video]

https://www.youtube.com/watch?v=nM86DBOqgPM
459•feb•3d ago•344 comments

Restoring 5 GHz Wi-Fi on an LG C5 by changing its webOS region

https://github.com/hawshemi/lg-c5-webos25-region-change
53•hawshemi•8h ago•63 comments