comp.lang.ada
 help / color / mirror / Atom feed
* Positive Floating Range?
@ 2001-04-21  3:21 Dr Nancy's Sweetie
  2001-04-21  7:25 ` tmoran
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Dr Nancy's Sweetie @ 2001-04-21  3:21 UTC (permalink / raw)



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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-05-01 20:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-21  3:21 Positive Floating Range? Dr Nancy's Sweetie
2001-04-21  7:25 ` tmoran
2001-04-21 14:57 ` Samuel T. Harris
2001-04-22  1:14 ` Jeffrey Carter
2001-04-23 14:13 ` Marin David Condic
2001-05-01 20:40 ` Georg Bauhaus

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