Re: finding primes
- From: "Azumanga" <4zumanga@xxxxxxxxx>
- Date: 30 Oct 2006 06:13:10 -0800
Chris Uppal wrote:
Azumanga wrote:
On the other hand, we are assuming that sqrt(n*n) results inIn any language I'm familar with, if you found an n where that
exactly n and not:
(n-1)+0.9999999999999999
happened, you'd submit a HUGE bug comment to the people who make the
langauge.
Will Java do ?
=====================
import java.math.BigInteger;
public class Test
{
public static void
main(String[] args)
{
// NB: n is representable as <= 64 bits, it is actually
// (1L << 60) + 1
BigInteger n = new BigInteger("1152921504606846977");
BigInteger squared = n.multiply(n);
// have to convert to double to get the square root
double root = Math.sqrt(squared.doubleValue());
// and...
System.out.println(n);
System.out.println((long)root);
}
}
=====================
Or any other language which can handle big integers but which doesn't
naturally represent floating point in arbitrary-precision.
If you are going to start casting to doubles, then all your problems
are your own :)
Chris
.
- Follow-Ups:
- Re: finding primes
- From: Arthur J. O'Dwyer
- Re: finding primes
- References:
- finding primes
- From: Digital Puer
- Re: finding primes
- From: Richard Heathfield
- Re: finding primes
- From: Logan Shaw
- Re: finding primes
- From: Richard Heathfield
- Re: finding primes
- From: dcorbit
- Re: finding primes
- From: Azumanga
- Re: finding primes
- From: Chris Uppal
- finding primes
- Prev by Date: Re: finding primes
- Next by Date: Re: 450,000x450,000 array: The best programming language to handle it
- Previous by thread: Re: finding primes
- Next by thread: Re: finding primes
- Index(es):
Relevant Pages
|
|