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.

Axios compromised on NPM – Malicious versions drop remote access trojan

https://www.stepsecurity.io/blog/axios-compromised-on-npm-malicious-versions-drop-remote-access-t...
335•mtud•2h ago•90 comments

Universal Claude.md – cut Claude output tokens

https://github.com/drona23/claude-token-efficient
222•killme2008•4h ago•79 comments

Artemis II is not safe to fly

https://idlewords.com/2026/03/artemis_ii_is_not_safe_to_fly.htm
147•idlewords•3h ago•68 comments

Ollama is now powered by MLX on Apple Silicon in preview

https://ollama.com/blog/mlx
77•redundantly•2h ago•24 comments

Google's 200M-parameter time-series foundation model with 16k context

https://github.com/google-research/timesfm
7•codepawl•18m ago•1 comments

Fedware: Government apps that spy harder than the apps they ban

https://www.sambent.com/the-white-house-app-has-huawei-spyware-and-an-ice-tip-line/
504•speckx•11h ago•161 comments

Do your own writing

https://alexhwoods.com/dont-let-ai-write-for-you/
450•karimf•17h ago•162 comments

Android Developer Verification

https://android-developers.googleblog.com/2026/03/android-developer-verification-rolling-out-to-a...
197•ingve•7h ago•180 comments

Clojure: The Documentary, official trailer [video]

https://www.youtube.com/watch?v=JJEyffSdBsk
103•fogus•4d ago•5 comments

Turning a MacBook into a touchscreen with $1 of hardware (2018)

https://anishathalye.com/macbook-touchscreen/
263•HughParry•10h ago•116 comments

How to turn anything into a router

https://nbailey.ca/post/router/
640•yabones•16h ago•223 comments

Safeguarding cryptocurrency by disclosing quantum vulnerabilities responsibly

https://research.google/blog/safeguarding-cryptocurrency-by-disclosing-quantum-vulnerabilities-re...
22•madars•2h ago•2 comments

Incident March 30th, 2026 – Accidental CDN Caching

https://blog.railway.com/p/incident-report-march-30-2026-accidental-cdn-caching
41•cebert•4h ago•13 comments

Mr. Chatterbox is a Victorian-era ethically trained model

https://simonwillison.net/2026/Mar/30/mr-chatterbox/
16•y1n0•3h ago•2 comments

Show HN: I turned a sketch into a 3D-print pegboard for my kid with an AI agent

https://github.com/virpo/pegboard
29•virpo•6h ago•5 comments

Bird brains (2023)

https://www.dhanishsemar.com/writing/bird-brains
308•DiffTheEnder•16h ago•195 comments

Rock Star: Reading the Rosetta Stone

https://www.historytoday.com/archive/feature/original-rock-star
5•samizdis•2d ago•0 comments

OpenGridWorks: The Electricity Infrasctructure, Mapped

https://www.opengridworks.com
81•jonbraun•8h ago•8 comments

Show HN: Will AI take my job

https://aijobsreport.org/quiz
7•galuggus•1h ago•6 comments

Unit: A self-replicating Forth mesh agent running in a browser tab

https://davidcanhelp.github.io/unit/
22•DavidCanHelp•4d ago•1 comments

Agents of Chaos

https://agentsofchaos.baulab.info/report.html
91•luu•3d ago•10 comments

Cherri – programming language that compiles to an Apple Shortuct

https://github.com/electrikmilk/cherri
287•mihau•3d ago•57 comments

Researchers find 3,500-year-old loom that reveals textile revolution

https://web.ua.es/en/actualidad-universitaria/2026/marzo2026/23-31/ua-researchers-find-3-500-year...
95•geox•3d ago•9 comments

CodingFont: A game to help you pick a coding font

https://www.codingfont.com/
368•nvahalik•14h ago•191 comments

Vulnerability research is cooked

https://sockpuppet.org/blog/2026/03/30/vulnerability-research-is-cooked/
142•pedro84•10h ago•101 comments

R3 Bio pitched “brainless clones” to serve the role of backup human bodies

https://www.technologyreview.com/2026/03/30/1134780/r3-bio-brainless-human-clones-full-body-repla...
46•joozio•18h ago•57 comments

Seeing like a spreadsheet

https://davidoks.blog/p/how-the-spreadsheet-reshaped-america
98•paulpauper•2d ago•34 comments

Sony halts memory card shipments due to NAND shortage

https://www.techzine.eu/news/devices/140058/sony-halts-memory-card-shipments-due-to-nand-shortage/
5•methuselah_in•28m ago•0 comments

Learn Claude Code by doing, not reading

https://claude.nagdy.me/
215•taubek•9h ago•98 comments

William Blake, Remote by the Sea

https://www.laphamsquarterly.org/roundtable/william-blake-remote-sea
72•occurrence•10h ago•4 comments