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
126•mefengl•2h ago•60 comments

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

https://www.youtube.com/watch?v=moBCOEiqiPs
220•codetheweb•6h ago•52 comments

AI Is a Horse (2024)

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

Replacing Protobuf with Rust to go 5 times faster

https://pgdog.dev/blog/replace-protobuf-with-rust
48•whiteros_e•3h ago•32 comments

Proton Spam and the AI Consent Problem

https://dbushell.com/2026/01/22/proton-spam/
232•dbushell•5h ago•128 comments

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

https://cannoneyed.com/isometric-nyc/
998•cannoneyed•19h ago•190 comments

GPTZero finds 100 new hallucinations in NeurIPS 2025 accepted papers

https://gptzero.me/news/neurips/
858•segmenta•20h ago•455 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...
310•personjerry•14h ago•244 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
12•tuukkao•2h ago•1 comments

Why does SSH send 100 packets per keystroke?

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

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

https://hugodaniel.com/posts/claude-code-banned-me/
572•hugodan•17h ago•515 comments

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

https://qwen.ai/blog?id=qwen3tts-0115
628•Palmik•22h ago•197 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/
43•ibobev•4d ago•20 comments

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

https://shreevatsa.net/post/douglas-adams-cultural-divide/
466•speckx•22h ago•468 comments

Your app subscription is now my weekend project

https://rselbach.com/your-sub-is-now-my-weekend-project
393•robteix•4d ago•285 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/
9•akakievich•3d ago•3 comments

Bugs Apple Loves

https://www.bugsappleloves.com
705•nhod•9h ago•312 comments

Scaling PostgreSQL to power 800M ChatGPT users

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

Show HN: AskUCP – UCP protocol explorer showing all products on Shopify

https://askucp.com/
3•possiblelion•4d ago•0 comments

Improving the usability of C libraries in Swift

https://www.swift.org/blog/improving-usability-of-c-libraries-in-swift/
120•timsneath•12h ago•15 comments

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

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

Project Mercury and the Sofar Bomb

https://www.thequantumcat.space/p/project-mercury-and-the-sofar-bomb
11•verzali•5d ago•2 comments

Writing First, Tooling Second

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

Google is ending full-web search for niche search engines

https://programmablesearchengine.googleblog.com/
110•01jonny01•2h ago•86 comments

'Askers' vs. 'Guessers' (2010)

https://www.theatlantic.com/national/2010/05/askers-vs-guessers/340891/
159•BoorishBears•1d ago•106 comments

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

https://github.com/malvarezcastillo/txt2plotter
26•tsanummy•3d ago•7 comments

CSS Optical Illusions

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

Stunnel

https://www.stunnel.org/
90•firesteelrain•11h ago•31 comments

In Europe, wind and solar overtake fossil fuels

https://e360.yale.edu/digest/europe-wind-solar-fossil-fuels
650•speckx•22h ago•665 comments

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

40•kmajid•19h ago•15 comments