On Wed, Jul 16, 2025 at 5:57 PM Anthony Sorace <[email protected]> wrote:
> I have a floating point issue I don’t understand. I have a stripped-down 
> reproducer here:
>
> http://a.9srv.net/tmp/fptest.c
>
> Tested on 8c on 9legacy and 6c on geoff’s 9k, “step” prints different things 
> for the intermediate value and the set variable, both of which are nonsense.
>
> Am I doing something wrong with that cast? It looks right to me (and performs 
> as expected in unix).
>
> (Use caution: moving the (float) to inside the parens to only apply to end 
> crashes at least one 9legacy kernel.)

I believe this is due to the difference in type-promotion rules
between ISO C and Plan 9 C.  It's been a while, so the details are
kinda fuzzy, but ISO C will (almost certainly) promote e.g. the
`u8int`'s to signed `int`'s before performing the arithmetic binops;
plan9 C will promote them to `unsigned int`, so you end up with
wrapping behavior, so your `end - start` gives a (large) number as the
result. If I change your `u8int`s to `int` everywhere, then compiling
with `8c` gives the same results on plan 9 as with clang on macOS.

        - Dan C.

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T5e40b126925dfe86-M38df311c00cdbc248ebfc07e
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to