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

Comments

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

Adversarial Poetry as a Universal Single-Turn Jailbreak Mechanism in LLMs

https://arxiv.org/abs/2511.15304
72•capgre•2h ago•45 comments

Interactive World History Atlas Since 3000 BC

http://geacron.com/home-en/
137•not_knuth•4h ago•81 comments

Red Alert 2 in web browser

https://chronodivide.com/
37•nsoonhui•2h ago•10 comments

Show HN: Awesome J2ME

https://github.com/hstsethi/awesome-j2me
49•catstor•3h ago•26 comments

40 years ago, Calvin and Hobbes' burst onto the page

https://www.npr.org/2025/11/18/nx-s1-5564064/calvin-and-hobbes-bill-watterson-40-years-comic-stri...
114•mooreds•2h ago•27 comments

Android/Linux Dual Boot

https://wiki.postmarketos.org/wiki/Dual_Booting/WiP
165•joooscha•3d ago•95 comments

CUDA Ontology

https://jamesakl.com/posts/cuda-ontology/
155•gugagore•3d ago•20 comments

Basalt Woven Textile

https://materialdistrict.com/material/basalt-woven-textile/
148•rbanffy•8h ago•69 comments

Towards Interplanetary QUIC Traffic

https://ochagavia.nl/blog/towards-interplanetary-quic-traffic/
44•wofo•2d ago•10 comments

Students fight back over course taught by AI

https://www.theguardian.com/education/2025/nov/20/university-of-staffordshire-course-taught-in-la...
33•level87•1h ago•13 comments

Europe is scaling back GDPR and relaxing AI laws

https://www.theverge.com/news/823750/european-union-ai-act-gdpr-changes
835•ksec•23h ago•946 comments

Meta Segment Anything Model 3

https://ai.meta.com/sam3/
557•lukeinator42•21h ago•111 comments

Loose wire leads to blackout, contact with Francis Scott Key bridge

https://www.ntsb.gov:443/news/press-releases/Pages/NR20251118.aspx
380•DamnInteresting•18h ago•168 comments

The lost cause of the Lisp machines

https://www.tfeb.org/fragments/2025/11/18/the-lost-cause-of-the-lisp-machines/
100•enbywithunix•18h ago•99 comments

Scientists Reveal How the Maya Predicted Eclipses for Centuries

https://www.sciencealert.com/scientists-reveal-how-the-maya-predicted-eclipses-for-centuries
34•rguiscard•6d ago•8 comments

DOS Days – Laptop Displays

https://www.dosdays.co.uk/topics/laptop_displays.php
35•nullbyte808•5h ago•7 comments

Researchers discover security vulnerability in WhatsApp

https://www.univie.ac.at/en/news/detail/forscherinnen-entdecken-grosse-sicherheitsluecke-in-whatsapp
273•KingNoLimit•17h ago•101 comments

Verifying your Matrix devices is becoming mandatory

https://element.io/blog/verifying-your-devices-is-becoming-mandatory-2/
158•LorenDB•14h ago•175 comments

New Proofs Probe Soap-Film Singularities

https://www.quantamagazine.org/new-proofs-probe-soap-film-singularities-20251112/
25•pseudolus•1w ago•0 comments

Wrapping my head around AI wrappers

https://www.wreflection.com/p/wrapping-my-head-around-ai-wrappers
17•nowflux•4d ago•8 comments

Building more with GPT-5.1-Codex-Max

https://openai.com/index/gpt-5-1-codex-max/
442•hansonw•20h ago•268 comments

Precise geolocation via Wi-Fi Positioning System

https://www.amoses.dev/blog/wifi-location/
207•nicosalm•16h ago•78 comments

A surprise with how '#!' handles its program argument in practice

https://utcc.utoronto.ca/~cks/space/blog/unix/ShebangRelativePathSurprise
70•SeenNotHeard•1d ago•56 comments

Details about the shebang/hash-bang mechanism on various Unix flavours (2001)

https://www.in-ulm.de/%7Emascheck/various/shebang/
54•js2•9h ago•13 comments

Show HN: I made a fireplace for your wrist (and widgets)

11•kingofspain•6d ago•7 comments

What really happened with the CIA and The Paris Review?

https://www.theparisreview.org/blog/2025/11/11/what-really-happened-with-the-cia-and-the-paris-re...
81•frenzcan•1w ago•10 comments

PHP 8.5

https://stitcher.io/blog/new-in-php-85
177•brentroose•8h ago•114 comments

Launch HN: Mosaic (YC W25) – Agentic Video Editing

https://mosaic.so
130•adishj•23h ago•121 comments

CLI tool to check the Git status of multiple projects

https://github.com/uralys/check-projects
48•chrisdugne•6d ago•28 comments

How Slide Rules Work

https://amenzwa.github.io/stem/ComputingHistory/HowSlideRulesWork/
143•ColinWright•17h ago•38 comments