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.

Ghostty's AI Policy

https://github.com/ghostty-org/ghostty/blob/main/AI_POLICY.md
48•mefengl•1h ago•20 comments

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

https://www.youtube.com/watch?v=moBCOEiqiPs
184•codetheweb•5h ago•47 comments

AI Is a Horse (2024)

https://kconner.com/2024/08/02/ai-is-a-horse.html
48•zdw•3d ago•24 comments

Replacing Protobuf with Rust to go 5 times faster

https://pgdog.dev/blog/replace-protobuf-with-rust
34•whiteros_e•2h ago•25 comments

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

https://cannoneyed.com/isometric-nyc/
972•cannoneyed•18h ago•189 comments

GPTZero finds 100 new hallucinations in NeurIPS 2025 accepted papers

https://gptzero.me/news/neurips/
852•segmenta•20h ago•446 comments

Proton Spam and the AI Consent Problem

https://dbushell.com/2026/01/22/proton-spam/
210•dbushell•4h ago•120 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...
307•personjerry•14h ago•235 comments

Why does SSH send 100 packets per keystroke?

https://eieio.games/blog/ssh-sends-100-packets-per-keystroke/
496•eieio•16h ago•267 comments

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

https://hugodaniel.com/posts/claude-code-banned-me/
560•hugodan•16h ago•490 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/
40•ibobev•4d ago•17 comments

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

https://qwen.ai/blog?id=qwen3tts-0115
618•Palmik•21h ago•192 comments

Google is ending full-web search for niche search engines

https://programmablesearchengine.googleblog.com/
92•01jonny01•1h ago•70 comments

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

https://shreevatsa.net/post/douglas-adams-cultural-divide/
454•speckx•21h ago•454 comments

The State of Modern AI Text to Speech Systems for Screen Reader Users

https://stuff.interfree.ca/2026/01/05/ai-tts-for-screenreaders.html
5•tuukkao•2h ago•1 comments

Our collective obsession with boredom: Interview with a boredom lab researcher

https://nautil.us/why-the-do-nothing-challenge-doesnt-do-much-for-you-1262005/
7•akakievich•3d ago•1 comments

Your app subscription is now my weekend project

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

Bugs Apple Loves

https://www.bugsappleloves.com
672•nhod•9h ago•299 comments

Scaling PostgreSQL to power 800M ChatGPT users

https://openai.com/index/scaling-postgresql/
201•mustaphah•14h ago•90 comments

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

https://www.leidenmedievalistsblog.nl/articles/why-medieval-city-builder-video-games-are-historic...
151•benbreen•11h ago•91 comments

Improving the usability of C libraries in Swift

https://www.swift.org/blog/improving-usability-of-c-libraries-in-swift/
118•timsneath•11h ago•13 comments

Writing First, Tooling Second

https://susam.net/writing-first-tooling-second.html
35•blenderob•4d ago•4 comments

'Askers' vs. 'Guessers' (2010)

https://www.theatlantic.com/national/2010/05/askers-vs-guessers/340891/
153•BoorishBears•23h ago•102 comments

Stunnel

https://www.stunnel.org/
84•firesteelrain•10h ago•28 comments

CSS Optical Illusions

https://alvaromontoro.com/blog/68091/css-optical-illusions
188•ulrischa•17h ago•16 comments

Project Mercury and the Sofar Bomb

https://www.thequantumcat.space/p/project-mercury-and-the-sofar-bomb
9•verzali•4d ago•0 comments

In Europe, wind and solar overtake fossil fuels

https://e360.yale.edu/digest/europe-wind-solar-fossil-fuels
639•speckx•21h ago•642 comments

Show HN: Txt2plotter – True centerline vectors from Flux.2 for pen plotters

https://github.com/malvarezcastillo/txt2plotter
20•tsanummy•3d ago•5 comments

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

40•kmajid•18h ago•15 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...
113•mikhael•16h ago•42 comments