Deutsch   English   Français   Italiano  
<ut5im0$36bc4$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c,comp.arch
Subject: Re: Radians Or Degrees?
Date: Sun, 17 Mar 2024 01:57:22 +0000
Organization: A noiseless patient Spider
Lines: 87
Message-ID: <ut5im0$36bc4$1@dont-email.me>
References: <ur5trn$3d64t$1@dont-email.me> <20240222015920.00000260@yahoo.com>
 <ur69j9$3ftgj$3@dont-email.me> <ur86eg$1aip$1@dont-email.me>
 <ur88e4$1rr1$5@dont-email.me> <ur8a2p$2446$1@dont-email.me>
 <ur8ctk$2vbd$2@dont-email.me> <20240222233838.0000572f@yahoo.com>
 <3b2e86cdb0ee8785b4405ab10871c5ca@www.novabbs.org>
 <ur8nud$4n1r$1@dont-email.me>
 <936a852388e7e4414cb7e529da7095ea@www.novabbs.org>
 <ur9qtp$fnm9$1@dont-email.me> <20240314112655.000011f8@yahoo.com>
 <ut17ji$27n6b$1@dont-email.me> <ut2csb$2fe4u$1@dont-email.me>
 <87wmq32o26.fsf@nosuchdomain.example.com>
 <8de6385435bbdb0695a7ff213653f345@www.novabbs.org>
 <20240316190815.000005a2@yahoo.com>
 <dbfb682bf2abb9b84ce04c257a85c6d1@www.novabbs.org>
 <87o7bd3guo.fsf@nosuchdomain.example.com> <ut5bpu$354bh$1@dont-email.me>
 <87jzm13af9.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 17 Mar 2024 01:57:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="86cdd72051d773a92e0c8f332750da77";
	logging-data="3353988"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Cyn14vlaVPJvrvzI1KLOD"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:17UbJYZbDMKzWBKTEWheFxI5EGU=
Content-Language: en-GB
In-Reply-To: <87jzm13af9.fsf@nosuchdomain.example.com>
Bytes: 4827

On 17/03/2024 01:38, Keith Thompson wrote:
> bart <bc@freeuk.com> writes:
>> On 16/03/2024 23:19, Keith Thompson wrote:
>>> mitchalsup@aol.com (MitchAlsup1) writes:
>>
>>>> Say you are a programmer and you receive a value like 2^53 from an
>>>> Input read and you wan the most accurate possible SIN( of that ).
>>> I can't think of a scenario where that would be useful (other than
>>> just
>>> doing it for the sake of doing it).
>>> If 2^53 represents a physical quantity, how likely is the actual
>>> value
>>> to be known within ±π (+/i pi for those who prefer ASCII)?
>>> If you can get better precision without too much extra cost, that's
>>> great.  I don't know enough to have an opinion about what the best
>>> tradeoff is, but I presume it's going to be different depending on the
>>> application.
>>> Here's a C program that shows how precise sin(2^53) can be for types
>>> float, double, and long double (I used gcc and glibc).  The nextafter
>>> functions are used to compute the nearest representable number.  For
>>> long double, the value of sin() changes by about 1 part in 1600, which
>>> seems decent, but it's not nearly as precise as for values around 1.0.
>>> For float and double, the imprecision of the argument is enough to make
>>> the result practically meaningless.
>>>
>>> ...
>>> Output:
>>> float (32 bits, 24 mantissa bits)
>>> 9007199254740992.00000000 -0.84892595
>>> 9007200328482816.00000000 -0.34159181
>>> double (64 bits, 53 mantissa bits)
>>> 9007199254740992.00000000 -0.84892596
>>> 9007199254740994.00000000 -0.12729655
>>> long double (128 bits, 64 mantissa bits)
>>> 9007199254740992.00000000 -0.84892596
>>> 9007199254740992.00097656 -0.84944168
> 
>>
>> Is this output supposed to be different between gcc -O0 and gcc -O3?
> 
> No, why do you ask?
> 
> On my system, the output is identical with gcc and clang, and tcc at all
> optimization levels, with both glibc and musl.  I do get slightly
> different results for long double on Cygwin vs. Ubuntu (Cygwin uses
> newlib, not glibc).


Because I get the results shown below. Even if the library is different 
from yours, I would have assumed matching results.


------------------------------

C:\c>gcc c.c -O3

C:\c>a
float (32 bits, 24 mantissa bits)
9007199254740992.00000000 -0.84892595
9007200328482816.00000000 -0.34159181

double (64 bits, 53 mantissa bits)
9007199254740992.00000000 -0.84892596
9007199254740994.00000000 -0.12729655

long double (128 bits, 64 mantissa bits)
9007199254740992.00000000 -0.84892596
9007199254740992.00097656 -0.84944168

C:\c>gcc c.c -O0

C:\c>a
float (32 bits, 24 mantissa bits)
9007199254740992.00000000 -0.84893209
9007200328482816.00000000 -0.34160271

double (64 bits, 53 mantissa bits)
9007199254740992.00000000 -0.84893209
9007199254740994.00000000 -0.12728505

long double (128 bits, 64 mantissa bits)
9007199254740992.00000000 -0.84893209
9007199254740992.00097656 -0.84944780

C:\c>gcc --version
gcc (tdm64-1) 10.3.0