Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 93b9561

Browse files
Add files via upload
1 parent 26d81c0 commit 93b9561

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2745
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*----------------------------------------------------------------------------------------------------------------------
2+
Complex sınıfı
3+
----------------------------------------------------------------------------------------------------------------------*/
4+
package org.csystem.math;
5+
6+
import static java.lang.Math.sqrt;
7+
8+
public class Complex {
9+
private static Complex add(double re1, double im1, double re2, double im2)
10+
{
11+
return new Complex(re1 + re2, im1 + im2);
12+
}
13+
14+
private static Complex sub(double re1, double im1, double re2, double im2)
15+
{
16+
return add(re1, im1, -re2, -im2);
17+
}
18+
19+
public double re, im;
20+
21+
public Complex()
22+
{}
23+
24+
public Complex(double re)
25+
{
26+
this.re = re;
27+
}
28+
29+
public Complex(double re, double im)
30+
{
31+
this.re = re;
32+
this.im = im;
33+
}
34+
35+
public Complex getConjugate()
36+
{
37+
Complex z = new Complex();
38+
39+
z.re = re;
40+
z.im = -im;
41+
42+
return z;
43+
}
44+
45+
public double getNorm()
46+
{
47+
return sqrt(re * re + im * im);
48+
}
49+
50+
public static Complex add(double re, double im, Complex z)
51+
{
52+
return add(re, im, z.re, z.im);
53+
}
54+
55+
public Complex add(Complex z)
56+
{
57+
return add(re, im, z.re, z.im);
58+
}
59+
60+
public Complex add(double x, double y)
61+
{
62+
return add(re, im, x, y);
63+
}
64+
65+
public static Complex sub(double re, double im, Complex z)
66+
{
67+
return sub(re, im, z.re, z.im);
68+
}
69+
70+
public Complex sub(Complex z)
71+
{
72+
return sub(re, im, z.re, z.im);
73+
}
74+
75+
public Complex sub(double x, double y)
76+
{
77+
return sub(re, im, x, y);
78+
}
79+
80+
public String toString()
81+
{
82+
return String.format("|%.2f + i * %.2f| = %f", re, im, this.getNorm());
83+
}
84+
}
85+
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/*----------------------------------------------------------------------------------------------------------------------
2+
Rational sınıfı
3+
----------------------------------------------------------------------------------------------------------------------*/
4+
package org.csystem.math;
5+
6+
public class Rational {
7+
private int m_a, m_b;
8+
9+
private static Rational add(int a1, int b1, int a2, int b2)
10+
{
11+
return new Rational(a1 * b2 + a2 * b1, b1 * b2);
12+
}
13+
14+
private static Rational sub(int a1, int b1, int a2, int b2)
15+
{
16+
return add(a1, b1, -a2, b2);
17+
}
18+
19+
private static Rational mul(int a1, int b1, int a2, int b2)
20+
{
21+
return new Rational(a1 * a2, b1 * b2);
22+
}
23+
24+
private static Rational div(int a1, int b1, int a2, int b2)
25+
{
26+
return mul(a1, b1, b2, a2);
27+
}
28+
29+
private static void control(int a, int b)
30+
{
31+
if (b == 0) {
32+
if (a == 0)
33+
throw new RationalException("Belirsiz", RationalExceptionStatus.INDEFINITE);
34+
35+
throw new RationalException("Tanımsız", RationalExceptionStatus.UNDEFINED);
36+
}
37+
}
38+
39+
private void simplify()
40+
{
41+
int a = Math.abs(m_a);
42+
int b = m_b;
43+
int min = Math.min(a, b);
44+
45+
for (int i = min; i >= 2; --i) {
46+
if (a % i == 0 && b % i == 0) {
47+
m_a /= i;
48+
m_b /= i;
49+
break;
50+
}
51+
}
52+
}
53+
54+
private void setSigns()
55+
{
56+
if (m_b < 0) {
57+
m_a = -m_a;
58+
m_b = -m_b;
59+
}
60+
}
61+
62+
private void set(int a, int b)
63+
{
64+
m_a = a;
65+
if (m_a == 0) {
66+
m_b = 1;
67+
return;
68+
}
69+
m_b = b;
70+
this.setSigns();
71+
this.simplify();
72+
}
73+
74+
public Rational()
75+
{
76+
m_b = 1;
77+
}
78+
79+
public Rational(int a)
80+
{
81+
m_a = a;
82+
m_b = 1;
83+
}
84+
85+
public Rational(int a, int b)
86+
{
87+
control(a, b);
88+
this.set(a, b);
89+
}
90+
91+
public int getNumerator()
92+
{
93+
return m_a;
94+
}
95+
96+
public void setNumerator(int val)
97+
{
98+
if (m_a == val)
99+
return;
100+
101+
this.set(val, m_b);
102+
}
103+
104+
public int getDenominator()
105+
{
106+
return m_b;
107+
}
108+
109+
public void setDenominator(int val)
110+
{
111+
if (m_b == val)
112+
return;
113+
114+
control(m_a, val);
115+
this.set(m_a, val);
116+
}
117+
118+
public void setRational(int a, int b)
119+
{
120+
if (a == m_a || b == m_b)
121+
return;
122+
123+
control(a, b);
124+
this.set(a, b);
125+
}
126+
127+
public double getRealValue()
128+
{
129+
return (double)m_a / m_b;
130+
}
131+
132+
//add methods
133+
public static Rational add(int val, Rational r)
134+
{
135+
return add(val, 1, r.m_a, r.m_b);
136+
}
137+
138+
public Rational add(int val)
139+
{
140+
return add(m_a, m_b, val, 1);
141+
}
142+
143+
public Rational add(Rational r)
144+
{
145+
return add(m_a, m_b, r.m_a, r.m_b);
146+
}
147+
148+
//sub methods
149+
public static Rational sub(int val, Rational r)
150+
{
151+
return sub(val, 1, r.m_a, r.m_b);
152+
}
153+
154+
public Rational sub(int val)
155+
{
156+
return sub(m_a, m_b, val, 1);
157+
}
158+
159+
public Rational sub(Rational r)
160+
{
161+
return sub(m_a, m_b, r.m_a, r.m_b);
162+
}
163+
164+
//multiply methods
165+
public static Rational mul(int val, Rational r)
166+
{
167+
return mul(val, 1, r.m_a, r.m_b);
168+
}
169+
170+
public Rational mul(int val)
171+
{
172+
return mul(m_a, m_b, val, 1);
173+
}
174+
175+
public Rational mul(Rational r)
176+
{
177+
return mul(m_a, m_b, r.m_a, r.m_b);
178+
}
179+
180+
//div methods
181+
public static Rational div(int val, Rational r)
182+
{
183+
return div(val, 1, r.m_a, r.m_b);
184+
}
185+
186+
public Rational div(int val)
187+
{
188+
return div(m_a, m_b, val, 1);
189+
}
190+
191+
public Rational div(Rational r)
192+
{
193+
return div(m_a, m_b, r.m_a, r.m_b);
194+
}
195+
196+
//inc methods
197+
public void inc()
198+
{
199+
this.inc(1);
200+
}
201+
202+
public void inc(int val)
203+
{
204+
m_a += val * m_b;
205+
}
206+
207+
//dec methods
208+
public void dec()
209+
{
210+
this.dec(1);
211+
}
212+
213+
public void dec(int val)
214+
{
215+
this.inc(-val);
216+
}
217+
218+
//pow method
219+
public Rational pow(int n)
220+
{
221+
return new Rational((int)Math.pow(m_a, n), (int)Math.pow(m_b, n));
222+
}
223+
224+
public String toString()
225+
{
226+
return String.format("%d / %d = %.2f", m_a, m_b, this.getRealValue());
227+
}
228+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.csystem.math;
2+
3+
public class RationalException extends NumberFormatException {
4+
private final RationalExceptionStatus m_rationalExceptionStatus;
5+
6+
public RationalException(String message, RationalExceptionStatus rationalExceptionStatus)
7+
{
8+
super(message);
9+
m_rationalExceptionStatus = rationalExceptionStatus;
10+
}
11+
12+
public RationalExceptionStatus getRationalExceptionStatus()
13+
{
14+
return m_rationalExceptionStatus;
15+
}
16+
17+
public String getMessage()
18+
{
19+
return String.format("Message:%s, Exception Status:%s", super.getMessage(), m_rationalExceptionStatus);
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.csystem.math;
2+
3+
public enum RationalExceptionStatus {
4+
UNDEFINED, INDEFINITE
5+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /