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•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.

Show HN: Audiomass – a free, open-source multitrack audio editor for the web

https://audiomass.co/?multitrack=1
146•pantelisk•10h ago•36 comments

DeepSeek reasonix, DeepSeek native coding agent with high caching and low cost

https://esengine.github.io/DeepSeek-Reasonix/
430•Alifatisk•12h ago•196 comments

A fundamental principle of aeronautical engineering has been overturned

https://www.wired.com/story/a-fundamental-principle-of-aeronautical-engineering-has-been-overturned/
51•littlexsparkee•6h ago•23 comments

Memory has grown to nearly two-thirds of AI chip component costs

https://epoch.ai/data-insights/ai-chip-component-cost-shares
291•intelkishan•9h ago•311 comments

I spent 50 hours drawing a line graph

https://www.dougmacdowell.com/50-hours-to-draw-some-lines.html
431•dougdude3339•3d ago•74 comments

Defeating Git Rigour Fatigue with Jujutsu

https://ikesau.co/blog/defeating-git-rigour-fatigue-with-jujutsu/
90•ikesau•6h ago•75 comments

Constraint Decay: The Fragility of LLM Agents in Back End Code Generation

https://arxiv.org/abs/2605.06445
172•wek•12h ago•85 comments

Using HTTP/2 Cleartext for a server in Go 1.24

https://www.clarityboss.com/blog/go-http2-cleartext-h2c-cloud-run
55•dan_sbl•5d ago•6 comments

Microsoft open-sources “the earliest DOS source code discovered to date”

https://arstechnica.com/gadgets/2026/04/microsoft-open-sources-the-earliest-dos-source-code-disco...
424•DamnInteresting•1d ago•147 comments

Mastering Dyalog APL

https://mastering.dyalog.com/README.html
126•tosh•13h ago•36 comments

Noroboto: Lying Fonts and Mitigation in Rust

https://tritium.legal/blog/noroboto
57•piker•2d ago•25 comments

Scientists solve 200-year-old puzzle of how tobacco plants make nicotine

https://www.york.ac.uk/news-and-events/news/2026/research/200-year-old-puzzle-tobacco-plants-nico...
39•sohkamyung•2d ago•15 comments

Build Adafruit projects right from Firefox

https://www.firefox.com/en-US/landing/adafruit/
110•mch82•2d ago•33 comments

1k-year-old dingo bones show that it was injured, cared for, and ritually buried

https://www.popsci.com/environment/dingo-bones-ritual-burial-australia/
15•gmays•5d ago•0 comments

Greg Brockman interview [video]

https://fs.blog/knowledge-project-podcast/greg-brockman/
176•prakashqwerty•17h ago•168 comments

Getting an old Computer online with Android Ethernet tethering

https://82mhz.net/posts/2026/05/getting-an-old-computer-online-with-android-ethernet-tethering/
33•speckx•3d ago•14 comments

Scammers are abusing an internal Microsoft account to send spam links

https://techcrunch.com/2026/05/21/scammers-are-abusing-an-internal-microsoft-account-to-send-spam/
267•spike021•1d ago•148 comments

Migrating from Go to Rust

https://corrode.dev/learn/migration-guides/go-to-rust/
132•jabits•7h ago•125 comments

Childhood Computing

https://susam.net/childhood-computing.html
158•blenderob•13h ago•87 comments

LAN-LOK: The Antarctic DOS Sabotage Game Lost for 34 Years

https://alphapixeldev.com/lan-lok-the-antarctic-dos-sabotage-game-lost-for-34-years-part-1/
49•miffe•4d ago•7 comments

Perceptual Image Codec: What Matters in Practical Learned Image Compression

https://apple.github.io/ml-pico/
88•ksec•13h ago•25 comments

Flick (YC F25) Is Hiring Front End Engineer to Build Figma for AI Filmmaking

https://www.ycombinator.com/companies/flick/jobs/Tdu6FH6-senior-frontend-engineer
1•rayruiwang•8h ago

Why is Vivado 2026.1 dropping Linux support for free tier?

https://adaptivesupport.amd.com/s/question/0D5Pd00001YQLdMKAX/why-is-vivado-20261-dropping-linux-...
298•zdw•21h ago•182 comments

Book Review: On the Calculation of Volume

https://www.stephendiehl.com/posts/calculation_of_volume/
29•ibobev•3d ago•8 comments

Ruby for Good

https://ti.to/codeforgood/rubyforgood
118•mooreds•9h ago•51 comments

I keep bouncing off the Scheme language

https://www.sicpers.info/2026/05/i-keep-bouncing-off-the-scheme-language/
130•ingve•2d ago•52 comments

CBP Directive 3340-049B: Border Search of Electronic Devices

https://www.cbp.gov/document/directives/cbp-directive-no-3340-049b-border-search-electronic-devices
120•Ember_Wipe•6h ago•78 comments

The C64 Dead Test Font

https://www.masswerk.at/nowgobang/2026/c64-dead-test-font
126•masswerk•21h ago•24 comments

Usborne 1980s Computer Books

https://usborne.com/us/books/computer-and-coding-books
157•ngram•9h ago•48 comments

Time to talk about my writerdeck

https://veronicaexplains.net/my-first-writerdeck/
454•hggh•1d ago•277 comments