From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Ada function sqrt(x)
Date: 1996/09/21
Date: 1996-09-21T00:00:00+00:00 [thread overview]
Message-ID: <dewar.843335145@schonberg> (raw)
In-Reply-To: Dy0xBw.A1u@thomsoft.com
I assume the integer square root problem was an assignment anyway, so
I am not about to provide the obvious answer, but Keith said
"You can convert the argument to a floating-point type, take the square
root, and convert back to an integer type, but that may lose precision
in some cases. Also, I think an integer square root operation typically
truncates rather than rounding (for example, sqrt(99) is 9, not 10).
Ada 95 provides a 'Truncation attribute (see RM95-A.5.3) -- but again,
watch out for loss of precision (sqrt(9.0) *might* return something like
2.9999999; also, many 32-bit integers cannot be represented exactly in
32-bit floating-point)."
In fact, the square root of 9 must be exactly 3.
\x1adp
next prev parent reply other threads:[~1996-09-21 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <01bba50c$7c1a2760$dc014dc6@MountainNet>
1996-09-18 0:00 ` Ada function sqrt(x) Pascal Obry
1996-09-20 0:00 ` Keith Thompson
1996-09-20 0:00 ` Roderick Chapman
1996-09-21 0:00 ` Robert Dewar
1996-09-26 0:00 ` Keith Thompson
1996-09-21 0:00 ` Robert Dewar [this message]
1996-09-22 0:00 ` Matthew Heaney
1996-09-22 0:00 ` Matthew Heaney
1996-09-24 0:00 W. Wesley Groleau (Wes)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox