Ancestors

Written by Laurence Tratt on 2025-01-17 at 08:47

This morning I was scratching my head over failing Rust code that turned out to be due to Rust parsing "-1" as the literal "-1" (good!) but "-1.x(0)" is parsed as "-(1.x(0))" (bonkers!). Turns out that it's a known issue, but blimey is parsing hard! https://github.com/rust-lang/rust/issues/117155

=> More informations about this toot | More toots from ltratt@mastodon.social

Toot

Written by David Chisnall (Now with 50% more sarcasm!) on 2025-01-17 at 11:52

@ltratt I am increasingly of the opinion that a unary negation operator is a bad idea. The number of times I've written something like x = -x is so small that changing it to x = 0 - x is no hardship (and, the last time I wrote it, I actually did write it like that because it was clearer). Removing the unary negation operator would make that an unambiguous parse because -1 is a valid number literal, whereas - {expression} is not a valid expression. Similarly, x-1 is unambiguous (x {-1} is not valid).

=> More informations about this toot | More toots from david_chisnall@infosec.exchange

Descendants

Written by Josh Simmons on 2025-01-17 at 12:07

@david_chisnall @ltratt note that for fp numbers -x is not strictly equivalent to 0 - x, which is perhaps a small spanner in the works there (though certainly not a big one, you can always implement it as a negate function without the operator).

=> More informations about this toot | More toots from dotstdy@mastodon.social

Written by David Chisnall (Now with 50% more sarcasm!) on 2025-01-17 at 12:08

@dotstdy @ltratt If you're writing floating-point code that relies on that difference, and I ever have to read it, an explicit call to a function called fneg or something more descriptive would make me very happy.

=> More informations about this toot | More toots from david_chisnall@infosec.exchange

Written by Josh Simmons on 2025-01-17 at 12:11

@david_chisnall @ltratt yeah, 100%. Having a special function gives you a place to put documentation of the semantics too.

=> More informations about this toot | More toots from dotstdy@mastodon.social

Written by Steve Canon on 2025-01-17 at 12:19

@dotstdy @david_chisnall @ltratt (only if you care about the sign of zero in directed rounding modes or NaN payload/signaling status, which most people should not care about.)

=> More informations about this toot | More toots from steve@discuss.systems

Written by Josh Simmons on 2025-01-17 at 12:30

@steve @david_chisnall @ltratt it's also perhaps more likely that if you care, you want 0-x instead of -x anyway :')

=> More informations about this toot | More toots from dotstdy@mastodon.social

Written by Laurence Tratt on 2025-01-17 at 14:14

@david_chisnall I think I agree about banning unary negation (the FP case, as you pointed out elsewhere, can be handled in pleasing, though different, ways).

=> More informations about this toot | More toots from ltratt@mastodon.social

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113843551736132909
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
308.760246 milliseconds
Gemini-to-HTML Time
1.621411 milliseconds

This content has been proxied by September (3851b).