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.

Have a Fucking Website

https://www.otherstrangeness.com/2026/03/14/have-a-fucking-website/
199•asukachikaru•3h ago•93 comments

JPEG Compression

https://www.sophielwang.com/blog/jpeg
25•vinhnx•4d ago•0 comments

SSH has no Host header

https://blog.exe.dev/ssh-host-header
70•apitman•1h ago•46 comments

A Decade of Slug

https://terathon.com/blog/decade-slug.html
539•mwkaufma•12h ago•47 comments

Microsoft's 'unhackable' Xbox One has been hacked by 'Bliss'

https://www.tomshardware.com/video-games/console-gaming/microsofts-unhackable-xbox-one-has-been-h...
628•crtasm•15h ago•220 comments

Ndea (YC W26) is hiring a symbolic RL search guidance lead

https://ndea.com/jobs/search-guidance
1•mikeknoop•11s ago

More than 135 open hardware devices flashable with your own firmware

https://openhardware.directory
160•iosifnicolae2•4d ago•12 comments

Mistral AI Releases Forge

https://mistral.ai/news/forge
288•pember•9h ago•49 comments

Python 3.15's JIT is now back on track

https://fidget-spinner.github.io/posts/jit-on-track.html
342•guidoiaquinti•12h ago•164 comments

Get Shit Done: A meta-prompting, context engineering and spec-driven dev system

https://github.com/gsd-build/get-shit-done
292•stefankuehnel•10h ago•143 comments

Show HN: Sub-millisecond VM sandboxes using CoW memory forking

https://github.com/adammiribyan/zeroboot
122•adammiribyan•17h ago•24 comments

The pleasures of poor product design

https://www.inconspicuous.info/p/the-pleasures-of-poor-product-design
74•NaOH•5h ago•25 comments

A tale about fixing eBPF spinlock issues in the Linux kernel

https://rovarma.com/articles/a-tale-about-fixing-ebpf-spinlock-issues-in-the-linux-kernel/
69•y1n0•6h ago•2 comments

Why AI systems don't learn – On autonomous learning from cognitive science

https://arxiv.org/abs/2603.15381
84•aanet•9h ago•26 comments

Unsloth Studio

https://unsloth.ai/docs/new/studio
250•brainless•15h ago•50 comments

It Took Me 30 Years to Solve This VFX Problem – Green Screen Problem [video]

https://www.youtube.com/watch?v=3Ploi723hg4
219•yincrash•4d ago•93 comments

Electron microscopy shows ‘mouse bite’ defects in semiconductors

https://news.cornell.edu/stories/2026/03/electron-microscopy-shows-mouse-bite-defects-semiconductors
53•hhs•4d ago•10 comments

Launch HN: Kita (YC W26) – Automate credit review in emerging markets

37•rheamalhotra1•11h ago•5 comments

Honda is killing its EVs

https://techcrunch.com/2026/03/14/honda-is-killing-its-evs-and-any-chance-of-competing-in-the-fut...
290•sylvainkalache•2d ago•606 comments

Launch an autonomous AI agent with sandboxed execution in 2 lines of code

https://amaiya.github.io/onprem/examples_agent.html
26•wiseprobe•5h ago•4 comments

I Simulated 38,612 Countryle Games to Find the Best Strategy

https://stoffregen.io/posts/countryle/
12•st0ffregen•1d ago•2 comments

Switzerland Built an Alternative to BGP

https://www.theregister.com/2026/03/17/switzerland_bgp_alternative/
21•jonbaer•1h ago•2 comments

Ryugu asteroid samples contain all DNA and RNA building blocks

https://phys.org/news/2026-03-ryugu-asteroid-samples-dna-rna.html
220•bookofjoe•18h ago•122 comments

Leviathan (1651)

https://www.gutenberg.org/files/3207/3207-h/3207-h.htm
38•mrwh•3d ago•12 comments

Forget Flags and Scripts: Just Rename the File

https://robertsdotpm.github.io/software_engineering/program_names_as_input.html
15•Uptrenda•2h ago•14 comments

Edge.js: Run Node apps inside a WebAssembly sandbox

https://wasmer.io/posts/edgejs-safe-nodejs-using-wasm-sandbox
126•syrusakbary•12h ago•36 comments

Show HN: Fatal Core Dump – A debugging murder mystery played with GDB

https://www.robopenguins.com/fatal_core_dump/
52•axlan•4d ago•1 comments

Robotocore · a Digital Twin of AWS

https://github.com/robotocore/robotocore
14•pkaeding•5h ago•1 comments

Kagi Small Web

https://kagi.com/smallweb/
736•trueduke•21h ago•198 comments

Show HN: I built an interactive 3D three-body problem simulator in the browser

https://structuredlabs.github.io/threebodyproblem/
45•amrutha_•4d ago•16 comments