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.

Personal blogs are back, should niche blogs be next?

https://disassociated.com/personal-blogs-back-niche-blogs-next/
150•gnabgib•5h ago•105 comments

Arduino Terms of Service and Privacy Policy update: setting the record straight

https://blog.arduino.cc/2025/11/21/the-arduino-terms-of-service-and-privacy-policy-update-setting...
27•manchoz•6h ago•7 comments

Samsung's 60% DRAM price hike signals a new phase of global memory tightening

https://www.buysellram.com/blog/samsungs-memory-price-surge-sends-shockwaves-through-the-global-d...
193•redohmy•1w ago•143 comments

Helping Valve to power up Steam devices

https://www.igalia.com/2025/11/helpingvalve.html
474•TingPing•10h ago•150 comments

Show HN: Wealthfolio 2.0- Open source investment tracker. Now Mobile and Docker

https://wealthfolio.app/?v=2.0
457•a-fadil•11h ago•159 comments

Apple's Problem with Bodies

https://drobinin.com/posts/apples-problem-with-bodies/
8•valzevul•4h ago•0 comments

Moss Survives 9 Months in Space Vacuum

https://scienceclock.com/moss-survives-9-months-in-space-vacuum/
4•ashishgupta2209•13m ago•0 comments

Childhood Friends, Not Moms, Shape Attachment Styles Most

https://nautil.us/childhood-friends-not-moms-shape-attachment-styles-most-1247316/
146•dnetesn•1w ago•48 comments

LAPD helicopter tracker with real-time operating costs

https://lapdhelicoptertracker.com/
112•polalavik•5h ago•126 comments

How I learned Vulkan and wrote a small game engine with it (2024)

https://edw.is/learning-vulkan/
43•jakogut•4h ago•18 comments

Self-hosting a NAT Gateway

https://www.awsistoohard.com/blog/self-hosting-nat-gateway
81•veryrealsid•4d ago•51 comments

Pixar: The Early Days A never-before-seen 1996 interview

https://stevejobsarchive.com/stories/pixar-early-days
91•sanj•7h ago•7 comments

Sharper MRI scans may be on horizon thanks to new physics-based model

https://news.rice.edu/news/2025/sharper-mri-scans-may-be-horizon-thanks-new-physics-based-model
23•hhs•3h ago•3 comments

We should all be using dependency cooldowns

https://blog.yossarian.net/2025/11/21/We-should-all-be-using-dependency-cooldowns
306•todsacerdoti•13h ago•196 comments

Discontinuation of ARM Notebook with Snapdragon X Elite SoC

https://www.tuxedocomputers.com/en/Discontinuation-of-ARM-notebooks-with-Snapdragon-X-Elite-SoC.t...
97•Venn1•8h ago•28 comments

You can make PS2 games in JavaScript

https://jslegenddev.substack.com/p/you-can-now-make-ps2-games-in-javascript
244•tosh•11h ago•58 comments

Infinibay LXD Container

https://github.com/Infinibay/lxd
7•angaroshi•2h ago•0 comments

The death of tech idealism and rise of the homeless in Northern California

https://lithub.com/on-the-death-of-tech-idealism-and-rise-of-the-homeless-in-northern-california/
64•pseudolus•1h ago•16 comments

Is Matrix Multiplication Ugly?

https://mathenchant.wordpress.com/2025/11/21/is-matrix-multiplication-ugly/
51•jamespropp•5h ago•28 comments

Prozac 'no better than placebo' for treating children with depression, experts

https://www.theguardian.com/society/2025/nov/20/prozac-no-better-than-placebo-for-treating-childr...
228•pseudolus•1d ago•341 comments

The Strange Afterlife of Hilma af Klint, Painting’s Posthumous Star

https://www.newyorker.com/magazine/2025/11/24/the-strange-afterlife-of-hilma-af-klint-paintings-p...
19•FinnLobsien•4d ago•1 comments

Building a Durable Execution Engine with SQLite

https://www.morling.dev/blog/building-durable-execution-engine-with-sqlite/
120•ingve•1d ago•39 comments

3D printing with unconventional vase mode

https://vorpal.se/posts/2025/jun/23/3d-printing-with-unconventional-vase-mode/
27•dgroshev•5h ago•6 comments

Shop Sans is a typeface for curved text paths

https://www.futurefonts.com/hex/shop-sans
127•tobr•1w ago•34 comments

When functions dissolve (2020)

https://rubber-duck-typing.com/posts/2020-12-12-when-functions-dissolve.html
6•vitalnodo•6d ago•0 comments

Make product worse, get money

https://dynomight.net/worse/
66•zdw•12h ago•62 comments

RRules (yes handling RSCALE) using only PL/pgSQL

https://github.com/sirrodgepodge/rrule_plpgsql
16•sirrodgepodge•1w ago•1 comments

Pivot Robotics (YC W24) Is Hiring for an Industrial Automation Hardware Engineer

https://www.ycombinator.com/companies/pivot-robotics/jobs/7xG9Dc6-mechanical-engineer-controls
1•vigneshrajmohan•11h ago

Olmo 3: Charting a path through the model flow to lead open-source AI

https://allenai.org/blog/olmo3
368•mseri•21h ago•120 comments

Solving Fizz Buzz with Cosines

https://susam.net/fizz-buzz-with-cosines.html
128•hprotagonist•10h ago•37 comments