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);
-
}
Mar 19 '07
19 6456
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\suga r\math directory contains classes:
GeneralMath
MutableBigInteg erMutant
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\suga r\math directory contains classes:
GeneralMath
MutableBigInteg erMutant
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\BigA l\bigal-src\
inside there contains:
jonelo\bigal\ * 3 classes: Main, Algorithm, BigAlException
jonelo\sugar\ma th\ * classes: GeneralMath, BigIntMutant, MutableBigInteg erMutant
jonelo\sugar\ut il\ *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.BigIn teger;
import java.math.BigDe cimal;
import jonelo.sugar.ma th.GeneralMath;
import jonelo.sugar.ma th.BigIntMutant ;
import jonelo.sugar.ma th.MutableBigIn tegerMutant;
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\BigA l\bigal-src\
inside there contains:
jonelo\bigal\ * 3 classes: Main, Algorithm, BigAlException
jonelo\sugar\ma th\ * classes: GeneralMath, BigIntMutant, MutableBigInteg erMutant
jonelo\sugar\ut il\ *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.BigIn teger;
import java.math.BigDe cimal;
import jonelo.sugar.ma th.GeneralMath;
import jonelo.sugar.ma th.BigIntMutant ;
import jonelo.sugar.ma th.MutableBigIn tegerMutant;
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 - MutableBigInteg er, please share some with me. BinaryGCD here is what for...Let say I have gcd(45, 5) is that involves with binaryGCD(Mutab leBigInteger 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 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 would be used in Quantum Mechanics/QED for example
perhaps to calculate probabilities. I'm using it...
|
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 LISP has
rationals as far as I can tell. Because CL supports keyword arguments,
it has a wider range...
|
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 write and the conversations they
have --- Occam's Razor points to this explanation. For example,...
|
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 variable array
int mortgage calculator
|
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 they fit plus I want to then be able to tell them how much weight they need to loss (or gain if...
| |
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)
|
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!
|
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 sounds with C++?
|
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
in the C#.Net can be found here:
http://www.codeproject.com/KB/cs/biginteger.aspx
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |