frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

C++ float-to-int conversion can be undefined behavior

https://kttnr.net/blog/cpp-float-to-int-conversion-undefined-behavior/
17•signa11•4d ago

Comments

lionkor•4d ago
The core guidelines library is definitely not doing the right thing here. Very odd.
digitalPhonix•3d ago
Herb Sutter's comment on why it's ok is confusing to me:

> Regarding the use of UB internally: It's okay and if anyone is worried about it the use of UB is benign on the platforms we target (e.g., they don't involve hitting any hardware trap representations for these types)

Isn't the outcome of the UB (ie. whether it will "rm -rf /" or something else) dependent on both the target and the compiler? And the compiler (or future compiler) could plausibly make the assumption that the narrowing to an unpreventable value will never occur and change behaviour because of it?

pjmlp•55m ago
No, UB is allowed special powers for compiler and standard library implementors, which is what Herb Sutter means with internal behaviour.

Meaning MSVC is aware of these cases, so the compiler has special cases for it.

wavemode•43m ago
GSL is not the standard library nor an internal runtime library. Its GitHub page claims that it supports a variety of compilers:

> The GSL officially supports recent major versions of Visual Studio with both MSVC and LLVM, GCC, Clang, and XCode with Apple-Clang

pjmlp•21m ago
It was originally created by Microsoft and as Herb mentions "all our target platforms", so most likely it gets special treatment.
Maxatar•13m ago
There is absolutely no special treatment afforded to the GSL by any of the target platforms. While we can't inspect MSVC's source code, both clang and GCC do not have any support or affordance for the GSL whatsoever and it would be very unusual to expect MSVC's source code to have some kind of affordance for this library.
digitalPhonix•41m ago
That's my point - GSL is NOT MSVC only, it's a general purpose library and NOT a standard library implementation of a toolchain so any compiler is expected to be able to compile it (it also explicitly targets clang & gcc).
pjmlp•20m ago
It was originally created by Microsoft and as Herb mentions "all our target platforms", so most likely it gets special treatment.
Maxatar•43m ago
Yes, this is all true but Sutter's comment is that the specific platforms that this specific implementation of the GSL targets results in the correct output. The platforms officially supported are:

GCC 12, 13, 14

XCode 14.3.1, 15.4

Clang 16, 17, 18

Visual Studio with MSVC VS2019, VS2022

Visual Studio with LLVM VS2019, VS2022

wavemode•37m ago
For what it's worth, a GSL developer later reopened that GitHub issue and stated that they're going to look into fixing the UB. Sutter may have just been stating an assumption.

https://github.com/microsoft/GSL/issues/786#issuecomment-513...

> I'll raise this issue in the next internal GSL sync. I'd agree with y'all that this behavior: https://godbolt.org/z/4Tr1fe9xG is undesirable

LoganDark•33m ago
UB is bad not because it actually leads to any particular result on any particular platform or compiler, but because semantically it invalidates assumptions about a program. Rust is explicit on this, but it absolutely still applies to C/C++.
jcranmer•17m ago
In LLVM, the result of floating-to-int conversion that is out of range of the int is a poison value, which means you get essentially the full unpredictability of UB.

That said, I'm a little hard-pressed to think of optimizations that would actually take advantage of poison, because floating-point range isn't really computed in the optimizer.

pjmlp•57m ago
Hopefully this will be part of UB fixes for C++29, where plenty of UB is being redefined as erroneous behaviour instead.
orangepanda•51m ago
How could it be defined behaviour, when the result is different on ARM and x86?
marcosdumay•47m ago
Architecture dependent is not the same as undefined.
stouset•40m ago
Also, the spec says it’s undefined. But compiler authors can always special-case their own compilers.
cataphract•23m ago
Undefined behavior is not the same as implementation-defined or unspecified behavior. A program with undefined behavior is by definition an incorrect program. But there are cases where the spec actually gives some margin to the implementation. Programs relying on the choices of the implementation may be correct, even if non-portable.

Devtools must be open source

https://blog.exe.dev/devtools-must-be-open-source
237•bryanmikaelian•3h ago•72 comments

Ten advances in mathematics and theoretical computer science

https://openai.com/index/ten-advances-in-mathematics/
48•milkshakes•1h ago•363 comments

MiniMax H3 Day-0 Support in ComfyUI: Open Weights, Native Audio, and 2K Video

https://blog.comfy.org/p/minimax-h3-day-0-support-in-comfyui
166•vblanco•4h ago•49 comments

Wind and solar overtake fossil fuels in Germany for the first time

https://www.intellinews.com/wind-and-solar-overtake-fossil-fuels-in-germany-for-the-first-time-ev...
131•just_some_user•4h ago•54 comments

Launch HN: Hoplite (YC S26) – Effortlessly deploy cloud coding agents

https://hoplite.sh
18•BenceRed•1h ago•15 comments

Andy Pavlo joins ClickHouse to establish ClickHouse Labs

https://clickhouse.com/blog/andy-pavlo-joins-clickhouse
135•nikolay_sivko•3h ago•27 comments

Celebrating 45 Years of Kermit with the First New C-Kermit Release in 15 Years

https://changelog.complete.org/archives/44456-celebrating-45-years-of-kermit-with-the-first-new-c...
17•roryirvine•52m ago•4 comments

How Hollywood stopped making movies in Hollywood

https://www.statsignificant.com/p/how-hollywood-stopped-making-movies
90•speckx•6d ago•83 comments

Qwen3.8-Max: A New Bar for Coding and Cowork

https://qwen.ai/blog?id=qwen3.8
955•ai2027•15h ago•490 comments

Show HN: Product analytics (and evals) for agent sessions on your MCP

https://armature.tech/
15•screm•1h ago•0 comments

AirLLM 70B inference with single 4GB GPU

https://github.com/lyogavin/airllm
134•Anon84•6h ago•46 comments

Bonsai: Janestreet's UI Library

https://github.com/janestreet/bonsai
229•KolmogorovComp•9h ago•83 comments

C++ float-to-int conversion can be undefined behavior

https://kttnr.net/blog/cpp-float-to-int-conversion-undefined-behavior/
18•signa11•4d ago•17 comments

SQLite Critical CVEs or LLM Slop?

https://research.jfrog.com/post/sqlite-critical-cves-or-llm-slops/
638•ymir_e•6h ago•264 comments

SPF Record Syntax: Mechanisms, Qualifiers, Modifiers, and Macros

https://dmarcguard.io/blog/spf-record-syntax/
30•meysamazad•4h ago•7 comments

Taylor Farms has rewritten its cyclospora statement four times in sixteen days

https://www.marlerblog.com/case-news/taylor-farms-has-rewritten-its-cyclospora-statement-four-tim...
210•speckx•2h ago•118 comments

Don't be a meat proxy

https://gruhn.me/blog/2026-08-03/
1463•ngruhn•11h ago•621 comments

Explanation of INT8 ConvRot (FP8 is no longer needed)

https://note.com/hirorohi03/n/n047a8c5f7f8b?hl=en
10•peter_d_sherman•1h ago•4 comments

Massively Parallel Postgres Backups

https://planetscale.com/blog/massively-parallel-postgres-backups
4•ksec•3d ago•0 comments

SearXNG in Rust

https://github.com/MikeLuu99/searxng-rust
8•dluuuu•1h ago•2 comments

Show HN: Nightcrawler – A local AI pentesting agent running on a smartphone

https://github.com/garagehq/nightcrawler/
84•NickySlicks•6h ago•23 comments

What DMARC Protects You From, and What It Does Not

https://senderledger.com/articles/what-dmarc-actually-protects-you-from
97•adulion•8h ago•25 comments

Rust project goals: Immobile types and guaranteed destructors

https://github.com/rust-lang/rust-project-goals/blob/main/src/2026/move-trait.md
191•paavohtl•11h ago•72 comments

Kraid is a now a real compiler

https://www.collabora.com/news-and-blog/news-and-events/kraid-is-a-now-a-real-compiler.html
15•losgehts•4d ago•4 comments

Prevent cognitive debt by manually retyping LLM-generated code

https://ankursethi.com/blog/prevent-cognitive-debt-by-manually-retyping-llm-generated-code/
288•mpweiher•8h ago•256 comments

Games at the press of a button: The Rip-O-Bot (1989)

https://blog.gingerbeardman.com/2026/08/02/games-at-the-press-of-a-button-the-rip-o-bot/
25•msephton•21h ago•5 comments

Octane – React’s programming model, compiled

https://octanejs.dev
112•nnx•9h ago•37 comments

Walk on Decomposed Subdomains

https://clementjambon.github.io/wods/index.html#blogpost
32•E-Reverance•6d ago•2 comments

Train Simulator Controller

https://z80.me/blog/tsc-2026-july/
81•austinallegro•3d ago•5 comments

The Abandoned Fish Sauce Terrorizing a Small Canadian Town

https://defector.com/abandoned-fish-sauce-canada-interview
160•ohjeez•3d ago•132 comments