473,569 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java.math.BigIn teger

281 Contributor
I don't understand about this program is doing. Could someone please tell me what it is about. Because I have gcd function in one program that calls this function. Thanks a lot
Expand|Select|Wrap|Line Numbers
  1.  
  2. switch (opcode) {
  3. case GCD:       out = b1.gcd(b2).toString();
  4.                             break;
Expand|Select|Wrap|Line Numbers
  1. /**
  2.      * Returns a BigInteger whose value is the greatest common divisor of
  3.      * <tt>abs(this)</tt> and <tt>abs(val)</tt>.  Returns 0 if
  4.      * <tt>this==0 &amp;&amp; val==0</tt>.
  5.      *
  6.      * @param  val value with with the GCD is to be computed.
  7.      * @return <tt>GCD(abs(this), abs(val))</tt>
  8.      */
  9.     public BigInteger gcd(BigInteger val) {
  10.         if (val.signum == 0)
  11.         return this.abs();
  12.     else if (this.signum == 0)
  13.         return val.abs();
  14.  
  15.         MutableBigInteger a = new MutableBigInteger(this);
  16.         MutableBigInteger b = new MutableBigInteger(val);
  17.  
  18.         MutableBigInteger result = a.hybridGCD(b);
  19.  
  20.         return new BigInteger(result, 1);
  21.     }
Mar 19 '07 #1
19 6435
r035198x
13,262 MVP
I don't understand about this program is doing. Could someone please tell me what it is about. Because I have gcd function in one program that calls this function. Thanks a lot
Expand|Select|Wrap|Line Numbers
  1.  
  2. switch (opcode) {
  3. case GCD: out = b1.gcd(b2).toString();
  4. break;
Expand|Select|Wrap|Line Numbers
  1. /**
  2. * Returns a BigInteger whose value is the greatest common divisor of
  3. * <tt>abs(this)</tt> and <tt>abs(val)</tt>. Returns 0 if
  4. * <tt>this==0 &amp;&amp; val==0</tt>.
  5. *
  6. * @param val value with with the GCD is to be computed.
  7. * @return <tt>GCD(abs(this), abs(val))</tt>
  8. */
  9. public BigInteger gcd(BigInteger val) {
  10. if (val.signum == 0)
  11.      return this.abs();
  12.     else if (this.signum == 0)
  13.      return val.abs();
  14.  
  15. MutableBigInteger a = new MutableBigInteger(this);
  16. MutableBigInteger b = new MutableBigInteger(val);
  17.  
  18. MutableBigInteger result = a.hybridGCD(b);
  19.  
  20. return new BigInteger(result, 1);
  21. }
which part specifically do you not understand?
Mar 19 '07 #2
shana07
281 Contributor
which part specifically do you not understand?
The java package code. From my reading, signum is either '+', '-' or 0.
Then, mutableBigInteg er is for what?
As for gcd (a, b) calculation actually is about
a.gcd(b)
Then it involves with operator 'mod' to get remainder.
Where can I check those operators?

Expand|Select|Wrap|Line Numbers
  1. public BigInteger gcd(BigInteger val) {
  2. if (val.signum == 0)
  3.      return this.abs();
  4.     else if (this.signum == 0)
  5.      return val.abs();
  6.  
  7. MutableBigInteger a = new MutableBigInteger(this);
  8. MutableBigInteger b = new MutableBigInteger(val);
  9.  
  10. MutableBigInteger result = a.hybridGCD(b);
  11.  
  12. return new BigInteger(result, 1);
  13. }
Mar 19 '07 #3
r035198x
13,262 MVP
The java package code. From my reading, signum is either '+', '-' or 0.
Then, mutableBigInteg er is for what?
As for gcd (a, b) calculation actually is about
a.gcd(b)
Then it involves with operator 'mod' to get remainder.
Where can I check those operators?

Expand|Select|Wrap|Line Numbers
  1. public BigInteger gcd(BigInteger val) {
  2. if (val.signum == 0)
  3.      return this.abs();
  4.     else if (this.signum == 0)
  5.      return val.abs();
  6.  
  7. MutableBigInteger a = new MutableBigInteger(this);
  8. MutableBigInteger b = new MutableBigInteger(val);
  9.  
  10. MutableBigInteger result = a.hybridGCD(b);
  11.  
  12. return new BigInteger(result, 1);
  13. }
MutableBigInteg er is another class in the java.math package. It's implementation of hybridGCD is

Expand|Select|Wrap|Line Numbers
  1.  
  2. MutableBigInteger hybridGCD(MutableBigInteger b) {
  3.         // Use Euclid's algorithm until the numbers are approximately the
  4.         // same length, then use the binary GCD algorithm to find the GCD.
  5.         MutableBigInteger a = this;
  6.         MutableBigInteger q = new MutableBigInteger(),
  7.                           r = new MutableBigInteger();
  8.         while (b.intLen != 0) {
  9.             if (Math.abs(a.intLen - b.intLen) < 2)
  10.                 return a.binaryGCD(b);
  11.             a.divide(b, q, r);
  12.             MutableBigInteger swapper = a;
  13.             a = b; b = r; r = swapper;
  14.         }
  15.         return a;
  16.     }
  17.  
Mar 19 '07 #4
shana07
281 Contributor
MutableBigInteg er is another class in the java.math package. It's implementation of hybridGCD is

Expand|Select|Wrap|Line Numbers
  1.  
  2. MutableBigInteger hybridGCD(MutableBigInteger b) {
  3.         // Use Euclid's algorithm until the numbers are approximately the
  4.         // same length, then use the binary GCD algorithm to find the GCD.
  5.         MutableBigInteger a = this;
  6.         MutableBigInteger q = new MutableBigInteger(),
  7.                           r = new MutableBigInteger();
  8.         while (b.intLen != 0) {
  9.             if (Math.abs(a.intLen - b.intLen) < 2)
  10.                 return a.binaryGCD(b);
  11.             a.divide(b, q, r);
  12.             MutableBigInteger swapper = a;
  13.             a = b; b = r; r = swapper;
  14.         }
  15.         return a;
  16.     }
  17.  
Oh it's there...alright . TQ
One more question I need to consult you.Is it possible for me to replace any operators inside this class (only gcd subroutines)? Seems I can't do mutation on my program (that calls gcd class) .
* Aim - to do mutation to this gcd function. Because I remember last time, I tried on other java default pakcages and from netbean I can't open that package anymore once I changed it (unzipped the packages and zipped back).....sorry If this confusing you....
Mar 19 '07 #5
r035198x
13,262 MVP
Oh it's there...alright . TQ
One more question I need to consult you.Is it possible for me to replace any operators inside this class (only gcd subroutines)? Seems I can't do mutation on my program (that calls gcd class) .
* Aim - to do mutation to this gcd function. Because I remember last time, I tried on other java default pakcages and from netbean I can't open that package anymore once I changed it (unzipped the packages and zipped back).....sorry If this confusing you....
Do not change any classes in your java directories.
If you need to use any of them, copy them somewhere else and edit them there if you need to.
Mar 19 '07 #6
shana07
281 Contributor
Do not change any classes in your java directories.
If you need to use any of them, copy them somewhere else and edit them there if you need to.
Meaning to say that this is possible for me to do so isn't.
I need your advice regarding this please..
1. I have copied those two default java classes in my program under test
2. I renamed classes names as below:

java.math.BigIn teger >>> jonelo.sugar.ma th.MutableBigIn tegerMutant
java.math.Mutab leBigInteger >>> jonelo.sugar.ma th.BigIntMutant

3. And I have renamed all methods/variables/constructors with BigIntMutant
and MutableBigInteg erMutant

4. Is that possible for me to ask my program to refer to these two new classes when it calls gcd (I changed gcd method >>> gcdMutant).
Expand|Select|Wrap|Line Numbers
  1. case GCD:       out = b1.gcdMutant(b2).toString();
  2.                             break;
When I compile my main program - these 3 errors occured, Please advise what should I do..thank you

Main.java:31: cannot find symbol
symbol : class BigIntMutant
location: package jonelo.sugar.ma th
import jonelo.sugar.ma th.BigIntMutant ;
^
Main.java:32: cannot find symbol
symbol : class MutableBigInteg erMutant
location: package jonelo.sugar.ma th
import jonelo.sugar.ma th.MutableBigIn tegerMutant;
^
Main.java:528: cannot find symbol
symbol : method gcdMutant(java. math.BigInteger )
location: class java.math.BigIn teger
case GCD: out = b1.gcdMutant(b2 ).toString();
^
3 errors
Mar 20 '07 #7
r035198x
13,262 MVP
Meaning to say that this is possible for me to do so isn't.
I need your advice regarding this please..
1. I have copied those two default java classes in my program under test
2. I renamed classes names as below:

java.math.BigIn teger >>> jonelo.sugar.ma th.MutableBigIn tegerMutant
java.math.Mutab leBigInteger >>> jonelo.sugar.ma th.BigIntMutant

3. And I have renamed all methods/variables/constructors with BigIntMutant
and MutableBigInteg erMutant

4. Is that possible for me to ask my program to refer to these two new classes when it calls gcd (I changed gcd method >>> gcdMutant).
Expand|Select|Wrap|Line Numbers
  1. case GCD: out = b1.gcdMutant(b2).toString();
  2. break;
When I compile my main program - these 3 errors occured, Please advise what should I do..thank you

Main.java:31: cannot find symbol
symbol : class BigIntMutant
location: package jonelo.sugar.ma th
import jonelo.sugar.ma th.BigIntMutant ;
^
Main.java:32: cannot find symbol
symbol : class MutableBigInteg erMutant
location: package jonelo.sugar.ma th
import jonelo.sugar.ma th.MutableBigIn tegerMutant;
^
Main.java:528: cannot find symbol
symbol : method gcdMutant(java. math.BigInteger )
location: class java.math.BigIn teger
case GCD: out = b1.gcdMutant(b2 ).toString();
^
3 errors
First you will need to make sure that the classes you copied are not referencing other classes that you may not have copied.
Then you need to make sure that your import statements are correct e.g you cannot import a class that you are actually writting code for.
Mar 20 '07 #8
shana07
281 Contributor
First you will need to make sure that the classes you copied are not referencing other classes that you may not have copied.
Then you need to make sure that your import statements are correct e.g you cannot import a class that you are actually writting code for.
good example. Help me take a look at this import of the Main class. Why when I compile the Main class comes that errors: can't find class from that import statement....

Expand|Select|Wrap|Line Numbers
  1. package jonelo.bigal;
  2. import java.io.*;
  3. import java.math.BigInteger;
  4. import java.math.BigDecimal;
  5. import jonelo.sugar.math.GeneralMath; // ** Check: This default class from this program
  6.  
  7. import jonelo.sugar.math.BigIntMutant; //** Check: That's why I put these altered class in here
  8. import jonelo.sugar.math.MutableBigIntegerMutant; //** Check: same as this
  9.  
Mar 20 '07 #9
r035198x
13,262 MVP
good example. Help me take a look at this import of the Main class. Why when I compile the Main class comes that errors: can't find class from that import statement....

Expand|Select|Wrap|Line Numbers
  1. package jonelo.bigal;
  2. import java.io.*;
  3. import java.math.BigInteger;
  4. import java.math.BigDecimal;
  5. import jonelo.sugar.math.GeneralMath; // ** Check: This default class from this program
  6.  
  7. import jonelo.sugar.math.BigIntMutant; //** Check: That's why I put these altered class in here
  8. import jonelo.sugar.math.MutableBigIntegerMutant; //** Check: same as this
  9.  
Did you set up the directory structure correctly?
Mar 20 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3312
by: Cheetah | last post by:
Does anyone know of some public/open source implementations of Trig funtions - ie sin, cos, tan - for Java that operate with BigIntegers or BigDecimals. Even better would be a library which can add vectors. I'm starting with amplitudes and degrees, and need to add the vectors to come out with a final vector (amplitude). This kind of thing...
73
7932
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only...
458
20944
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers simply aren't smart enough to understand C++? This is not merely a whimsical hypothesis. Given my experience with Java programmers --- the code they...
2
7863
by: phjones | last post by:
Need help programming mortagage calculator for 3 different loans 7 year, 15 year and 30 year. using java array I am a beginner with Java, This is what I have so far. Need to know if I am off the path, import java.math.*;//*loan calculator import java.text.*;//*formats numbers public class 3 Mortgage loans { // declare class...
1
3289
by: feathers75 | last post by:
-------------------------------------------------------------------------------- First, Hello eveyone and I am new to Java. I am trying to create a Java program that will calculate a person BMI based on user input of weight (in pounds) and heigh (in inches) and then display what the BMI is and give the a message that tells them where...
5
6268
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
6
13541
by: mearvk | last post by:
Does C++ or C have something roughly equivalent to this: http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html What I need is a way to quickly convert between decimal and binary and from char*/string to a numeric representation. Thanks!
318
10833
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html Just to keep the post on topic for my friends at comp.lang.c++, how do I play default windows...
11
10468
by: imranisb | last post by:
Hi, Im developing RSA cryptography based application in VC#.Net 2.0 and need to use "BigInteger.probablePrime()". I know that VC#.Net 2.0 doesn't have the BigInteger class but found that one buddy created BigInteger class but it is missing some overloading function like BigInteger.probablePrime(). The code of the BigInteger class developed...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.