frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

The Secret Life of NaN

https://anniecherkaev.com/the-secret-life-of-nan
18•prakashqwerty•1d ago

Comments

WalterBright•1h ago
NaNs are a very underappreciated feature of IEEE-754 floating point. In the D programming language, floats get default initialized to NaN, not to 0.0.

    double y = 0.0; // initialized to 0.0
    double x; // initialized to NaN
The discussion routinely comes up as "why not default initialize to 0.0?" The reason is a routine mistake in programming is forgetting to initialize a variable. With a floating point 0.0, one may never realize that the floating point calculation results are wrong. But with NaN, the result of a floating point computation will be NaN, which is unlikely to go unnoticed.

I don't know of any other programming language with this safety feature.

Also, the D `char` type is initialized to 0xFF, not 0, because Unicode says that 0xFF is an invalid character.

WalterBright•1h ago
Another crucial use of NaNs is if you have a sensor. If the sensor has failed, the sensed value should be transmitted as NaN, not 0, so the receiver knows the data is bad.
AlotOfReading•16m ago
My experience is that if you write an interface that (rarely) returns NaNs, someone will use it assuming it's never NaN no matter how good the docs are. Then their code does bad things and you have to patiently explain why they're wrong and yes, they are holding isnan() wrong (in C/C++).
p1necone•35m ago
Just requiring explicit assignment before first use feels like the superior approach to automatic initialization, regardless of whether the automatic initialization is with 0 or with NaN.
WalterBright•20m ago
That suggestion is often made.

The trouble with it is a bug I've seen often. People will get an error message about an "uninitialized variable". Then they go into "just get the compiler to shut up" mode, amd pick "0" as the initializer. Then, the program compiles and runs, and silently produces the wrong answer. Code reviews will simply pass over the "0" initializer, as it looks right.

With default NaN initialization, the programmer is more likely to stop and think about it, not just insert 0.

Another issue with it is:

    float x = 0.0;
    setFloat(&x);

    void setFloat(float* px) { *px = 3.0; }
For the purposes of code clarity I don't want to see a variable initialized to a value that is never used, just to shut the compiler up.
wpollock•30m ago
> ... Unicode says that 0xFF is an invalid character.

Not so. You may be thinking of UTF-8 encoding. 0xff is DEL in Unicode.

WalterBright•16m ago
The "char" type in D represents a UTF-8 code unit, the byte 0xFF is not a valid character code and is strictly forbidden.
anitil•26m ago
That's a very thoughtful decision, I always enjoy your updates on D
GMoromisato•1h ago
I use nan boxing in GridWhale. It feels like the Infinite Hotel[1]: you can always add another type. Note that these techniques also rely on the fact that we don't use all 64-bits for memory addressing. If we ever do, lots of VMs will break.

For me, the major advantage of nan boxing is that you don't have to allocate a whole class of types (like floats). That saves so much at garbage collection time.

------------

[1] https://en.wikipedia.org/wiki/Hilbert%27s_paradox_of_the_Gra...

Microsoft and OpenAI end their exclusive and revenue-sharing deal

https://www.bloomberg.com/news/articles/2026-04-27/microsoft-to-stop-sharing-revenue-with-main-ai...
704•helsinkiandrew•10h ago•632 comments

Is my blue your blue?

https://ismy.blue/
248•theogravity•3h ago•161 comments

Three men are facing charges in Toronto SMS Blaster arrests

https://www.tps.ca/media-centre/stories/unprecedented-sms-blaster-arrests/
65•gnabgib•2h ago•30 comments

Easyduino: Open Source PCB Devboards for KiCad

https://github.com/Hanqaqa/Easyduino
149•Hanqaqa•5h ago•21 comments

Spanish archaeologists discover trove of ancient shipwrecks in Bay of Gibraltar

https://www.theguardian.com/science/2026/apr/15/hidden-treasures-spanish-archaeologists-discover-...
69•1659447091•1d ago•8 comments

New Integrated by Design FreeBSD Book

https://vivianvoss.net/blog/integrated-by-design-launch
5•vermaden•18m ago•0 comments

The quiet resurgence of RF engineering

https://atempleton.bearblog.dev/quiet-resurgence-of-rf-engineering/
96•merlinq•2d ago•46 comments

Networking changes coming in macOS 27

https://eclecticlight.co/2026/04/23/networking-changes-coming-in-macos-27/
187•pvtmert•7h ago•159 comments

China blocks Meta's acquisition of AI startup Manus

https://www.cnbc.com/2026/04/27/meta-manus-china-blocks-acquisition-ai-startup.html
269•yakkomajuri•11h ago•172 comments

4TB of voice samples just stolen from 40k AI contractors at Mercor

https://app.oravys.com/blog/mercor-breach-2026
418•Oravys•13h ago•154 comments

Men who stare at walls

https://www.alexselimov.com/posts/men_who_stare_at_walls/
404•aselimov3•12h ago•194 comments

The woes of sanitizing SVGs

https://muffin.ink/blog/scratch-svg-sanitization/
165•varun_ch•8h ago•64 comments

Super ZSNES – GPU Powered SNES Emulator

https://zsnes.com/
211•haunter•5h ago•56 comments

NPM website was down

https://status.npmjs.org
108•18nleung•2h ago•44 comments

The Secret Life of NaN

https://anniecherkaev.com/the-secret-life-of-nan
18•prakashqwerty•1d ago•9 comments

Radar Laboratory – Interactive Radar Phenomenology

https://radarlaboratory.com/
8•jonbaer•2d ago•0 comments

“Why not just use Lean?”

https://lawrencecpaulson.github.io//2026/04/23/Why_not_Lean.html
243•ibobev•9h ago•166 comments

GitHub Copilot is moving to usage-based billing

https://github.blog/news-insights/company-news/github-copilot-is-moving-to-usage-based-billing/
505•frizlab•7h ago•386 comments

Pgbackrest is no longer being maintained

https://github.com/pgbackrest/pgbackrest
391•c0l0•12h ago•197 comments

Fully Featured Audio DSP Firmware for the Raspberry Pi Pico

https://github.com/WeebLabs/DSPi
252•BoingBoomTschak•2d ago•75 comments

Magic by return of post: How mail order delivered the occult

https://publicdomainreview.org/essay/magic-by-return-of-post/
35•Vigier•2d ago•4 comments

Show HN: OSS Agent I built topped the TerminalBench on Gemini-3-flash-preview

https://github.com/dirac-run/dirac
286•GodelNumbering•10h ago•115 comments

FDA approves first gene therapy for treatment of genetic hearing loss

https://www.fda.gov/news-events/press-announcements/fda-approves-first-ever-gene-therapy-treatmen...
204•JeanKage•13h ago•76 comments

L123: A Lotus 1-2-3–style terminal spreadsheet with modern Excel compatibility

https://github.com/duane1024/l123
57•duane1024•3h ago•14 comments

US Supreme Court reviews police use of cell location data

https://www.nytimes.com/2026/04/27/us/politics/supreme-court-cell-data-geofence.html
208•unethical_ban•8h ago•127 comments

Adding a team was the wrong strategic decision

https://learnings.aleixmorgadas.dev/p/adding-a-team-was-the-wrong-strategic
68•milkglass•2d ago•21 comments

Quarkdown – Markdown with Superpowers

https://quarkdown.com/
238•amai•14h ago•83 comments

Ukraine's drone commander has Russian oil, troops and morale in his sights

https://www.bbc.com/news/articles/c1d9wvd2e4ro
14•tkgally•23m ago•1 comments

Decoupled DiLoCo: Resilient, Distributed AI Training at Scale

https://deepmind.google/blog/decoupled-diloco/
42•metadat•6h ago•5 comments

Show HN: Utilyze – an open source GPU monitoring tool more accurate than nvtop

https://www.systalyze.com/utilyze
84•ManyaGhobadi•9h ago•22 comments