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.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f349615dc134784c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-23 07:25:27 PST Path: newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!193.174.75.178!news-fra1.dfn.de!news0.de.colt.net!newscore.gigabell.net!isdnet!psinet-france!psiuk-f4!psiuk-p4!uknet!psiuk-n!news.pace.co.uk!nh.pace.co.uk!not-for-mail From: "Marin David Condic" Newsgroups: comp.lang.ada Subject: Re: Positive Floating Range? Date: Mon, 23 Apr 2001 10:13:55 -0400 Organization: Posted on a server owned by Pace Micro Technology plc Message-ID: <9c1db4$nph$1@nh.pace.co.uk> References: <817E6.2056$DW1.94361@iad-read.news.verio.net> NNTP-Posting-Host: 136.170.200.133 X-Trace: nh.pace.co.uk 988035236 24369 136.170.200.133 (23 Apr 2001 14:13:56 GMT) X-Complaints-To: newsmaster@pace.co.uk NNTP-Posting-Date: 23 Apr 2001 14:13:56 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: newsfeed.google.com comp.lang.ada:6858 Date: 2001-04-23T14:13:56+00:00 List-Id: It seems that everyone missed your first question. AFAIK, there isn't going to be any easy way of restricting a floating point subtype to only positive, non-zero entities. At least not in a way that is always 100% portable and takes full advantage of the machine. You can pick some semi-arbitrary small number to be the lower bound: subtype Foo is Float range 0.000001..Float'Last; (At or about zero, things in floating point get pretty nasty anyway! :-) You could also look into using attributes of floating point types to help you out in picking the lower bound. (See ARM, A.5.3 for a full list.) Of particular interest may be 'Model_Small, but I've never tried using Float'Model_Small as a lower bound. See if: subtype Foo is Float range Float'Model_Small..Float'Last; gives you what you want. (And if it even compiles!) You may still have problems getting this sort of thing to raise constraint error because it is likely to be implementation dependent as to how accurately "0.0" is going to get converted to a float by Text_IO and if this is going to trigger a constraint error. Hope this helps. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Dr Nancy's Sweetie" wrote in message news:817E6.2056$DW1.94361@iad-read.news.verio.net... > > I looked in a few books and at some FAQs, but maybe I just wasn't > looking in the right place. > > I want to specify a subtype for floating point numbers which will > only allow positive numbers to be entered. I can do something like > this: > subtype Foo is Float range 0.0..Float'Last; > > and then test for zero myself whenever somebody enters a number, > but that feels an awful lot like a kludge. > > I tried float'first, but it turned out to be a negative number of > large magnitude, not a positive number of small magnitude. Trying > this: > Put(Float'succ(0.0)); > gave me: > 0.00000E+00 > > This test: > > if Float'Succ(0.0) = 0.0 then > Put("They're equal!"); > else > Put("Not equal!"); > end if; > > said "Not equal!", but then why didn't the previous "put" give me > something like "1.1E-52"? > > So it looks like I get what I want with: > > subtype Foo is Float range Float'Succ(0.0)..Float'Last; > > When I tried that, and typed in "0.0" for a "Get(fooVar);", it > didn't give a constraint error. So there's apparently something > I can't see going on here. > > > Also, while I can get a Float, the compiler claims that there's no > such thing as a "Double". At first I figured maybe Ada used the > double all the time (like Perl does), but Float'Machine_Radix is 2, > and Float'Machine_Mantissa is 24; that's single precision on this > machine. How do I get what C calls `double'? > > I found a reference to things like this: > > type foo is delta 0.000001 digits 20; > > But it's not clear what happens if I specify something which is too > precise (or too many digits) for the machine's natural double-word size. > Does it truncate, or build its own floating type and then do the work in > software? The former seems sorta anti-Adaish (just throwing out your > information), and the latter could be time consuming. I just want it to > use the machine's natural double word size. Is there some way to do that? > > > Since these are pretty basic questions, it may be best to e-mail you > responses directly to me and I'll summarise in a few days. Thanks! > > > Darren F Provine ! kilroy@copland.rowan.edu ! http://www.rowan.edu/~kilroy > "The obvious mathematical breakthrough would be development of an easy > way to factor large prime numbers." > -- Bill Gates, _The Road Ahead_, Viking Penguin (1995), page 265