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•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.

I Don't Want My Search Engine to Think for Me

https://searchzee.com/blog/search-without-ai-summaries
57•rajkverma123•2h ago•49 comments

Use your Nvidia GPU's VRAM as swap space on Linux

https://github.com/c0dejedi/nbd-vram
144•tanelpoder•3h ago•43 comments

MAI-Code-1-Flash

https://microsoft.ai/news/introducingmai-code-1-flash/
396•EvanZhouDev•7h ago•178 comments

CT scans of BYD car parts

https://www.lumafield.com/scan-of-the-month/byd
242•viasfo•6h ago•92 comments

Are blue zones real? Answering that question is harder then ever

https://www.statnews.com/2026/05/04/are-blue-zones-real-new-scrutiny-longevity-hot-spots/
28•mfld•1d ago•15 comments

Gmail thinks I'm stupid, so I left

https://moddedbear.com/gmail-thinks-im-stupid-so-i-left
646•speckx•7h ago•400 comments

My thoughts after using Clojure for about a month

https://www.acdw.net/clojure/
115•speckx•6h ago•71 comments

AI outperforms law professors in Stanford Law study

https://law.stanford.edu/press/ai-outperforms-law-professors-in-stanford-law-study/
104•berlianta•2h ago•102 comments

4K years ago, Mohenjo-daro grew more equal over time

https://archaeologymag.com/2026/05/mohenjo-daro-grew-more-equal-over-time/
47•marojejian•4h ago•23 comments

A walking tour of surveillance infrastructure in Seattle (2020)

https://coveillance.org/a-walking-tour-of-surveillance-infrastructure-in-seattle/
378•eustoria•13h ago•251 comments

HP re-releases classic computer science calculator: The HP-16C

https://hpcalcs.com/product/hp-16c-collectors-edition/
127•dm319•7h ago•79 comments

Open Repair Data Standard – Open Repair Alliance

https://openrepair.org/open-data/open-standard/
99•cassepipe•7h ago•3 comments

LLMs are not the black box you were promised

https://www.jay.ai/blog/llms-are-not-a-black-box
48•_jayhack_•3h ago•28 comments

More than 6 out of 10 people turn to AI for psychological support

https://www.axa.com/en/press/press-releases/2026-mind-health-report
58•mgh2•2h ago•47 comments

How we index images for RAG

https://www.kapa.ai/blog/how-we-index-images-for-rag
92•mooreds•10h ago•14 comments

Pluto.jl 1.0 release – reactive notebook for Julia

https://discourse.julialang.org/t/pluto-1-0-release/137296
14•fons-p•3h ago•0 comments

Trump signs downsized AI order after weeks of reversals

https://www.politico.com/news/2026/06/02/trump-signs-downsized-ai-order-00946389
178•_alternator_•9h ago•127 comments

OpenFOV – Webcam head tracking for iRacing

https://www.openfov.com/
90•mwit2023•3d ago•50 comments

Roku LT Operating System open source distribution

https://blog.roku.com/developer/roku-lt-os
7•dpmdpm•1h ago•3 comments

Multicore suppport for DOS is real – partly

https://www.vogons.org/viewtopic.php?t=111336
62•beebix•2d ago•10 comments

Love systemd timers

https://blog.tjll.net/you-dont-love-systemd-timers-enough/
354•yacin•17h ago•229 comments

Expanding Project Glasswing

https://www.anthropic.com/news/expanding-project-glasswing
160•surprisetalk•13h ago•211 comments

Preparing for KDE Plasma's Last X11-Supported Release

https://blog.davidedmundson.co.uk/blog/596/
149•jandeboevrie•12h ago•183 comments

Fidonet: Technology, Use, Tools, and History (1993)

https://www.fidonet.org/inet92_Randy_Bush.txt
150•BruceEel•12h ago•63 comments

The advertising cartel coming to your web browser

https://blog.zgp.org/the-advertising-cartel-coming-to-your-web-browser/
137•speckx•6h ago•39 comments

QBE – Compiler Backend – 1.3

https://c9x.me/compile/release/qbe-1.3.html
80•birdculture•9h ago•28 comments

Loading Sega Games Off a Vinyl Record [video]

https://www.youtube.com/watch?v=c744iD0_fWU
8•zdw•2d ago•0 comments

Gleam v1.17.0

https://gleam.run/news/single-file-gleam-beam-programs-with-escript/
97•figbert•4h ago•7 comments

Bringing Up DeepSeek-V4-Flash on AMD MI300X

https://fergusfinn.com/blog/deepseek-v4-flash-mi300x/
82•kkm•8h ago•7 comments

Show HN: Paseo – Beautiful open-source coding agent interface

https://github.com/getpaseo/paseo
25•timhigins•4h ago•13 comments