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 -
-
switch (opcode) {
-
case GCD: out = b1.gcd(b2).toString();
-
break;
- /**
-
* Returns a BigInteger whose value is the greatest common divisor of
-
* <tt>abs(this)</tt> and <tt>abs(val)</tt>. Returns 0 if
-
* <tt>this==0 && val==0</tt>.
-
*
-
* @param val value with with the GCD is to be computed.
-
* @return <tt>GCD(abs(this), abs(val))</tt>
-
*/
-
public BigInteger gcd(BigInteger val) {
-
if (val.signum == 0)
-
return this.abs();
-
else if (this.signum == 0)
-
return val.abs();
-
-
MutableBigInteger a = new MutableBigInteger(this);
-
MutableBigInteger b = new MutableBigInteger(val);
-
-
MutableBigInteger result = a.hybridGCD(b);
-
-
return new BigInteger(result, 1);
-
}
19 6424
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 -
-
switch (opcode) {
-
case GCD: out = b1.gcd(b2).toString();
-
break;
- /**
-
* Returns a BigInteger whose value is the greatest common divisor of
-
* <tt>abs(this)</tt> and <tt>abs(val)</tt>. Returns 0 if
-
* <tt>this==0 && val==0</tt>.
-
*
-
* @param val value with with the GCD is to be computed.
-
* @return <tt>GCD(abs(this), abs(val))</tt>
-
*/
-
public BigInteger gcd(BigInteger val) {
-
if (val.signum == 0)
-
return this.abs();
-
else if (this.signum == 0)
-
return val.abs();
-
-
MutableBigInteger a = new MutableBigInteger(this);
-
MutableBigInteger b = new MutableBigInteger(val);
-
-
MutableBigInteger result = a.hybridGCD(b);
-
-
return new BigInteger(result, 1);
-
}
which part specifically do you not understand?
which part specifically do you not understand?
The java package code. From my reading, signum is either '+', '-' or 0.
Then, mutableBigInteger 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? - public BigInteger gcd(BigInteger val) {
-
if (val.signum == 0)
-
return this.abs();
-
else if (this.signum == 0)
-
return val.abs();
-
-
MutableBigInteger a = new MutableBigInteger(this);
-
MutableBigInteger b = new MutableBigInteger(val);
-
-
MutableBigInteger result = a.hybridGCD(b);
-
-
return new BigInteger(result, 1);
-
}
The java package code. From my reading, signum is either '+', '-' or 0.
Then, mutableBigInteger 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? - public BigInteger gcd(BigInteger val) {
-
if (val.signum == 0)
-
return this.abs();
-
else if (this.signum == 0)
-
return val.abs();
-
-
MutableBigInteger a = new MutableBigInteger(this);
-
MutableBigInteger b = new MutableBigInteger(val);
-
-
MutableBigInteger result = a.hybridGCD(b);
-
-
return new BigInteger(result, 1);
-
}
MutableBigInteger is another class in the java.math package. It's implementation of hybridGCD is -
-
MutableBigInteger hybridGCD(MutableBigInteger b) {
-
// Use Euclid's algorithm until the numbers are approximately the
-
// same length, then use the binary GCD algorithm to find the GCD.
-
MutableBigInteger a = this;
-
MutableBigInteger q = new MutableBigInteger(),
-
r = new MutableBigInteger();
-
while (b.intLen != 0) {
-
if (Math.abs(a.intLen - b.intLen) < 2)
-
return a.binaryGCD(b);
-
a.divide(b, q, r);
-
MutableBigInteger swapper = a;
-
a = b; b = r; r = swapper;
-
}
-
return a;
-
}
-
MutableBigInteger is another class in the java.math package. It's implementation of hybridGCD is -
-
MutableBigInteger hybridGCD(MutableBigInteger b) {
-
// Use Euclid's algorithm until the numbers are approximately the
-
// same length, then use the binary GCD algorithm to find the GCD.
-
MutableBigInteger a = this;
-
MutableBigInteger q = new MutableBigInteger(),
-
r = new MutableBigInteger();
-
while (b.intLen != 0) {
-
if (Math.abs(a.intLen - b.intLen) < 2)
-
return a.binaryGCD(b);
-
a.divide(b, q, r);
-
MutableBigInteger swapper = a;
-
a = b; b = r; r = swapper;
-
}
-
return a;
-
}
-
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....
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.
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.BigInteger >>> jonelo.sugar.math.MutableBigIntegerMutant
java.math.MutableBigInteger >>> jonelo.sugar.math.BigIntMutant
3. And I have renamed all methods/variables/constructors with BigIntMutant
and MutableBigIntegerMutant
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). - case GCD: out = b1.gcdMutant(b2).toString();
-
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.math
import jonelo.sugar.math.BigIntMutant;
^
Main.java:32: cannot find symbol
symbol : class MutableBigIntegerMutant
location: package jonelo.sugar.math
import jonelo.sugar.math.MutableBigIntegerMutant;
^
Main.java:528: cannot find symbol
symbol : method gcdMutant(java.math.BigInteger)
location: class java.math.BigInteger
case GCD: out = b1.gcdMutant(b2).toString();
^
3 errors
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.BigInteger >>> jonelo.sugar.math.MutableBigIntegerMutant
java.math.MutableBigInteger >>> jonelo.sugar.math.BigIntMutant
3. And I have renamed all methods/variables/constructors with BigIntMutant
and MutableBigIntegerMutant
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). - case GCD: out = b1.gcdMutant(b2).toString();
-
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.math
import jonelo.sugar.math.BigIntMutant;
^
Main.java:32: cannot find symbol
symbol : class MutableBigIntegerMutant
location: package jonelo.sugar.math
import jonelo.sugar.math.MutableBigIntegerMutant;
^
Main.java:528: cannot find symbol
symbol : method gcdMutant(java.math.BigInteger)
location: class java.math.BigInteger
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.
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.... - package jonelo.bigal;
-
import java.io.*;
-
import java.math.BigInteger;
-
import java.math.BigDecimal;
-
import jonelo.sugar.math.GeneralMath; // ** Check: This default class from this program
-
-
import jonelo.sugar.math.BigIntMutant; //** Check: That's why I put these altered class in here
-
import jonelo.sugar.math.MutableBigIntegerMutant; //** Check: same as this
-
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.... - package jonelo.bigal;
-
import java.io.*;
-
import java.math.BigInteger;
-
import java.math.BigDecimal;
-
import jonelo.sugar.math.GeneralMath; // ** Check: This default class from this program
-
-
import jonelo.sugar.math.BigIntMutant; //** Check: That's why I put these altered class in here
-
import jonelo.sugar.math.MutableBigIntegerMutant; //** Check: same as this
-
Did you set up the directory structure correctly?
Did you set up the directory structure correctly?
I think yes, because I just paste the two classes in that directory.
So in the src\jonelo\sugar\math directory contains classes:
GeneralMath
MutableBigIntegerMutant
BigIntMutant
What else should be done you think...
I think yes, because I just paste the two classes in that directory.
So in the src\jonelo\sugar\math directory contains classes:
GeneralMath
MutableBigIntegerMutant
BigIntMutant
What else should be done you think...
and you put the package name correctly in the classes in the package statement.
and you put the package name correctly in the classes in the package statement.
Hurm, I need to consult you about this naming directory/package which I am not clear about it. I have located my program such this:
D:\Assignments\GOOD\BigAl\BigAl\bigal-src\
inside there contains:
jonelo\bigal\ * 3 classes: Main, Algorithm, BigAlException
jonelo\sugar\math\ * classes: GeneralMath, BigIntMutant, MutableBigIntegerMutant
jonelo\sugar\util\ *1 class: General
So, from where should I put import statement in Main class?
This is my import statements in Main class, please correct if I made wrong
package jonelo.bigal;
import java.io.*;
import java.math.BigInteger;
import java.math.BigDecimal;
import jonelo.sugar.math.GeneralMath;
import jonelo.sugar.math.BigIntMutant;
import jonelo.sugar.math.MutableBigIntegerMutant;
Hurm, I need to consult you about this naming directory/package which I am not clear about it. I have located my program such this:
D:\Assignments\GOOD\BigAl\BigAl\bigal-src\
inside there contains:
jonelo\bigal\ * 3 classes: Main, Algorithm, BigAlException
jonelo\sugar\math\ * classes: GeneralMath, BigIntMutant, MutableBigIntegerMutant
jonelo\sugar\util\ *1 class: General
So, from where should I put import statement in Main class?
This is my import statements in Main class, please correct if I made wrong
package jonelo.bigal;
import java.io.*;
import java.math.BigInteger;
import java.math.BigDecimal;
import jonelo.sugar.math.GeneralMath;
import jonelo.sugar.math.BigIntMutant;
import jonelo.sugar.math.MutableBigIntegerMutant;
Why don't you try to put all your classes in one package first.
Why don't you try to put all your classes in one package first.
This porblem is solved. I created one package like javah/math/BigInteger.
Then I used netbeans to build and run.
About this, i need to ask you: build in netbeans is same as compile?
Then I can see there is one jar created with same program name and build folder?....What happened was, I used prompt before to compile them one by one.
One more thing, what is this statement means? - int k = (s1 < s2) ? s1 : s2;
This porblem is solved. I created one package like javah/math/BigInteger.
Then I used netbeans to build and run.
About this, i need to ask you: build in netbeans is same as compile?
Then I can see there is one jar created with same program name and build folder?....What happened was, I used prompt before to compile them one by one.
One more thing, what is this statement means? - int k = (s1 < s2) ? s1 : s2;
It's a short cut way of writing the if-else construct. Play around with it and you will understand it better then.
Again about java/math package ...
1. I do need help to understand what is this program for.
2. In what situation then it calls binaryGCD (different binaryGCD & hybridGCD)
please..thanks - /**
-
* Calculate GCD of this and b. This and b are changed by the computation.
-
*/
-
MutableBigInteger hybridGCD(MutableBigInteger b) {
-
// Use Euclid's algorithm until the numbers are approximately the
-
// same length, then use the binary GCD algorithm to find the GCD.
-
MutableBigInteger a = this;
-
MutableBigInteger q = new MutableBigInteger(),
-
r = new MutableBigInteger();
-
-
while (b.intLen != 0)
-
{
-
if (Math.abs(a.intLen - b.intLen) < 2)
-
return a.binaryGCD(b);
-
a.divide(b, q, r);
-
MutableBigInteger swapper = a;
-
a = b; b = r; r = swapper;
-
}
-
return a;
-
}
Again about java/math package ...
1. I do need help to understand what is this program for.
2. In what situation then it calls binaryGCD (different binaryGCD & hybridGCD)
please..thanks - /**
-
* Calculate GCD of this and b. This and b are changed by the computation.
-
*/
-
MutableBigInteger hybridGCD(MutableBigInteger b) {
-
// Use Euclid's algorithm until the numbers are approximately the
-
// same length, then use the binary GCD algorithm to find the GCD.
-
MutableBigInteger a = this;
-
MutableBigInteger q = new MutableBigInteger(),
-
r = new MutableBigInteger();
-
- while (b.intLen != 0)
- {
- if (Math.abs(a.intLen - b.intLen) < 2)
- return a.binaryGCD(b);
-
a.divide(b, q, r);
-
MutableBigInteger swapper = a;
-
a = b; b = r; r = swapper;
-
}
-
return a;
-
}
What it's used for can be anything where one fells they need the gcd and when it calls which method is actually explained by the comment there : // Use Euclid's algorithm until the numbers are approximately the
// same length, then use the binary GCD algorithm to find the GCD.
What it's used for can be anything where one fells they need the gcd and when it calls which method is actually explained by the comment there : // Use Euclid's algorithm until the numbers are approximately the
// same length, then use the binary GCD algorithm to find the GCD.
meaning to say, if I need to write one calculation program to test :
45.gcd(5) or gcd (45, 5) >>> it will call hybrid function and binary both?
Sorry, I need to paste long codes here to show my query .....thanks
Need help, If someone has experience in core java class - MutableBigInteger, please share some with me. BinaryGCD here is what for...Let say I have gcd(45, 5) is that involves with binaryGCD(MutableBigInteger v)) too?
Thankss
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 ...
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |