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

Comments

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

Ada, Its Design, and the Language That Built the Languages

https://www.iqiipi.com/the-quiet-colossus.html
119•mpweiher•3h ago•58 comments

Claude Opus 4.7

https://www.anthropic.com/news/claude-opus-4-7
1815•meetpateltech•22h ago•1306 comments

FIM – Linux framebuffer image viewer

https://www.nongnu.org/fbi-improved/
80•Mr_Minderbinder•5h ago•38 comments

Codex for almost everything

https://openai.com/index/codex-for-almost-everything/
913•mikeevans•19h ago•474 comments

Average Is All You Need

https://rawquery.dev/blog/average-is-all-you-need
20•AlexC04•3d ago•2 comments

CadQuery is an open-source Python library for building 3D CAD models

https://cadquery.github.io/
167•gregsadetsky•2d ago•43 comments

A Python Interpreter Written in Python

https://aosabook.org/en/500L/a-python-interpreter-written-in-python.html
83•xk3•3d ago•23 comments

中文 Literacy Speedrun II: Character Cyclotron

https://blog.kevinzwu.com/character-cyclotron/
29•surprisetalk•4d ago•12 comments

30 Years of HPC: many hardware advances, little adoption of new languages

https://chapel-lang.org/blog/posts/30years/
71•matt_d•3d ago•35 comments

How Silicon Valley Is Turning Scientists into Exploited Gig Workers

https://www.thenation.com/article/society/ai-silicon-valley-andreesen-thiel-stem/
19•ZunarJ5•1h ago•5 comments

Show HN: SPICE simulation → oscilloscope → verification with Claude Code

https://lucasgerads.com/blog/lecroy-mcp-spice-demo/
94•_fizz_buzz_•11h ago•19 comments

Human Accelerated Region 1

https://en.wikipedia.org/wiki/Human_accelerated_region_1
66•apollinaire•8h ago•31 comments

Official Clojure Documentary page with Video, Shownotes, and Links

https://clojure.org/about/documentary
247•adityaathalye•16h ago•65 comments

Android CLI: Build Android apps 3x faster using any agent

https://android-developers.googleblog.com/2026/04/build-android-apps-3x-faster-using-any-agent.html
259•ingve•17h ago•102 comments

Guy builds AI driven hardware hacker arm from duct tape, old cam and CNC machine

https://github.com/gainsec/autoprober
198•scaredpelican•14h ago•40 comments

Playdate’s handheld changed how Duke University teaches game design

https://news.play.date/news/duke-playdate-education/
180•Ivoah•17h ago•84 comments

How Big Tech wrote secrecy into EU law to hide data centres' environmental toll

https://www.investigate-europe.eu/posts/big-tech-data-centres-secrecy-eu-law-environment-footprint
67•cyberlimerence•3h ago•19 comments

ReBot-DevArm: open-source Robotic Arm

https://github.com/Seeed-Projects/reBot-DevArm
71•rickcarlino•4d ago•17 comments

Substrate AI Is Hiring Harness Engineers

https://www.ycombinator.com/companies/substrate/jobs/QJU9023-harness-engineer
1•kunle•9h ago

A Better R Programming Experience Thanks to Tree-sitter

https://ropensci.org/blog/2026/04/02/tree-sitter-overview/
136•sebg•15h ago•23 comments

Century-bandwidth antenna reinvented,patented after 18 yrs with decade bandwidth (2006)

https://ieeexplore.ieee.org/document/1715264
33•teleforce•4d ago•11 comments

A Git helper tool that breaks large merges into parallelizable tasks

https://github.com/mwallner/mergetopus
45•schusterfredl•4d ago•11 comments

Qwen3.6-35B-A3B: Agentic coding power, now open to all

https://qwen.ai/blog?id=qwen3.6-35b-a3b
1146•cmitsakis•22h ago•482 comments

US Bill Mandates On-Device Age Verification

https://reclaimthenet.org/us-bill-mandates-on-device-age-verification
231•ronsor•9h ago•148 comments

PROBoter – Open-source platform for automated PCB analysis

https://www.schutzwerk.com/en/blog/proboter-01/
17•kuizu•6h ago•0 comments

Cloudflare's AI Platform: an inference layer designed for agents

https://blog.cloudflare.com/ai-platform/
291•nikitoci•23h ago•73 comments

The beginning of scarcity in AI

https://tomtunguz.com/ai-compute-crisis-2026/
108•gmays•15h ago•141 comments

The future of everything is lies, I guess: Where do we go from here?

https://aphyr.com/posts/420-the-future-of-everything-is-lies-i-guess-where-do-we-go-from-here
645•aphyr•22h ago•663 comments

Rubens Menin's 150 Years "Old" Port Wine

https://neofeed.com.br/finde/o-vinho-do-porto-very-very-old-de-rubens-menin/en/
9•Anon84•3d ago•6 comments

Discourse Is Not Going Closed Source

https://blog.discourse.org/2026/04/discourse-is-not-going-closed-source/
158•sams99•8h ago•57 comments