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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fee8802cc3d8334d X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/16 Message-ID: <7k8mba$rf3@sjx-ixn9.ix.netcom.com>#1/1 X-Deja-AN: 490324297 References: <7jt2c0$vrb@drn.newsguy.com> <7k57vb$1ipf@drn.newsguy.com> <7k5kef$1ghi@news1.newsguy.com> Organization: Netcom X-NETCOM-Date: Wed Jun 16 10:19:38 AM PDT 1999 Newsgroups: comp.lang.ada Date: 1999-06-16T10:19:38-07:00 List-Id: In article , jerry@jvdsys.stuyts.nl wrote: >Of course, there was no overflow but an error. Banks use fixed point >arithmatic. It is actually a reason why PL/I is still in use, Cobol, >like Ada, garantees 18 digits accuracy and that sometimes is not >enough. IBM's PL/I compiler offers 22 digit accuracy for it's fixed point >arithmatic. Actually, U.S. banks do not use fixed point arithmetic. They use decimal arithmetic. This is one reason COBOL is preferred over languages that do not have inherent support for decimal data types. Ada has added decimal type capability with, type Yen is delta 0.01 digits 15; There is no need for any kind of type casting. It should be of interest to note that Ada and COBOL are among the few languages with direct support for decimal data types. In this regard, Ada and COBOL are superior to C++, Eiffel, Java, Modula-3, etc, which all require a decimal type class to make this work. Unfortunately, this is one of those cases where defining a class is not as effective as intrinsic language support. Even better, with Ada we can easily express the proper relationships and operations for accounting using the decimal fraction data type. package Money is type Dollars is delta 0.0001 digits 15; Money_Error : exception; ... end Money; followed by an abstract type that can be used as the root for derivations of asset, liability, equity, expense, and revenue account types. For example, a debit behaves differently for an asset than for a liability. package Money.Accounting is type Account_Type is abstract tagged private; procedure Debit (Account : in out Account; Amount : in Dollars) is abstract; procedure Credit (Account : in out Account; Amount : in Dollars) is abstract; private type Account_Type is abstract tagged record Amount : Dollars := 0.0; ... end record; end Money.Accounting; Decimal types is one of those cases where Ada has excellent potential for simple and direct solutions to a set of problems that is likely to be more complex in a language such as C++ or Java. Richard Riehle richard@adaworks.com http://www.adaworks.com