Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Ignorance is the soil in which belief in miracles grows." -- Robert G. Ingersoll


devel / comp.lang.c / Re: <math.h> precision guarantees, if any

SubjectAuthor
* <math.h> precision guarantees, if anyAndrey Tarasevich
+- Re: <math.h> precision guarantees, if anyBen
+* Re: <math.h> precision guarantees, if anyJames Kuyper
|`* Re: <math.h> precision guarantees, if anyKeith Thompson
| `* Re: <math.h> precision guarantees, if anyJames Kuyper
|  `- Re: <math.h> precision guarantees, if anyKeith Thompson
`- Re: <math.h> precision guarantees, if anyFred J. Tydeman

1
<math.h> precision guarantees, if any

<t37he9$v4o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21203&group=comp.lang.c#21203

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: <math.h> precision guarantees, if any
Date: Wed, 13 Apr 2022 15:04:56 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <t37he9$v4o$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 13 Apr 2022 22:04:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e0c2d8d982dc47ab52c9054a399b94ef";
logging-data="31896"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19P1cFyKRErYGInkGrbFM2s"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Cancel-Lock: sha1:wOk/7CBXG+FiiRUaHm2imXTng2Y=
Content-Language: en-US
 by: Andrey Tarasevich - Wed, 13 Apr 2022 22:04 UTC

I vaguely remember that from time to time a come across mentions of some
specification that imposes more-or-less strict precision (or rounding)
guarantees onto functions from <math.h>. Something along the lines of
`pow(2, 2)` being guaranteed to produce 4.0, possibly under some set of
additional implementation-defined circumstances.

But I can't seem to find anything like that in the C standard. Do these
guarantees actually exist somewhere? IEE754? POSIX? The C standard?
Somewhere else?

--
Best regards,
Andrey Tarasevich

Re: <math.h> precision guarantees, if any

<87r160tvq2.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21208&group=comp.lang.c#21208

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.lang.c
Subject: Re: <math.h> precision guarantees, if any
Date: Thu, 14 Apr 2022 00:22:13 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <87r160tvq2.fsf@bsb.me.uk>
References: <t37he9$v4o$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="d24b48f9c0b0cf8c127841564518bd44";
logging-data="19853"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NcLpMlXBYT3e10XEoDG9YGSPYsNnNz1s="
Cancel-Lock: sha1:B6sF0n87d7HPu9FiSZW0bgYuMI8=
sha1:d3RS3viH8yVQcn7KnKeBKgFuBhA=
X-BSB-Auth: 1.a770948ca3c59a06dd5a.20220414002213BST.87r160tvq2.fsf@bsb.me.uk
 by: Ben - Wed, 13 Apr 2022 23:22 UTC

Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> I vaguely remember that from time to time a come across mentions of
> some specification that imposes more-or-less strict precision (or
> rounding) guarantees onto functions from <math.h>. Something along the
> lines of `pow(2, 2)` being guaranteed to produce 4.0, possibly under
> some set of additional implementation-defined circumstances.
>
> But I can't seem to find anything like that in the C standard. Do
> these guarantees actually exist somewhere? IEE754? POSIX? The C
> standard? Somewhere else?

IEEE 754 requires that the basic operations (add, subtract, etc) have
results as if they were done exactly and then correctly rounded to the
nearest representable value. Operations like x^y are optional in the
specification, but even when they are provided they are not required (in
general) to as accurate. If there are special rules for some cases
(like 2.0^2.0) I am unaware of them.

--
Ben.

Re: <math.h> precision guarantees, if any

<t37pab$hil$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21211&group=comp.lang.c#21211

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: <math.h> precision guarantees, if any
Date: Wed, 13 Apr 2022 20:19:23 -0400
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <t37pab$hil$1@dont-email.me>
References: <t37he9$v4o$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Apr 2022 00:19:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cbcc4f6839691843302fd41383d5f73b";
logging-data="18005"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hoBakwTsjf66XSX4e8i8MeGzKLTzPzOc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:LyICaCSpT1IDR4nf/nEjKFedq+k=
In-Reply-To: <t37he9$v4o$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Thu, 14 Apr 2022 00:19 UTC

On 4/13/22 18:04, Andrey Tarasevich wrote:
> I vaguely remember that from time to time a come across mentions of
> some specification that imposes more-or-less strict precision (or
> rounding) guarantees onto functions from <math.h>. Something along the
> lines of `pow(2, 2)` being guaranteed to produce 4.0, possibly under
> some set of additional implementation-defined circumstances.
>
> But I can't seem to find anything like that in the C standard. Do
> these guarantees actually exist somewhere? IEE754? POSIX? The C
> standard? Somewhere else?
>

Here's what the C standard says:
"The accuracy of the floating-point operations ( + , - , * , / ) and of
the library functions in <math.h> and <complex.h> that return
floating-point results is implementation-defined, as is the accuracy of
the conversion between floating-point internal representations and
string representations performed by the library functions in <stdio.h>,
<stdlib.h> , and <wchar.h> . The implementation may state that the
accuracy is unknown." (5.2.4.2.2p6).

Note that this does not apply to any of the other expression types that
can have operands of floating point type, all of which must therefore be
exact: () _Generic() ++ -- ! < > <= >= == != ?: ,
This doesn't help much, except for the relational operators.

Note that this means that an implementation can implement floating point
math so inaccurately that LDBL_MAX - LDBL_MIN < LDBL_MIN - LDBL_MAX, so
long as an implementation correctly documents that fact, or chooses to
say "the accuracy is unknown".

[Re: conversion of floating point constants to internal representations]
"For decimal floating constants, and also for hexadecimal floating
constants when FLT_RADIX is not a power of 2, the result is either the
nearest representable value, or the larger or smaller representable
value immediately adjacent to the nearest representable value, chosen in
an implementation-defined manner. For hexadecimal floating constants
when FLT_RADIX is a power of 2, the result is correctly rounded."
(6.4.4.2p3).

Since comparison operations on floating point numbers are required to be
exact, those requirement imply that you can compare floating point
constants with very high accuracy - but that's the most that you can
portably rely on when using C.

Recommended practice:
"The translation-time conversion of floating constants should match the
execution-time conversion of character strings by library functions,
such as strtod , given matching inputs suitable for both conversions,
the same result format, and default execution-time rounding." (6.5.5.3p7).

However, when __STDC_IEC_559__ or __STDC_IEC_559_COMPLEX__ are
pre#defined by the implementation, then the implementation must conform
to Annex F and Annex G, respectively, which impose requirements similar,
though not quite identical, to those of ISO/IEC 60559 (== IEEE 754).
That standard imposes much stricter requirements - pretty much the
strictest requirements that can reasonably be applied.

POSIX imposes no accuracy requirements of it's own. It mandates
conformance to the C standard's very minimal requirements, and allows,
but does not require, IEEE 754 conformance.

Re: <math.h> precision guarantees, if any

<87bkx4fj27.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21213&group=comp.lang.c#21213

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: <math.h> precision guarantees, if any
Date: Wed, 13 Apr 2022 20:19:28 -0700
Organization: None to speak of
Lines: 41
Message-ID: <87bkx4fj27.fsf@nosuchdomain.example.com>
References: <t37he9$v4o$1@dont-email.me> <t37pab$hil$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="f70bdff0312c3b54d6b132549de7af94";
logging-data="16295"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197TN2xmii5qK/fg/IEW92Q"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:vvj37pZdgyKOFt86SfwdRDEtdm8=
sha1:nFTGg/M+lnkJy+PU9xy+Jx+syNc=
 by: Keith Thompson - Thu, 14 Apr 2022 03:19 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 4/13/22 18:04, Andrey Tarasevich wrote:
>> I vaguely remember that from time to time a come across mentions of
>> some specification that imposes more-or-less strict precision (or
>> rounding) guarantees onto functions from <math.h>. Something along the
>> lines of `pow(2, 2)` being guaranteed to produce 4.0, possibly under
>> some set of additional implementation-defined circumstances.
>>
>> But I can't seem to find anything like that in the C standard. Do
>> these guarantees actually exist somewhere? IEE754? POSIX? The C
>> standard? Somewhere else?
>>
>
> Here's what the C standard says:
> "The accuracy of the floating-point operations ( + , - , * , / ) and of
> the library functions in <math.h> and <complex.h> that return
> floating-point results is implementation-defined, as is the accuracy of
> the conversion between floating-point internal representations and
> string representations performed by the library functions in <stdio.h>,
> <stdlib.h> , and <wchar.h> . The implementation may state that the
> accuracy is unknown." (5.2.4.2.2p6).
>
> Note that this does not apply to any of the other expression types that
> can have operands of floating point type, all of which must therefore be
> exact: () _Generic() ++ -- ! < > <= >= == != ?: ,
> This doesn't help much, except for the relational operators.

It does apply to ++ and --. For example:

The expression ++E is equivalent to (E+=1).

so if E is of floating-point type, the constant 1 is converted to that
type and the accuracy requirements are the same as for ordinary
addition.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: <math.h> precision guarantees, if any

<t38c45$th1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21218&group=comp.lang.c#21218

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: <math.h> precision guarantees, if any
Date: Thu, 14 Apr 2022 01:40:21 -0400
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <t38c45$th1$1@dont-email.me>
References: <t37he9$v4o$1@dont-email.me> <t37pab$hil$1@dont-email.me>
<87bkx4fj27.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Apr 2022 05:40:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="fa3e78f11f0f9ef37c80fba2b7c1f018";
logging-data="30241"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1fHFhwYnvZgw9NS9kzG94iMZcOEPxAQk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:JOigAhejz1ZmCYHEidBNkvk2IyA=
In-Reply-To: <87bkx4fj27.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: James Kuyper - Thu, 14 Apr 2022 05:40 UTC

On 4/13/22 23:19, Keith Thompson wrote:
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
....
>> Here's what the C standard says:
>> "The accuracy of the floating-point operations ( + , - , * , / ) and of
>> the library functions in <math.h> and <complex.h> that return
>> floating-point results is implementation-defined, as is the accuracy of
>> the conversion between floating-point internal representations and
>> string representations performed by the library functions in <stdio.h>,
>> <stdlib.h> , and <wchar.h> . The implementation may state that the
>> accuracy is unknown." (5.2.4.2.2p6).
>>
>> Note that this does not apply to any of the other expression types that
>> can have operands of floating point type, all of which must therefore be
>> exact: () _Generic() ++ -- ! < > <= >= == != ?: ,
>> This doesn't help much, except for the relational operators.
>
> It does apply to ++ and --. For example:
Sorry - I was undergoing constant harassment by two seven-year olds
while trying to post that message.

Re: <math.h> precision guarantees, if any

<Jd11RFbi8Eoq-pn2-dGdJog046JjR@ECS16501512.domain>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21231&group=comp.lang.c#21231

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tydeman....@sbcglobal.net (Fred J. Tydeman)
Newsgroups: comp.lang.c
Subject: Re: <math.h> precision guarantees, if any
Date: Thu, 14 Apr 2022 14:03:40 -0000 (UTC)
Organization: Tydeman Consulting
Lines: 24
Message-ID: <Jd11RFbi8Eoq-pn2-dGdJog046JjR@ECS16501512.domain>
References: <t37he9$v4o$1@dont-email.me>
Reply-To: tydeman@tybor.com
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 14 Apr 2022 14:03:40 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="79de943036c475b0c95a7db99914da11";
logging-data="14092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BoaEXSDeLRfjQkYNUPUrG"
User-Agent: ProNews/2 V1.60.cp125
Cancel-Lock: sha1:TqqocioP4IRJY/IuIvJ6BkPxOBg=
 by: Fred J. Tydeman - Thu, 14 Apr 2022 14:03 UTC

On Wed, 13 Apr 2022 22:04:56 UTC, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:

> I vaguely remember that from time to time a come across mentions of some
> specification that imposes more-or-less strict precision (or rounding)
> guarantees onto functions from <math.h>. Something along the lines of
> `pow(2, 2)` being guaranteed to produce 4.0, possibly under some set of
> additional implementation-defined circumstances.
>
> But I can't seem to find anything like that in the C standard. Do these
> guarantees actually exist somewhere? IEE754? POSIX? The C standard?
> Somewhere else?
>

The international standard
ISO/IEC 10967-2
Language independent arithmetic -
Part 2: Elementary numerical functions
may have precision / accuracy requirements on math functions.
---
Fred J. Tydeman Tydeman Consulting
tydeman@tybor.com Testing, numerics, programming
+1 (702) 608-6093 Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.

Re: <math.h> precision guarantees, if any

<87v8vbecsk.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21235&group=comp.lang.c#21235

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: <math.h> precision guarantees, if any
Date: Thu, 14 Apr 2022 11:32:27 -0700
Organization: None to speak of
Lines: 28
Message-ID: <87v8vbecsk.fsf@nosuchdomain.example.com>
References: <t37he9$v4o$1@dont-email.me> <t37pab$hil$1@dont-email.me>
<87bkx4fj27.fsf@nosuchdomain.example.com> <t38c45$th1$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="f70bdff0312c3b54d6b132549de7af94";
logging-data="11958"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lyKQuI7L/QhVlBlBEVdBh"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:RunrvUtPvk7E7xzK0Lxmi59yzxQ=
sha1:DQ/RXOCrReiMDJLGnG9JDjzEU/c=
 by: Keith Thompson - Thu, 14 Apr 2022 18:32 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 4/13/22 23:19, Keith Thompson wrote:
>> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> ...
>>> Here's what the C standard says:
>>> "The accuracy of the floating-point operations ( + , - , * , / ) and of
>>> the library functions in <math.h> and <complex.h> that return
>>> floating-point results is implementation-defined, as is the accuracy of
>>> the conversion between floating-point internal representations and
>>> string representations performed by the library functions in <stdio.h>,
>>> <stdlib.h> , and <wchar.h> . The implementation may state that the
>>> accuracy is unknown." (5.2.4.2.2p6).
>>>
>>> Note that this does not apply to any of the other expression types that
>>> can have operands of floating point type, all of which must therefore be
>>> exact: () _Generic() ++ -- ! < > <= >= == != ?: ,
>>> This doesn't help much, except for the relational operators.
>>
>> It does apply to ++ and --. For example:
> Sorry - I was undergoing constant harassment by two seven-year olds
> while trying to post that message.

That definitely causes undefined behavior.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor