Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #383671
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c, comp.arch |
| Subject | Re: Radians Or Degrees? |
| Date | 2024-03-16 19:57 -0700 |
| Organization | None to speak of |
| Message-ID | <87frwp36r6.fsf@nosuchdomain.example.com> (permalink) |
| References | (16 earlier) <dbfb682bf2abb9b84ce04c257a85c6d1@www.novabbs.org> <87o7bd3guo.fsf@nosuchdomain.example.com> <ut5bpu$354bh$1@dont-email.me> <87jzm13af9.fsf@nosuchdomain.example.com> <ut5im0$36bc4$1@dont-email.me> |
Cross-posted to 2 groups.
bart <bc@freeuk.com> writes:
> 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
I see similar results (possibly identical, I haven't checked) with
i686-w64-mingw32-gcc on Cygwin. I think it uses the same, or a similar,
runtime library as the tdm64 implementation you're using.
Comparing the generated assembly, at -O0 it generates a call to "sin",
while at -O1 and above it replaces the expression with a compile-time
constant. Apparently that compile-time constant matches the run-time
computed value for glibc, but not for whatever tdm64 uses.
I don't *think* it's a conformance issue as long as the precision is
within the standard's (fairly vague) requirements. When I modify the
program to start with sin(1.0) rather than sin(2**53), the output is
identical at all optimization levels.
Apparently glibc and the library used by tgm64 behave differently when
computing the sin of very large values. The result for sin(2**53) in
long double differs by about one part in 2**17 between -O0 and -O1, or
between gcc/glibc and tgm64.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-14 11:26 +0200
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-14 17:34 +0000
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-14 19:48 +0000
Re: Radians Or Degrees? Terje Mathisen <terje.mathisen@tmsw.no> - 2024-03-15 12:16 +0100
Re: Radians Or Degrees? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-14 20:30 +0000
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-14 15:12 -0700
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-14 22:19 +0000
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-14 15:21 -0700
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-14 15:22 -0700
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-15 13:49 +0200
Re: Radians Or Degrees? Terje Mathisen <terje.mathisen@tmsw.no> - 2024-03-15 11:23 +0100
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-15 14:15 +0200
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-16 01:23 +0000
Re: Radians Or Degrees? Terje Mathisen <terje.mathisen@tmsw.no> - 2024-03-16 16:59 +0100
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-15 13:59 -0700
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-15 14:13 -0700
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-16 13:23 -0700
Re: Radians Or Degrees? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-15 14:16 -0700
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-15 14:26 -0700
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-15 14:30 -0700
Re: Radians Or Degrees? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-15 15:48 -0700
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-17 13:41 -0700
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-17 21:49 -0700
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-16 01:16 +0000
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-16 19:08 +0200
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-16 17:22 +0000
Re: Radians Or Degrees? scott@slp53.sl.home (Scott Lurndal) - 2024-03-16 18:32 +0000
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-16 20:49 +0200
Re: Radians Or Degrees? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-16 16:19 -0700
Re: Radians Or Degrees? bart <bc@freeuk.com> - 2024-03-17 00:00 +0000
Re: Radians Or Degrees? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-16 18:38 -0700
Re: Radians Or Degrees? bart <bc@freeuk.com> - 2024-03-17 01:57 +0000
Re: Radians Or Degrees? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-16 19:57 -0700
Re: Radians Or Degrees? David Brown <david.brown@hesbynett.no> - 2024-03-17 13:10 +0100
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-17 11:06 +0200
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-17 11:34 +0200
Re: Radians Or Degrees? bart <bc@freeuk.com> - 2024-03-17 10:59 +0000
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-17 14:15 +0200
Re: Radians Or Degrees? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-15 15:13 -0700
Re: Radians Or Degrees? Stefan Monnier <monnier@iro.umontreal.ca> - 2024-03-18 15:18 -0400
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-18 22:19 +0000
Re: Radians Or Degrees? Stefan Monnier <monnier@iro.umontreal.ca> - 2024-03-20 09:54 -0400
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-20 18:21 +0200
Re: Radians Or Degrees? Stefan Monnier <monnier@iro.umontreal.ca> - 2024-03-20 12:59 -0400
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-20 20:40 +0000
Re: Radians Or Degrees? Terje Mathisen <terje.mathisen@tmsw.no> - 2024-03-21 08:52 +0100
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-21 14:51 +0200
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-21 16:37 +0000
Re: Radians Or Degrees? Terje Mathisen <terje.mathisen@tmsw.no> - 2024-03-23 09:11 +0100
Re: Radians Or Degrees? "Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu> - 2024-03-20 17:02 +0000
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-20 20:47 +0000
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-20 20:33 +0000
Re: Radians Or Degrees? Michael S <already5chosen@yahoo.com> - 2024-03-21 00:03 +0200
Re: Radians Or Degrees? mitchalsup@aol.com (MitchAlsup1) - 2024-03-20 20:26 +0000
Re: Radians Or Degrees? Stefan Monnier <monnier@iro.umontreal.ca> - 2024-03-20 16:34 -0400
Re: Radians Or Degrees? Terje Mathisen <terje.mathisen@tmsw.no> - 2024-03-21 08:38 +0100
csiph-web