[llvm-dev] double to unsigned char cast

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu Apr 5 09:41:41 PDT 2018


Hi Jay,

On 5 April 2018 at 07:49, Jay K via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> wrt
> https://github.com/mono/mono/commit/fb91fce5d339bb9ffe507588f5bc1d8d6f244d9b
>
>
> This doesn't seem right to me.

Nevertheless, it's what the standard says. C99 6.3.1.4: When a finite
value of real floating type is converted to an integer type other than
_Bool, the fractional part is discarded (i.e. the value is truncated
toward zero). If the value of the integral part cannot be represented
by the integer type, the behavior is undefined.

By definition any double you're allowed to convert to an unsigned char
doesn't need the "and".

Cheers.

Tim.


More information about the llvm-dev mailing list