comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <marin.condic.auntie.spam@pacemicro.com>
Subject: Re: error output numbers
Date: Mon, 19 Mar 2001 16:28:00 -0500
Date: 2001-03-19T21:28:19+00:00	[thread overview]
Message-ID: <995tlj$sd5$1@nh.pace.co.uk> (raw)
In-Reply-To: 01c0b0b5$af29df60$2a9ec594@default

The correct result is in excess of six billion. A garden variety integer is
only good to 2**31 - or around two billion - on most Ada implementations.
Hence your calculation is overflowing. You did not say what compiler you are
using but I bet if you check you'll discover there is a switch you can set
to turn on runtime checks for overflows. Do that, and your program will
probably raise Constraint_Error.

If your compiler supports a longer integer, this might help your
calculations, but it is only a matter of time before this will overflow too.
Factorials grow very rapidly to exceed whatever size integer you want to
pick.

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/



"w" <wwminirl@hotmail.com> wrote in message
news:01c0b0b5$af29df60$2a9ec594@default...
> when i use ada to write a program to calculate factorial, i found that
> result after 12! is always wrong.
>
> for example,
>
> 12! = 479001600
> but 13! gives me 1932053504.
> The correct result should be 6227020800.
>
> May be there are some problems with my integer declaration?
> I decleared all outputs to be INTEGER.
>
> Thanks!       :-)





  reply	other threads:[~2001-03-19 21:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-19 20:46 error output numbers w
2001-03-19 21:28 ` Marin David Condic [this message]
2001-03-20  2:22   ` tmoran
2001-03-19 21:36 ` David C. Hoos, Sr.
2001-03-19 22:10 ` Chad R. Meiners
2001-04-06 14:03 ` Nils
replies disabled

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