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.

DeepSeek V4 Flash 0731

https://arcprize.org/results/deepseek-v4-flash-0731
318•tosh•4h ago•195 comments

Assembly Hall of Shame

https://github.com/xoreaxeaxeax/asm-hall-of-shame
170•piotrgrabowski•4h ago•34 comments

Ancient Library – 1,060 Greek/Latin texts, click any word to parse it

https://ancientlibrary.net/
86•aagha•3h ago•27 comments

Responding to the next frontier of critical cyber capabilities

https://openai.com/index/responding-next-frontier-critical-cyber-capabilities/
126•artninja1988•5h ago•142 comments

What happens if an entire class of workers loses faith in their careers

https://www.noemamag.com/why-is-everyone-in-tech-so-sad/
258•RickJWagner•9h ago•396 comments

An all-sky map of half a million supermassive black holes

https://www.sdss.org/black-hole-mapper-release-20/
115•MarcoDewey•6h ago•31 comments

Oracle bans AI-generated code from OpenJDK

https://app.dealroom.co/news/feed/oracle-bans-ai-generated-code-from-openjdk-despite-ellison-s-cl...
308•delduca•4h ago•219 comments

Guarded Methods in OCaml

https://xvw.lol/en/articles/oop-refl.html
27•birdculture•4d ago•1 comments

Psychological Warfare in Reverse Engineering (2015)

https://github.com/xoreaxeaxeax/repsych
29•theanonymousone•3h ago•2 comments

Carl's Required Reading

https://carlkolon.com/reading/
60•cckolon•6d ago•5 comments

App Store Rejection of the Week: Dark Hours

https://daringfireball.net/2026/08/app_store_rejection_of_the_week_dark_hours
185•_da_•3h ago•84 comments

Water system controllers don't belong on the internet, says ex-NSA chief

https://www.theregister.com/security/2026/08/07/water-system-controllers-dont-belong-on-the-inter...
22•Bender•42m ago•4 comments

Making Postgres 300x faster for analytics: batching, operator fusion, and SIMD

https://malisper.me/how-we-made-postgres-hundreds-of-times-faster-the-query-engine/
215•poly2it•11h ago•95 comments

Kitesurf: Agent-first browser that runs in V8 isolates

https://blog.cloudflare.com/kitesurf/
131•m3h•11h ago•37 comments

2027 memory capacity is reportedly sold out

https://www.ign.com/articles/ramageddon-continues-another-year-as-2027-memory-capacity-is-reporte...
163•inigyou•14h ago•143 comments

A year of fighting scrapers on my 1.5 million-page website

https://patronview.com/news/99-percent-of-my-website-traffic-is-bots/
344•petercooper•7h ago•325 comments

Radical Study Suggests Life on Earth Arose Twice

https://www.sciencealert.com/radical-study-suggests-life-on-earth-arose-from-non-living-matter-twice
67•jnord•9h ago•72 comments

Show HN: textlog – A quiet, text-only microblogging platform, open-source, no JS

https://textlog.cc/about
119•stagas•11h ago•51 comments

Möbius-Strip Crosswords

https://quuxplusone.github.io/blog/2026/08/04/mobius-crossword/
45•ibobev•6h ago•4 comments

Databricks drove down AI coding spend 70%

https://www.databricks.com/blog/managing-ai-coding-costs-scale
133•moonikakiss•3h ago•115 comments

Why Are There Statues of Beavers on Top of This Oxford Street Shop?

https://londonist.com/london/history/oxford-street-beavers
48•bookofjoe•4d ago•22 comments

Show HN: Wyzer Programming Language

https://github.com/Wyzer-Lang/wyzer
161•v0id_isgood•9h ago•93 comments

Petri Nets as a Music Sequencer

https://blog.stackdump.com/posts/petri-net-sequencer
56•m_kos•4d ago•19 comments

New Mexico court orders Meta to pay $567m over harms to children’s mental health

https://www.theguardian.com/technology/2026/aug/06/new-mexico-court-meta
698•boplicity•21h ago•377 comments

Energizing a vacuum-tube flip-flop module from a 1948 IBM system

https://www.righto.com/2026/07/ibm-604-trigger-tube-module.html
11•geerlingguy•5d ago•3 comments

Building community out of strangers (2023)

https://tracydurnell.com/2023/11/30/building-community-out-of-strangers/
28•surprisetalk•3d ago•1 comments

São Paulo resident transforms degraded area into urban forest

https://saopaulosecreto.com/en/tiquatira-linear-park-en/
312•rmason•6d ago•117 comments

AMD acquires Taalas to boost inference performance by etching models in silicon

https://www.theregister.com/systems/2026/08/06/amd-acquires-ai-chip-startup-taalas-to-boost-infer...
870•itvision•1d ago•654 comments

Thoroughly Understanding C++ ABI (2024)

https://ykiko.me/en/articles/692886292/
55•rramadass•5d ago•59 comments

TypeStax: A type scale generator with vintage audio hardware interface

https://www.typestax.com/
49•jasim•1w ago•18 comments