|
-bottom | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--mmpp.lang.MathFP
fixed point 연산을 하기 위한 클래스 KVM에서 floating point 연산을 지원하지 않기 때문에, 소수점 이하의 값을 갖는 값들을 계산하기 위하여 차선책으로 integer 변수를 활용한 fixed point 연산을 지원한다.
즉 integer변수(32bit)를 2부분으로 나누어서, 상위 20bit을 정수 부분, 하위 12bit을 소수 부분을 표현하는 데 사용한다. fixed point는 floating point와 달리 소수점의 위치가 이동하지 않기 때문에 가질 수 있는 값의 범위가 매우 한정되어 있다. fixed point로 표현할 수 있는 범위는 최대 524287(2^19)에서 최소 -524288(-2^19)이다. 그리고 정확도는 0.000244140625(2^-12)이다.
현재 구현되어 있는 함수는 fixed point로 변환과 역변환 관련(
parseFP(), toInt(), toString()
) 산술 연산 관련(add(),
sub(), multiply(), divide(), abs(), round(), pow(), sqrt(), log(),
exp(), max(), min()
), 삼각함수 관련(sin(), cos(), tan()
asin(), acos(), atan()
)이 있다.
기본적인 사용법은 기존의 값들을 FP로 변경한 뒤, 해당하는 연산을 수행하고, 이를 다시 기존의 형식으로 돌린다.
예1) { int fp, result; fp = MathFP.parseFP("12.563"); result = MathFP.log(fp); System.out.println( MathFP.toString(result) ); }예2) { int fp, result; fp = MathFP.PI/4; result = MathFP.tan(fp); System.out.println( MathFP.toString(result) ); }
Field Summary | |
static int |
E
e에 가장 가까운 fixed point 값 자연 로그 계산 등에 사용된다. |
static int |
MAX_VALUE
fixed point값으로 표현할 수 있는 최대값(fixed point 형식) |
static int |
MAX_VALUE_INT
fixed point값으로 표현할 수 있는 최대값(integer 형식) |
static int |
MIN_VALUE
fixed point값으로 표현할 수 있는 최소값(fixed point 형식) |
static int |
MIN_VALUE_INT
fixed point값으로 표현할 수 있는 최대값(integer point 형식) |
static int |
PI
pi에 가장 가까운 fixed point 값 원주율으로 삼각 함수에 사용된다. |
Method Summary | |
static int |
abs(int i)
첫번째 인자(fixed point)의 절대값을 리턴한다. |
static int |
acos(int r)
주어진 값에 대한 arc cosine값을 구한다. |
static int |
add(int i,
int j)
첫번째 인수(fixed point)와 두번째 인수(fixed point)를 더한 값을 리턴(fixed point)한다. |
static int |
asin(int r)
주어진 값에 대한 arc sine값을 구한다. |
static int |
atan(int r)
주어진 값에 대한 arc tangent값을 구한다. |
static int |
cos(int r)
라디안 값으로 주어진 각도에 대하여 삼각함수 cosine값을 리턴(fixed point)한다. |
static int |
divide(int i,
int j)
첫번째 인수(fixed point)와 두번째 인수(fixed point)를 곱한 값을 리턴(fixed point)한다. |
static int |
exp(int f)
e를 첫번째 인수만큼 제곱하여 리턴(fixed point)한다. |
static int |
log(int f)
첫번째 인자(fixed point)의 자연 로그값을 리턴(fixed point)한다. |
static int |
max(int a,
int b)
첫번째 인수(fixed point)와 두번째 인수(fixed point)를 비교하여 큰 값을 리턴(fixed point)한다. |
static int |
min(int a,
int b)
첫번째 인수(fixed point)와 두번째 인수(fixed point)를 비교하여 작은 값을 리턴(fixed point)한다. |
static int |
multiply(int i,
int j)
첫번째 인수(fixed point)와 두번째 인수(fixed point)를 곱한 값을 리턴(fixed point)한다. |
static int |
parseFP(int f)
일반 integer 값을 fixed point값으로 변경시킨다. fixed point 값의 범위가 한정되어 있기 때문에, MAX_VALUE_INT 와
MIN_VALUE_INT 사이의 범위를 벗어나는 경우 NumberFormatException을 발생시킨다. |
static int |
parseFP(java.lang.String s)
String으로 표현된 변수값을 fixed point값으로 변경시킨다. fixed point 값의 범위가 한정되어 있기 때문에, MAX_VALUE_INT 와
MIN_VALUE_INT 사이의 범위를 벗어나는 경우 NumberFormatException을 발생시킨다.
|
static int |
pow(int b,
int e)
첫번째 인자(fixed point)를 두번째 인자(fixed point)만큼 제곱하여 리턴(fixed point)한다. |
static int |
round(int i)
첫번째 인자(fixed point)의 가장 가까운 정수를 리턴(fixed point)한다. |
static int |
sin(int r)
라디안 값으로 주어진 각도에 대하여 삼각함수 sine값을 리턴(fixed point)한다. |
static int |
sqrt(int i)
첫번째 인자(fixed point)의 제곱근을 리턴(fixed point)한다. |
static int |
sub(int i,
int j)
첫번째 인수(fixed point)와 두번째 인수(fixed point)를 뺀 값을 리턴(fixed point)한다. |
static int |
tan(int r)
라디안 값으로 주어진 각도에 대하여 삼각함수 tangent값을 리턴(fixed point)한다. |
static int |
toInt(int i)
fixed point 변수의 값을 int 값으로 변경한다. |
static java.lang.String |
toString(int f)
fixed point의 String 표현을 돌려준다. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int E
public static final int PI
public static final int MAX_VALUE
public static final int MIN_VALUE
public static final int MAX_VALUE_INT
public static final int MIN_VALUE_INT
Method Detail |
public static int abs(int i)
i
- fixed point integerpublic static int round(int i)
i
- fixed point integerpublic static int pow(int b, int e) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException
지수의 값(두번째 인자)으로 소수부분을 갖는 fixed point의 값도 올 수 있다. 단, 밑이 음수일 경우, 지수가 소수부분을 가지면( (-2)^(1.2) ), 부호의 정의가 애매하므로 IllegalArgumentException을 발생시킨다.
결과값이 fixed point로 표현할 수 있는 범위를 넘어나도 Arithmetic Exception을 발생시킨다.
b
- fixed point integere
- fixed point integerjava.lang.IllegalArgumentException
- 밑이 음수인 경우java.lang.ArithmeticException
- 결과 값이 fixed point로 표현할 수 있는
범위를 벗어날 경우public static int sqrt(int i) throws java.lang.ArithmeticException
인자의 값이 음수일 경우 IllegalArgumentException을 발생시키고, 오버 플로우가 발생하면 ArithmeticException을 발생시킨다.
i
- fixed point integerjava.lang.IllegalArgumentException
- i가 음수인 경우java.lang.ArithmeticException
- 오버플로우 발생할 경우public static int log(int f) throws java.lang.ArithmeticException
첫번째 인자의 값이 음수일 경우 IllegalArgumentException을 발생시키고, 값의 범위에 벗어나도 ArithmeticException을 발생시킨다.
f
- fixed point integerjava.lang.IllegalArgumentException
- f가 음수인 경우java.lang.ArithmeticException
- 계산 결과가 fixed point범위를 벗어나는 경우public static int exp(int f) throws java.lang.ArithmeticException
결과 값이 표현할 수 있는 범위를 벗어나면 ArithmeticException을 발생시킨다.
f
- fixed point integerjava.lang.ArithmeticException
- 오버플로우 발생 시public static int max(int a, int b)
a
- fixed point integerb
- fixed point integerpublic static int min(int a, int b)
a
- fixed point integerb
- fixed point integerpublic static int add(int i, int j)
i
- fixed point integerj
- fixed point integerpublic static int sub(int i, int j)
i
- fixed point integerj
- fixed point integerpublic static int multiply(int i, int j) throws java.lang.ArithmeticException
fixed point로 표현할 수 있는 최대값을 넘길 경우, Arithmetic Exception을 발생시킨다.
i
- fixed point integerj
- fixed point integerjava.lang.ArithmeticException
- 오버플로우 발생 시public static int divide(int i, int j) throws java.lang.ArithmeticException
i
- fixed point integerj
- fixed point integerjava.lang.ArithmeticException
- j가 0인 경우public static int parseFP(int f) throws java.lang.NumberFormatException
MAX_VALUE_INT
와
MIN_VALUE_INT
사이의 범위를 벗어나는 경우 NumberFormatException을 발생시킨다.f
- fixed point로 변경될 integer 값java.lang.NumberFormatException
- 변환한 값이 MAX_VALUE_INT
와 MIN_VALUE_INT
를 벗어나는 경우public static int parseFP(java.lang.String s) throws java.lang.NumberFormatException
MAX_VALUE_INT
와
MIN_VALUE_INT
사이의 범위를 벗어나는 경우 NumberFormatException을 발생시킨다.
예) { int fp = MathFP.parseFP("-1.234"); }
s
- fixed point값으로 변경될 String값java.lang.NumberFormatException
- 변화한 값이 MAX_VALUE_INT
와 MIN_VALUE_INT
사이의 범위를 벗어나는 경우public static int toInt(int i)
반올림을 통해서 integer값으로 변경된다.
public static java.lang.String toString(int f)
public static int cos(int r)
r
- radian 각도를 표현하는 fixed point integerpublic static int sin(int r)
r
- radian 각도를 표현하는 fixed point integerpublic static int tan(int r)
r
- radian 각도를 표현하는 fixed point integerpublic static int acos(int r)
-1과 1사이를 벗어나는 잘못된 입력에 대해서는 IllegalArgumentException을 발생시킨다.
r
- cosine의 값을 나타낼 fixed point 값java.lang.IllegalArgumentException
- r이 -1과 1사이를 벗어나는 경우public static int asin(int r)
-1과 1사이를 벗어나는 잘못된 입력에 대해서는 IllegalArgumentException을 발생시킨다.
r
- sine의 값을 나타낼 fixed point 값java.lang.IllegalArgumentException
- r이 -1과 1사이를 벗어나는 경우public static int atan(int r)
r
- tangent의 값을 나타낼 fixed point 값
|