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

Comments

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

If AI writes code, should the session be part of the commit?

https://github.com/mandel-macaque/memento
98•mandel_x•5h ago•120 comments

Computer-generated dream world: Virtual reality for a 286 processor

https://deadlime.hu/en/2026/02/22/computer-generated-dream-world/
20•MBCook•1h ago•0 comments

WebMCP is available for early preview

https://developer.chrome.com/blog/webmcp-epp
222•andsoitis•7h ago•130 comments

Everett shuts down Flock camera network after judge rules footage public record

https://www.wltx.com/article/news/nation-world/281-53d8693e-77a4-42ad-86e4-3426a30d25ae
79•aranaur•1h ago•13 comments

Show HN: Timber – Ollama for classical ML models, 336x faster than Python

https://github.com/kossisoroyce/timber
73•kossisoroyce•4h ago•7 comments

Show HN: I built a zero-browser, pure-JS typesetting engine for bit-perfect PDFs

https://github.com/cosmiciron/vmprint
22•cosmiciron•17h ago•8 comments

Frankensqlite a Rust reimplementation of SQLite with concurrent writers

https://frankensqlite.com/
14•rahimnathwani•3d ago•6 comments

Right-sizes LLM models to your system's RAM, CPU, and GPU

https://github.com/AlexsJones/llmfit
59•bilsbie•6h ago•12 comments

Ghostty – Terminal Emulator

https://ghostty.org/docs
677•oli5679•17h ago•297 comments

Tove Jansson's criticized illustrations of The Hobbit (2023)

https://tovejansson.com/hobbit-tolkien/
125•abelanger•2d ago•59 comments

Little Free Library

https://littlefreelibrary.org/
97•TigerUniversity•7h ago•42 comments

Why does C have the best file API

https://maurycyz.com/misc/c_files/
91•maurycyz•10h ago•49 comments

When does MCP make sense vs CLI?

https://ejholmes.github.io/2026/02/28/mcp-is-dead-long-live-the-cli.html
330•ejholmes•12h ago•212 comments

C64 Copy Protection

https://www.commodoregames.net/copyprotection/
30•snvzz•3d ago•1 comments

Decision trees – the unreasonable power of nested decision rules

https://mlu-explain.github.io/decision-tree/
438•mschnell•20h ago•72 comments

What our DNA reveals about the sex life of Neanderthals

https://www.nytimes.com/2026/02/26/science/human-evolution-neanderthal-sex.html
35•Hooke•3d ago•31 comments

Next-gen spacecraft are overwhelming communication networks

https://atempleton.bearblog.dev/how-next-gen-spacecraft-are-overwhelming-our-communication-networks/
48•korrz•2d ago•13 comments

Long Range E-Bike (2021)

https://jacquesmattheij.com/long-range-ebike/
138•birdculture•3d ago•210 comments

Running Neural Amp Modeler on embedded hardware

https://www.tone3000.com/blog/running-nam-on-embedded-hardware
21•woodybury•2d ago•4 comments

Ape Coding [fiction]

https://rsaksida.com/blog/ape-coding/
157•rmsaksida•15h ago•100 comments

Why XML tags are so fundamental to Claude

https://glthr.com/XML-fundamental-to-Claude
182•glth•14h ago•127 comments

Setting up phones is a nightmare

https://joelchrono.xyz/blog/setting-up-phones-is-a-nightmare/
129•bariumbitmap•3d ago•162 comments

Microgpt explained interactively

https://growingswe.com/blog/microgpt
227•growingswe•19h ago•36 comments

Chorba: A novel CRC32 implementation (2024)

https://arxiv.org/abs/2412.16398
56•fnands•2d ago•15 comments

Flightradar24 for Ships

https://atlas.flexport.com/
212•chromy•18h ago•45 comments

You don't have to

https://www.scottsmitelli.com/articles/you-dont-have-to/
37•marginalia_nu•7h ago•26 comments

Microgpt

http://karpathy.github.io/2026/02/12/microgpt/
1754•tambourine_man•1d ago•300 comments

Show HN: Vibe Code your 3D Models

https://github.com/ierror/synaps-cad
35•burrnii•2d ago•10 comments

Show HN: Logira – eBPF runtime auditing for AI agent runs

https://github.com/melonattacker/logira
14•melonattacker•6h ago•1 comments

I built a demo of what AI chat will look like when it's “free” and ad-supported

https://99helpers.com/tools/ad-supported-chat
514•nickk81•17h ago•278 comments