comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: pragma import (C, , ); -- import a constant value from C library
Date: Sat, 27 Oct 2012 09:40:01 +0200
Date: 2012-10-27T09:40:01+02:00	[thread overview]
Message-ID: <16623y0sig37z$.1r95bz8a2eoyd$.dlg@40tude.net> (raw)
In-Reply-To: c5fc4cd5-8948-40dd-9191-e79a4617ffd4@googlegroups.com

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.

You can even perform simple calculations with such constants keeping their
huge precision. The compiler uses arbitrary-precision arithmetic for them.
E.g.

[ with Ada.Numerics; use Ada.Numerics; ]

half_pi : constant := pi / 2.0;
    -- far more than enough right digits for a Long_Float

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent 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 [this message]
2012-10-27  8:15   ` Simon Wright
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