comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Drummond <brian@shapes.demon.co.uk>
Subject: Re: Ada.Numerics, Accuracy of trigonometric functions
Date: Fri, 7 Oct 2016 10:23:54 -0000 (UTC)
Date: 2016-10-07T10:23:54+00:00	[thread overview]
Message-ID: <nt7t3q$697$1@dont-email.me> (raw)
In-Reply-To: nt7sgs$1a06$1@gioia.aioe.org

On Fri, 07 Oct 2016 12:13:48 +0200, Markus Schöpflin wrote:

> The following tests have been performed using GNAT 7.4 on a 64bit Linux
> system.
> 
> I'm puzzled by the seemingly bad accuracy of calling COS on a large
> value of type Short_Float.
> 
> ---%<---
> Size of SHORT_FLOAT =  32 Maximum relative error of COS =  2.38419E-07
> Angle threshold =  12 X = 4294967296.00000; COS(X) =  1.00000      <--
> WHAT?
> --->%---
> 
> The corresponding C program:
> 
> ---%<---
> 
> gives:
> 
> ---%<---
> sizeof(float) = 4 x = 4294967296.000000; cos(x) = -0.886887    <--- OK
> --->%---
> 
> Now, why is the error on cos(2**32) so large in this case? I am aware
> that I'm way beyond the required angle threshold mentioned in G.2.4(12),
> so it's up to the compiler to decide on the accuracy.

C tends to silently coerce "float" to "double" any time you pass a float 
argument to a function unless you jump through hoops to make such 
coercion impossible. 

So my suspicion is simply that the C program is giving you double 
precision.

-- Brian

  parent reply	other threads:[~2016-10-07 10:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-07 10:13 Ada.Numerics, Accuracy of trigonometric functions Markus Schöpflin
2016-10-07 10:23 ` Markus Schöpflin
2016-10-07 10:23 ` Brian Drummond [this message]
2016-10-07 10:40   ` Markus Schöpflin
2016-10-07 14:52 ` Dennis Lee Bieber
2016-10-07 15:19   ` Markus Schöpflin
2016-10-07 22:15     ` Dennis Lee Bieber
2016-10-07 16:38 ` Jeffrey R. Carter
2016-10-10  7:44   ` Markus Schöpflin
2016-10-22 22:38 ` Robert Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox