comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: pragma import (C, , ); -- import a constant value from C library
Date: Sat, 27 Oct 2012 09:15:41 +0100
Date: 2012-10-27T09:15:41+01:00	[thread overview]
Message-ID: <lyd304qqj6.fsf@pushface.org> (raw)
In-Reply-To: 16623y0sig37z$.1r95bz8a2eoyd$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Fri, 26 Oct 2012 15:45:29 -0700 (PDT), Enzo Guerra wrote:
>
>> trying to import a constant value from C library (libgsl)
>> but having no luck
>> 
>>  M_EULER : Long_Float;
>>  -- M_EULER, Euler's constant, \gamma
>> pragma Import (C, M_EULER, "M_EULER");
>> 
>> get error undefined reference to `M_EULER'
>> 
>> would appreciate any help
>
> Don't do this. Ada.Numerics already defines Euler's constant.
>
> And in general, you can define any constant this way in Ada. The precision
> is limited only by the source where you get its tabulated value. And it
> will work for all real types. E.g.
>
> gamma : constant :=
>    0.57721_56649_01532_86060_65120_90082_40243;
>
>    X : Long_Float := gamma;
>    Y : Float := gamma;
>    ...
>
> The compiler truncates the value when you use a narrower target like
> Long_Float.

Yes.

I worked on a project where the system engineers on the other side had
defined pi to be 3.14159 (not even 3.141592); so when we sent a Float
equal to Ada.Numerics.Pi they got a range check. We ended up agreeing
the bounds to be one mantissa bit outside the actual limit we intended.



  reply	other threads:[~2012-10-29  2:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-26 22:45 pragma import (C, , ); -- import a constant value from C library Enzo Guerra
2012-10-26 23:06 ` Simon Wright
2012-10-27  7:15   ` Maciej Sobczak
2012-11-05  3:41     ` David Thompson
2012-10-27  7:40 ` Dmitry A. Kazakov
2012-10-27  8:15   ` Simon Wright [this message]
2012-10-27  8:19   ` Simon Wright
2012-10-27  8:47     ` Dmitry A. Kazakov
replies disabled

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