comp.lang.ada
 help / color / mirror / Atom feed
From: adambeneschan@gmail.com
Subject: Re: Differences between Ada 83 and other revisions
Date: Fri, 14 Feb 2014 08:47:22 -0800 (PST)
Date: 2014-02-14T08:47:22-08:00	[thread overview]
Message-ID: <55497f04-98ab-472e-b82d-bbab9dd6915e@googlegroups.com> (raw)
In-Reply-To: <e3a83bb2-483f-4cc4-bc34-a0a67522c9b6@googlegroups.com>

On Friday, February 14, 2014 5:18:22 AM UTC-8, yoursurr...@gmail.com wrote:
> 
> One more question.  Can you custom specify floats with a specific number of decimal spaces?  For example, if you want ada to handle decimals that your comp hardware cannot handle.

I'm not sure just what you're looking for.  Although you can define a floating-point type using a "digits" clause that could, in theory, give you greater precision than your floating-point hardware can handle, in practice I don't think this is possible.  That is, if your machine supports 32-bit and 64-bit IEEE floats, then any floating-point type you define will map to one of those two floats, or will produce an error message at compile time.  A compiler vendor *could* provide additional floating-point types that have to be emulated in software, but the language does not require them to do so, and I don't know of any compiler that does.  [On machines with no floating-point, there is often a C library to emulate it, provided either by the manufacturer or by some other third party; here again, though, Ada compiler vendors are not required to go beyond that.]

When you refer to "decimals", some people have assumed you were talking about "decimal fixed-point".  This is a different kind of numeric type, generally with a fixed number of digits after the decimal point.  For example, this example from the RM defines a type that could be used for currency:

    type Money is delta 0.01 digits 15;

"delta 0.01" means that every numeric value of the type is a multiple of 0.01; thus, this type defines numbers with two digits after the decimal point.  "digits 15" means that the type can handle numbers of up to 15 digits, counting the digits after the decimal point; thus, the type can hold numbers from about -(10**13-1) to 10**13-1.  Those numbers are generally represented as integers, but the compiler keeps track of the scale factor.  So the number 2.35 would be represented internally as the integer 235.  If you multiply two such numbers, the program will multiply the integers and then automatically do any scaling and rounding for you.  [By the way, it's legal to declare a "delta 10.0" or "delta 100.0" type, etc., so that the scale factor is 10**N instead of 10**(-N).]

Here again, though, compilers aren't required to support decimal fixed types that would involve an integer too big for it to handle.  (If the Information Systems Annex is supported, then the compiler has to handle decimal fixed types that require 64-bit integers, but nothing larger.)  There's no language-defined equivalent of Java's BigInteger or BigDecimal, for example, with unlimited numbers of digits; on the other hand, compiler implementations could provide them if the vendor chooses.  Also, it would be incorrect to refer to types like this as "floats", since they're treated basically like integers and don't fit into the traditional definition of "floating-point".

So in any case, I think the answer to your question about numbers that the hardware can't handle is: no, Ada compilers are not required to support such numbers.  However, they're not prevented from doing so.  (And if hardware has no floating-point at all, I think Ada may require the compiler to provide *some* kind of software-emulated floating-point, although I'm not certain.)

                                 -- Adam


  parent reply	other threads:[~2014-02-14 16:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13 15:59 Differences between Ada 83 and other revisions yoursurrogategod
2014-02-13 16:12 ` adambeneschan
2014-02-13 18:00   ` yoursurrogategod
2014-02-13 18:07 ` AdaMagica
2014-02-13 19:44 ` Niklas Holsti
2014-02-13 21:25   ` yoursurrogategod
2014-02-13 22:00     ` Niklas Holsti
2014-02-13 22:18       ` adambeneschan
2014-02-14 13:18         ` yoursurrogategod
2014-02-14 13:53           ` AdaMagica
2014-02-14 14:06           ` Jacob Sparre Andersen
2014-02-14 16:47           ` adambeneschan [this message]
2014-02-14 14:08         ` Robert A Duff
2014-02-16  9:36         ` Martin
2014-02-16 14:13           ` Robert A Duff
2014-02-16 15:58             ` J-P. Rosen
2014-02-19 22:09               ` Robert A Duff
2014-02-19 22:23                 ` J-P. Rosen
2014-02-19 22:37                   ` Robert A Duff
2014-04-19  8:59                     ` Jacob Sparre Andersen
2014-02-19 22:34                 ` adambeneschan
2014-02-19 22:58                   ` Robert A Duff
2014-02-13 21:28 ` yoursurrogategod
2014-02-13 23:31   ` Randy Brukardt
2014-02-20 10:30     ` john
replies disabled

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