From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48 autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,840fead62ccf9fad X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.216.216.131 with SMTP id g3mr1607488wep.10.1351478331978; Sun, 28 Oct 2012 19:38:51 -0700 (PDT) Path: q13ni92136wii.0!nntp.google.com!feeder1.cambriumusenet.nl!feeder2.cambriumusenet.nl!feed.tweaknews.nl!81.171.88.15.MISMATCH!lightspeed.eweka.nl!81.171.88.16.MISMATCH!eweka.nl!hq-usenetpeers.eweka.nl!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!newsreader4.netcologne.de!news.netcologne.de!news.albasani.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: pragma import (C, , ); -- import a constant value from C library Date: Sat, 27 Oct 2012 09:15:41 +0100 Organization: A noiseless patient Spider Message-ID: References: <16623y0sig37z$.1r95bz8a2eoyd$.dlg@40tude.net> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="36fd3459bdfc79b1cfb1716bdcdac508"; logging-data="30112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2kk/EeKyuFRXOpy3f5ob4hR1X5qgnhjQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (darwin) Cancel-Lock: sha1:AS9hyK6lI5TNlehSNbMxeUQ755Y= sha1:AZY94kOGMFXSBWis4niCOPsCwWI= Content-Type: text/plain Date: 2012-10-27T09:15:41+01:00 List-Id: "Dmitry A. Kazakov" 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.