Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c5c08e3b-1e41-36-a0f5-324f4976b8df@esi.com.au>
Date: Wed, 19 Jun 2024 17:09:25 +1000 (AEST)
From: Damian McGuckin <damianm@....com.au>
To: MUSL <musl@...ts.openwall.com>
Subject: Re: roundf() (and round(), and ...)


Commenting on only part of that:

On Tue, 18 Jun 2024, Szabolcs Nagy wrote:

> it is unspecified if (uint32_t)a raises inexact exception,
> so this will be target and compiler dependent in practice.

Yes. Scary.

> ieee-754-2008:
>
>  5.8 Details of conversions from floating-point to integer formats
>  ...
>  A language standard that permits implicit conversions or expressions
>  involving mixed types should require that these be implemented with
>  the inexact-signaling conversion operations below.

IEEE-754 2019 now specifies:

 	The operations for conversion from floating-point to a specific
 	signed or unsigned integer format without signaling the inexact
 	exception are:

 	One of which is:

 		intFormatOf-convertToIntegerTowardZero(source)

 		convertToIntegerTowardZero(x) rounds x to an integral
 		value toward zero.

AND

 	The operations for conversion from floating-point to a specific
 	signed or unsigned integer format, signaling if inexact, are:

 		intFormatOf-convertToIntegerExactTowardZero(source)

 		convertToIntegerExactTowardZero(x) rounds x to an integral
 		value toward zero.

So, it depends as you say, which of those two operations the compiler 
uses when it translates:

 	(integral-type) floating-point-expression

If indeed the target supports both.

> c23:
>
>  F.4 Floating to integer conversion
>  ...
>  ... whether conversion of a non-integral floating value raises the
>  "inexact" floating-point exception is unspecified.[note]
>  ...
>  note: In those cases where it matters, library functions can be used
>  to effect such conversions with or without raising the "inexact"
>  floating-point exception.

Ah, but then such functions are lower down those that we currently name.

Thanks - Damian

Pacific Engineering Systems International ..... 20D Grose St, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.