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•8mo ago

Comments

LegionMammal978•8mo 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•8mo 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•8mo 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.

I built a light that reacts to radio waves [video]

https://www.youtube.com/watch?v=moBCOEiqiPs
25•codetheweb•1h ago•2 comments

Talking to LLMs has improved my thinking

https://philipotoole.com/why-talking-to-llms-has-improved-my-thinking/
60•otoolep•2h ago•35 comments

Capital One to acquire Brex for $5.15B

https://www.reuters.com/legal/transactional/capital-one-buy-fintech-firm-brex-515-billion-deal-20...
268•personjerry•9h ago•190 comments

GPTZero finds 100 new hallucinations in NeurIPS 2025 accepted papers

https://gptzero.me/news/neurips/
790•segmenta•15h ago•426 comments

Show HN: isometric.nyc – giant isometric pixel art map of NYC

https://cannoneyed.com/isometric-nyc/
807•cannoneyed•13h ago•168 comments

Why does SSH send 100 packets per keystroke?

https://eieio.games/blog/ssh-sends-100-packets-per-keystroke/
391•eieio•11h ago•237 comments

TI-99/4A: Leaning More on the Firmware

https://bumbershootsoft.wordpress.com/2026/01/17/ti-99-4a-leaning-more-heavily-on-the-firmware/
11•ibobev•4d ago•2 comments

I was banned from Claude for scaffolding a Claude.md file?

https://hugodaniel.com/posts/claude-code-banned-me/
455•hugodan•11h ago•350 comments

Qwen3-TTS family is now open sourced: Voice design, clone, and generation

https://qwen.ai/blog?id=qwen3tts-0115
541•Palmik•16h ago•174 comments

Turso is an in-process SQL database, compatible with SQLite

https://github.com/tursodatabase/turso
89•marklit•3d ago•50 comments

Writing First, Tooling Second

https://susam.net/writing-first-tooling-second.html
14•blenderob•3d ago•1 comments

Bugs Apple Loves

https://www.bugsappleloves.com
399•nhod•4h ago•142 comments

Improving the usability of C libraries in Swift

https://www.swift.org/blog/improving-usability-of-c-libraries-in-swift/
86•timsneath•7h ago•3 comments

Douglas Adams on the English–American cultural divide over "heroes"

https://shreevatsa.net/post/douglas-adams-cultural-divide/
396•speckx•16h ago•391 comments

Scaling PostgreSQL to power 800M ChatGPT users

https://openai.com/index/scaling-postgresql/
129•mustaphah•9h ago•42 comments

Why medieval city-builder video games are historically inaccurate (2020)

https://www.leidenmedievalistsblog.nl/articles/why-medieval-city-builder-video-games-are-historic...
99•benbreen•6h ago•56 comments

Your app subscription is now my weekend project

https://rselbach.com/your-sub-is-now-my-weekend-project
295•robteix•4d ago•216 comments

Launch HN: Constellation Space (YC W26) – AI for satellite mission assurance

35•kmajid•13h ago•15 comments

CSS Optical Illusions

https://alvaromontoro.com/blog/68091/css-optical-illusions
162•ulrischa•12h ago•14 comments

Show HN: Text-to-video model from scratch (2 brothers, 2 years, 2B params)

https://huggingface.co/collections/Linum-AI/linum-v2-2b-text-to-video
67•schopra909•14h ago•13 comments

'Askers' vs. 'Guessers' (2010)

https://www.theatlantic.com/national/2010/05/askers-vs-guessers/340891/
113•BoorishBears•18h ago•75 comments

Composing APIs and CLIs in the LLM era

https://walters.app/blog/composing-apis-clis
49•zerf•13h ago•12 comments

Recent discoveries on the acquisition of the highest levels of human performance

https://www.science.org/doi/abs/10.1126/science.adt7790
121•colincooke•12h ago•56 comments

Stunnel

https://www.stunnel.org/
53•firesteelrain•6h ago•16 comments

'Active' sitting is better for brain health: review of studies

https://www.sciencealert.com/not-all-sitting-is-equal-one-type-was-just-linked-to-better-brain-he...
92•mikhael•11h ago•34 comments

In Europe, wind and solar overtake fossil fuels

https://e360.yale.edu/digest/europe-wind-solar-fossil-fuels
546•speckx•16h ago•553 comments

Show HN: BrowserOS – "Claude Cowork" in the browser

https://github.com/browseros-ai/BrowserOS
54•felarof•14h ago•23 comments

Design Thinking Books (2024)

https://www.designorate.com/design-thinking-books/
276•rrm1977•18h ago•126 comments

Your brain on ChatGPT: Accumulation of cognitive debt when using an AI assistant

https://www.media.mit.edu/publications/your-brain-on-chatgpt/
656•misswaterfairy•1d ago•461 comments

Keeping 20k GPUs healthy

https://modal.com/blog/gpu-health
107•jxmorris12•4d ago•47 comments