Java number precision
Author |
Message |
HeavenAgain
|
Posted: Sat Nov 17, 2007 9:42 pm Post subject: Java number precision |
|
|
for example, how do i get the value of 1234 to the power of 7? it reached the number format limit
there must be a way to show it.... BigInteger or BigDecimal? how does those work, if they are related.... and if they are related, i need the log method, which they dont have... |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Euphoracle
|
|
|
|
|
HeavenAgain
|
Posted: Sat Nov 17, 2007 10:08 pm Post subject: RE:Java number precision |
|
|
ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
dont get it :'( |
|
|
|
|
|
Euphoracle
|
Posted: Sat Nov 17, 2007 10:32 pm Post subject: RE:Java number precision |
|
|
Meaning you have created a non terminating non repeating fraction, which BigDecimal cannot represent becuase it strives for absolute accuracy, and whatnot, perhaps I'm wrong, who knows, etc.
<horrible sentence structure > |
|
|
|
|
|
HeavenAgain
|
Posted: Sat Nov 17, 2007 10:53 pm Post subject: RE:Java number precision |
|
|
i understand and yet i dont understand
im going to kill myself if i dont get this must, research....!!
edit: im not saying you MUST use BigInteger or BigDecimal, that was just my idea, becuase i dont see how long or double is going to hold a number like 4357186184021382204544 (1234 to the power of 7) |
|
|
|
|
|
OneOffDriveByPoster
|
Posted: Sun Nov 18, 2007 12:45 pm Post subject: Re: Java number precision |
|
|
HeavenAgain @ Sat Nov 17, 2007 9:42 pm wrote: i need the log method, which they dont have...
You need log in what base? And are your inputs exact powers of the base? Might be easier if you don't need a general log function. |
|
|
|
|
|
HeavenAgain
|
Posted: Sun Nov 18, 2007 3:17 pm Post subject: RE:Java number precision |
|
|
input is 2 numbers, n and p
n square root of p, find k (the result)
and if p is 7 and n is 4357186184021382204544, result i should i get is 1234
now n is too big for double or long, thats what im talking about i hope it it helps anyone with helping me
side note, k = 10^((log n)/ p), i think |
|
|
|
|
|
Barbarrosa
|
Posted: Mon Nov 19, 2007 2:08 am Post subject: Re: Java number precision |
|
|
I've tried to use BigDecimal to do it, but to no avail. There is no floating point power, nor any root method for BigDecimal. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
HeavenAgain
|
Posted: Mon Nov 19, 2007 10:08 am Post subject: RE:Java number precision |
|
|
Java's BigDecimal have something weird going on inside, so for this problem, im not sure if it will be suitable for it, becuase
code: | BigDecimal num = new BigDecimal(1.1);
System.out.println(num);
System.out.println(num.pow(2)); |
as you can see num is not 1.1, its acually some number with some useless trail of floating point
but back to the problem, there was a hint given, and it said, double should be able to handle it |
|
|
|
|
|
Barbarrosa
|
Posted: Mon Nov 19, 2007 10:38 pm Post subject: Re: Java number precision |
|
|
Well, Eclipse will accept it if you put it in scientific notation. Won't give me 1234 as an answer, though. |
|
|
|
|
|
HeavenAgain
|
Posted: Mon Nov 19, 2007 10:44 pm Post subject: RE:Java number precision |
|
|
hehe, never mind about this question, i have figured out the way to solve this type of problem
something about high percision algorith, involving array
thanks for all the inputs |
|
|
|
|
|
Barbarrosa
|
Posted: Mon Nov 19, 2007 11:55 pm Post subject: Re: Java number precision |
|
|
Welcome, I'm also interested in getting the answer. Could you share it? |
|
|
|
|
|
|
|