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.

7.1 Earthquake in Japan

https://www.data.jma.go.jp/multi/quake/quake_detail.html?eventID=20260728163528&lang=en
312•krembo•4h ago•67 comments

About the security content of macOS Tahoe 26.6

https://support.apple.com/en-us/128067
76•andor•2h ago•33 comments

Google's Beyond Zero: Enterprise Security for the AI Era

https://spawn-queue.acm.org/doi/10.1145/3819083
25•jordigg•2h ago•10 comments

Our position on open-weights models

https://www.anthropic.com/news/position-open-weights-models
973•surprisetalk•14h ago•1406 comments

How to Survive Boiling Water

https://taxa.substack.com/p/how-to-survive-boiling-water
69•cainxinth•3d ago•12 comments

A $500 RL fine-tune of a 9B open model beat frontier models on catalog review

https://fermisense.com/when-machines-take-the-wheel/
222•ilreb•9h ago•64 comments

Ars Astronomica – English translations of rare Hebrew and Latin astronomy texts

https://arsastronomica.com/
74•sweisman•6h ago•15 comments

Golang Maps: how Swiss Tables replaced the old bucket design

https://blog.gaborkoos.com/posts/2026-07-24-Golang-Maps-How-Swiss-Tables-Replaced-the-Old-Bucket-...
19•Terretta•3d ago•1 comments

Benchmarking Opus 5 on SlopCodeBench

https://github.com/humanlayer/advanced-context-engineering-for-coding-agents/blob/main/benchmarki...
319•dhorthy•13h ago•73 comments

Vehicle Motion Cues

https://support.apple.com/guide/iphone/iphone-comfortably-riding-a-vehicle-iph55564cb22/ios
138•Austin_Conlon•10h ago•66 comments

Neutrino-1 8B

https://www.fermionresearch.com/models/neutrino-8b/
101•handfuloflight•7h ago•35 comments

Watching Go's new garbage collector move through the heap

https://theconsensus.dev/p/2026/07/19/observing-gos-garbage-collector-old-and-new.html
238•matheusmoreira•3d ago•31 comments

PyTorch: A Reference Language

https://docs.pytorch.org/devlogs/compiler/2026-07-25-pytorch-a-reference-language/
42•matt_d•7h ago•3 comments

TWC Classics

https://twcclassics.com/
17•stefanpie•5d ago•1 comments

Kimi K3 Now Available via Telnyx Inference API

https://telnyx.com/release-notes/kimi-k3-telnyx-inference
99•fionaattelnyx•13h ago•53 comments

Programming Languages Are Authoring Tools for Platforms

https://www.makonea.com/en-US/blog/programming-languages-are-authoring-tools-for-platforms
24•jdw64•3d ago•6 comments

Show HN: Yap – OSS on-device voice dictation for macOS with no model to download

https://github.com/FrigadeHQ/yap
78•pancomplex•17h ago•27 comments

Which Odyssey translation wins a blind reading test?

https://homer.scrivium.com/report/
8•curo•4d ago•3 comments

DConf 2026 in London

https://dconf.org/2026/index.html
104•teleforce•12h ago•46 comments

Launch HN: Rise Reforming (YC S26) – Turning Waste Gases into Valuable Chemicals

https://www.rise-reforming.com
76•george_rose25•16h ago•31 comments

Ray tracing massive amounts of animated geometry using tetrahedral cages

https://gpuopen.com/learn/ray-tracing-massive-amounts-animated-geometry/
113•LorenDB•4d ago•15 comments

RTX 2080 Ti Memory Upgrade to 22 GB

https://gpusolutions.net/rbservices/graphics-card-upgrade/
123•wslh•3d ago•92 comments

Paged Out #9 [pdf]

https://pagedout.institute/download/PagedOut_009.pdf
254•laurensr•21h ago•29 comments

Self-contained highly-portable Python distributions

https://gregoryszorc.com/docs/python-build-standalone/main/
152•jcbhmr•17h ago•32 comments

Some combinatorial applications of spacefilling curves

https://www2.isye.gatech.edu/~jjb/research/mow/mow.html
59•shraiwi•2d ago•9 comments

C/C++ projects packaged for Zig

https://github.com/allyourcodebase
67•jcbhmr•12h ago•35 comments

Securing Services with Rootless Containers

https://blog.coderspirit.xyz/blog/2026/07/06/securing-services-with-rootless-containers/
104•speckx•4d ago•32 comments

A Dying Art: The last of the morticians

https://harpers.org/archive/2026/08/a-dying-art-john-semley-mortuary-sciences-competition/
41•Petiver•4d ago•5 comments

Don't ask an LLM for a confidence score

https://justinflick.com/2026/07/27/llm-confidence-scores.html
46•pamplemeese•11h ago•5 comments

How real are real numbers? (2004)

https://arxiv.org/abs/math/0411418
84•surprisetalk•20h ago•63 comments