Re: finding primes




Chris Uppal wrote:
Azumanga wrote:


On the other hand, we are assuming that sqrt(n*n) results in
exactly n and not:
(n-1)+0.9999999999999999

In any language I'm familar with, if you found an n where that
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

.



Relevant Pages

  • Re: finding primes
    ... you'd submit a HUGE bug comment to the people who make the ... // have to convert to double to get the square root ... Or any other language which can handle big integers but which doesn't ...
    (comp.programming)
  • Re: Indentation and optional delimiters
    ... Probably many years ago a language like Python was too much ... But there's a need for higher level computer languages. ... Today Ruby is a bit higher-level than Python (despite being rather ... So it's a type bug. ...
    (comp.lang.python)
  • Re: Static vs Dynamic
    ... it's easy to miss the bug because the code looks quite correct ... >>As an experienced Java programmer you need to keep lots of code idioms ... These problems don't exist in a dynamically typed language. ... Any bad thread programming in any language is troublesome ...
    (comp.lang.lisp)
  • Re: best programming language for console/sql application?
    ... Zhang (or Weiwu?), I'm surprised there are no good open source bug tracking solutions out there already. ... Product, Platform, Version Range, and Programming Language. ...
    (freebsd-questions)
  • TransModal modal dialog project : beta testing
    ... I am proposing the current v. 0.0.3 beta for criticism and for bug fix ... user's preferred language and not English ... var lang = navigator.userLanguage.substring; ... * Until IE7 form controls were external DirectX objects ...
    (comp.lang.javascript)