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

Comments

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

Is BGP Safe Yet? No. Test Your ISP

https://isbgpsafeyet.com/
131•janandonly•2h ago•50 comments

Claude Code Unpacked : A visual guide

https://ccunpacked.dev/
844•autocracy101•10h ago•306 comments

CERN levels up with new superconducting karts

https://home.cern/news/news/engineering/cern-levels-new-superconducting-karts
288•fnands•8h ago•60 comments

Consider the Greenland Shark (2020)

https://www.lrb.co.uk/the-paper/v42/n09/katherine-rundell/consider-the-greenland-shark
43•mooreds•5d ago•8 comments

Intuiting Pratt Parsing

https://louis.co.nz/2026/03/26/pratt-parsing.html
92•signa11•2d ago•25 comments

Show HN: CLI to order groceries via reverse-engineered REWE API (Haskell)

https://github.com/yannick-cw/korb
161•wazHFsRy•2d ago•59 comments

Claude Wrote a Full FreeBSD Remote Kernel RCE with Root Shell (CVE-2026-4747)

https://github.com/califio/publications/blob/main/MADBugs/CVE-2026-4747/write-up.md
159•ishqdehlvi•10h ago•60 comments

Ada and Spark on ARM Cortex-M – A Tutorial with Arduino and Nucleo Examples

http://inspirel.com/articles/Ada_On_Cortex.html
14•swq115•4d ago•1 comments

Show HN: Sycamore – next gen Rust web UI library using fine-grained reactivity

https://sycamore.dev
61•lukechu10•3h ago•43 comments

Chess in SQL

https://www.dbpro.app/blog/chess-in-pure-sql
130•upmostly•3d ago•25 comments

New Patches Allow Building Linux IPv6-Only, Option to Deprecate "Legacy" IPv4

https://www.phoronix.com/news/Linux-IPv6-IPv4-Legacy-Knobs
64•Bender•2h ago•33 comments

A dot a day keeps the clutter away

https://scottlawsonbc.com/post/dot-system
448•scottlawson•18h ago•132 comments

Wasmer (YC S19) Is Hiring – Rust and DevRel Positions

https://www.workatastartup.com/companies/wasmer
1•syrusakbary•3h ago

OnlyOffice kills Nextcloud partnership for forking its project without approval

https://www.neowin.net/news/onlyoffice-suspends-nextcloud-partnership-over-unapproved-euro-office...
30•bundie•1h ago•15 comments

Show HN: 1-Bit Bonsai, the First Commercially Viable 1-Bit LLMs

https://prismml.com/
340•PrismML•18h ago•134 comments

TinyLoRA – Learning to Reason in 13 Parameters

https://arxiv.org/abs/2602.04118
216•sorenjan•5d ago•39 comments

I Quit. The Clankers Won

https://dbushell.com/2026/04/01/i-quit-the-clankers-won/
305•domysee•6h ago•316 comments

TruffleRuby

https://chrisseaton.com/truffleruby/
169•tosh•3d ago•22 comments

AI has suddenly become more useful to open-source developers

https://www.zdnet.com/article/maybe-open-source-needs-ai/
23•CrankyBear•1h ago•10 comments

MiniStack (replacement for LocalStack)

https://ministack.org/
280•kerblang•19h ago•56 comments

Tom Scott is back on YouTube [video]

https://www.youtube.com/watch?v=Yz3lSKgz4q8
6•latexr•12m ago•1 comments

The Claude Code Source Leak: fake tools, frustration regexes, undercover mode

https://alex000kim.com/posts/2026-03-31-claude-code-source-leak/
1303•alex000kim•1d ago•531 comments

Neanderthals survived on a knife's edge for 350k years

https://www.science.org/content/article/neanderthals-survived-knife-s-edge-350-000-years
207•Hooke•14h ago•155 comments

Bring Back MiniDV with This Raspberry Pi FireWire Hat

https://www.jeffgeerling.com/blog/2026/minidv-with-raspberry-pi-firewire-hat/
96•ingve•3d ago•17 comments

OpenAI demand sinks on secondary market as Anthropic runs hot

https://www.bloomberg.com/news/articles/2026-04-01/openai-demand-sinks-on-secondary-market-as-ant...
93•helsinkiandrew•1h ago•33 comments

4D Doom

https://github.com/danieldugas/HYPERHELL
255•chronolitus•4d ago•64 comments

Slop is not necessarily the future

https://www.greptile.com/blog/ai-slopware-future
285•dakshgupta•1d ago•459 comments

Show HN: Baton – A desktop app for developing with AI agents

https://getbaton.dev/
52•tordrt•3h ago•41 comments

The Document Foundation ejects its core developers

https://www.collaboraonline.com/blog/tdf-ejects-its-core-developers/
20•hackernewsblues•4h ago•4 comments

OpenAI closes funding round at an $852B valuation

https://www.cnbc.com/2026/03/31/openai-funding-round-ipo.html
495•surprisetalk•19h ago•457 comments