frontpage.
newsnewestaskshowjobs

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.

JSON-LD Explained for Personal Websites

https://hawksley.dev/blog/json-ld-explained-for-personal-websites/
54•ethanhawksley•1h ago•12 comments

Prefer duplication over the wrong abstraction (2016)

https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction
329•rafaepta•4h ago•233 comments

Beyond All Reason (Free Total Annihilation Inspired RTS)

https://www.beyondallreason.info
359•mosiuerbarso•8h ago•206 comments

(How to Write a (Lisp) Interpreter (In Python)) (2010)

https://norvig.com/lispy.html
124•tosh•4h ago•37 comments

Identity verification on Claude

https://support.claude.com/en/articles/14328960-identity-verification-on-claude
314•bathory•7h ago•269 comments

The minimum viable unit of saleable software

https://brandur.org/minimum-viable-unit
64•brandur•3h ago•32 comments

Show HN: CleverCrow: give tokens to your favorite projects

https://clevercrow.io
12•zhubert•1h ago•4 comments

An Embedded Linux on a Single Floppy

https://github.com/w84death/floppinux
26•modinfo•2d ago•13 comments

Occupancy Math on the AMD MI355X: A From-First-Principles Guide

https://indianspeedster.github.io/blog/occupancy-math-mi355x/
28•skidrow•4d ago•0 comments

A 3D voxel game engine written in APL

https://github.com/namgyaaal/avoxelgame
131•sph•12h ago•11 comments

15-minute at-home Lyme disease tick test

https://www.bostonglobe.com/2026/06/17/business/lyme-disease-tick-test/
207•bookofjoe•3d ago•143 comments

Wildcard (YC W25) is hiring an applied ML engineer

https://www.ycombinator.com/companies/wildcard/jobs/SEmo4di-founding-applied-ml-engineer
1•kaushikmahorker•3h ago

Loupe – A iOS app that raises awareness about what native apps can see

https://github.com/mysk-research/loupe
485•Cider9986•1d ago•199 comments

Developers don't understand CORS (2019)

https://fosterelli.co/developers-dont-understand-cors
321•toilet•18h ago•246 comments

System call instrumentation on Linux/x86‑64 using memory‑indirect calls, part I

https://www.humprog.org/~stephen/blog/2026/06/15/#system-call-instrumentation-on-intel-negative-r...
32•matt_d•4d ago•12 comments

Running MicroVMs in Proxmox VE, the Easy Way

https://taoofmac.com/space/blog/2026/06/18/1845
188•zdw•2d ago•31 comments

Show HN: Pulse – Dashboard for Claude Code, approve tool calls from your phone

https://github.com/nikitadoudikov/claude-pulse
22•nikitadvd•23h ago•9 comments

Show HN: TownSquare, a tiny presence layer for websites

https://townsquare.cauenapier.com/
227•cauenapier•1d ago•132 comments

Burnout is real for open source maintainers

https://openjsf.org/blog/burnout-is-real-for-open-source-maintainers
91•theanonymousone•3h ago•42 comments

Proportional-Integral-Derivative (PID) controllers

https://en.wikipedia.org/wiki/PID_controller
72•dhorthy•2d ago•45 comments

Slow breathing modulates brain function and risk behavior

https://www.cell.com/neuron/fulltext/S0896-6273(26)00339-9
349•croes•21h ago•99 comments

Excessive nil pointer checks in Go

https://konradreiche.com/blog/excessive-nil-pointer-checks-in-go/
78•ingve•3d ago•59 comments

Fossil Fuels Are 40% of Freight Shipping Tonnage, but Half Its Fuel Use

https://cleantechnica.com/2026/06/16/shipping-freight-energy-fossil-cargo/
109•choult•5h ago•77 comments

Cocktail Optimization, an Integer Programming Problem

https://bunkum.us/2026/06/18/cocktail-ingredients-milp
9•ftgregg•2d ago•2 comments

Renting a sewing machine from the library

https://www.bbc.com/future/article/20260618-the-weird-and-wonderful-libraries-of-finland
324•sohkamyung•21h ago•187 comments

The Commodore Callback 8020 smart flip phone

https://www.wired.me/story/commodore-made-a-digital-detox-phone-that-isnt-dumb
103•Audiophilip•3d ago•89 comments

Two Qwen3 models on one DGX Spark: the residency math

https://www.devashish.me/p/two-qwen3-models-on-one-dgx-spark
77•devashish86•3d ago•36 comments

The brain was not designed for this much bad news

https://www.sciencedaily.com/releases/2026/06/260614012006.htm
321•colinprince•16h ago•269 comments

The early hiring funnel is now breaking on both ends

https://hbr.org/2026/06/ai-has-broken-hiring-heres-how-to-fix-it
77•ChrisArchitect•4h ago•128 comments

Epoll vs. io_uring in Linux

https://sibexi.co/posts/epoll-vs-io_uring/
243•Sibexico•21h ago•57 comments