Class myMath

java.lang.Object
  |
  +--myMath

public class myMath
extends java.lang.Object

This library is now under construction.

まだ開発中の不完全バージョンです。

ソースとかはこのへん

This is a library for floated-pointed-number. On J2ME, we can't use either "double" nor "float", so we cannot use pointed-number at default.

On the case of J-PHONE's JavaAppli, J-PHONE's JBlend (that is the platform of J-PHONE's Java apolicatoins) has FixedPointed Class and with it we can use pointed-number at a brief accuracy. J-PHONE is a Japanese campany of cellur phones and releases phones that can run Java applications. For more information, see http://www.dp.j-phone.com/.

On the other case, in addition to the J-PHONE's case of requiring more accuracy, we can use MathFP library. This library is made in 64bit and on the most of the cases we can manage with this library.

But both of these libraries are constructed on FixedPoint method, so on some cases we across to calcuration errors. For example, "10000 * 0.0001" results "0.9997" on MathFP. This is caused by a rounded error and buiding on FixedPoint method we cannot avoid it.

To avoid rounded error, the library should be built on FloatedPoint method. For my searching, I found that there existed no pointed-number library that is built on FloatedPoint method. So I decided to make it by myself, and now I released this library.

You can use this library freely almost all of the cases, but only when you customize this library and republish it, please tell me and also tell the users of your customized library the truth that it is a customization of this original library. It is not necessary to publish with sources, which is the deference of GPL. I hope this library will become a much help to you.

Thank you. by rarul

An instance of this library uses one long and an int. And most of the method will cost much machine power. So when you think of using this library on a poor platform, I advise you should not use this library.


Field Summary
static myMath CON_E
          Instance of mathematical e.
static myMath CON_PI
          Instance os mathmatical PI.
static int prec
          Accuracy of this library.
 
Constructor Summary
myMath()
          Default constructor.
myMath(long in)
          Construct with setting number.
myMath(long in, int i)
          Construct with setting number.
myMath(myMath b)
          Make clone of b.
myMath(java.lang.String str)
          Construct with setting number.
 
Method Summary
 void add(myMath b)
          Add b to this and set the result.
static myMath add(myMath a, myMath b)
          Add a to b and return the result.
 void cos()
           
 void div(myMath b)
          Div this by b and set the result.
static myMath div(myMath a, myMath b)
          Div a by b and return the result.
static long fact(int n)
          Calculate n!.
 myMath getDecimal()
           
 long getInteger()
          Return the integer part.
static boolean max(myMath n, myMath m)
          If n>=m then return true.
 void Mod(myMath b)
           
static myMath Mod(myMath a, myMath b)
           
 void mul(myMath b)
          Mul b to this and set the result.
static myMath mul(myMath a, myMath b)
          Mul a to b and return the result.
static long power(int n, int m)
          Calculate n^m and return it.
 void set(long in)
          make [in] number.
 void set(long in, int i)
          make in*10^i number.
 void set(myMath b)
          Copy b.
 void set(java.lang.String str)
          make [str] number.
 void sin()
           
 void sub(myMath b)
          Sub b to this and set the result.
static myMath sub(myMath a, myMath b)
          Sub b from a and return the result.
 java.lang.String toString()
          Print in a format of using "E".
 java.lang.String toStringD()
          Print in a format of non using "E"
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

prec

public static final int prec
Accuracy of this library. You use 1.23456789 valid pointed-number on the default. For most cases, you should not change this variable.

CON_E

public static final myMath CON_E
Instance of mathematical e. That is almost 2.718281828

CON_PI

public static final myMath CON_PI
Instance os mathmatical PI. That is almost 3.141592654
Constructor Detail

myMath

public myMath()
Default constructor. This make "0".

myMath

public myMath(long in)
Construct with setting number.
See Also:
set(long).

myMath

public myMath(java.lang.String str)
Construct with setting number.
See Also:
set(String).

myMath

public myMath(long in,
              int i)
Construct with setting number.
See Also:
set(long,int).

myMath

public myMath(myMath b)
Make clone of b.
See Also:
set(myMath).
Method Detail

set

public void set(myMath b)
Copy b.
See Also:
myMath( myMath).

set

public void set(long in)
make [in] number. if in==100 then make 1.00E2
See Also:
myMath( long).

set

public void set(long in,
                int i)
make in*10^i number. if in=100 and i=2 then make 1.00E4
See Also:
myMath( long, int).

set

public void set(java.lang.String str)
make [str] number. formats are (num) or (num"E"int)
(let num "int.int" or "int")
for examble
1.1, 10, 10E1, 1.1E0, 0.1E2,
1.23E-12 ect..
See Also:
myMath( String).

add

public void add(myMath b)
Add b to this and set the result. So this method is as same as following. ("a" means the instance to call this method.)
a = a + b
See Also:
add( myMath, myMath)

sub

public void sub(myMath b)
Sub b to this and set the result. So this method is as same as following. ("a" means the instance to call this method.)
a = a - b
See Also:
sub( myMath, myMath)

mul

public void mul(myMath b)
Mul b to this and set the result. So this method is as same as following. ("a" means the instance to call this method.)
a = a * b
See Also:
mul( myMath, myMath)

div

public void div(myMath b)
Div this by b and set the result. So this method is as same as following. ("a" means the instance to call this method.)
a = a / b
See Also:
div( myMath, myMath)

add

public static myMath add(myMath a,
                         myMath b)
Add a to b and return the result. So this method is as same as following.
return a + b
See Also:
add( myMath)

sub

public static myMath sub(myMath a,
                         myMath b)
Sub b from a and return the result. So this method is as same as following.
return a - b
See Also:
sub( myMath)

mul

public static myMath mul(myMath a,
                         myMath b)
Mul a to b and return the result. So this method is as same as following.
return a * b
See Also:
mul( myMath)

div

public static myMath div(myMath a,
                         myMath b)
Div a by b and return the result. So this method is as same as following.
return a / b
See Also:
div( myMath)

fact

public static long fact(int n)
Calculate n!. n! is as following
n! = n * (n-1)! , (n>=2)
n! = 1 , ( n = 0, 1)

power

public static long power(int n,
                         int m)
Calculate n^m and return it. n^m is as following
n^m = n * n^(m-1) , (m>=1)
n^0 = 1

max

public static boolean max(myMath n,
                          myMath m)
If n>=m then return true. This method will return earlier than sub( myMath, myMath) or div( myMath, myMath).
See Also:
sub( myMath, myMath), div( myMath, myMath)

getInteger

public long getInteger()
Return the integer part. n's integer part means max integer p, as following.
n = p + q , ( 0<=q<1)
For example, integer part of 5.01 is 5, -3,22 -4, etc.

toString

public java.lang.String toString()
Print in a format of using "E".
That is, [111] -> "1.11E2" , [12.34] -> "1.234E1" , etc.
Overrides:
toString in class java.lang.Object
See Also:
toStringD()

toStringD

public java.lang.String toStringD()
Print in a format of non using "E"
See Also:
toString()

getDecimal

public myMath getDecimal()

Mod

public void Mod(myMath b)

Mod

public static myMath Mod(myMath a,
                         myMath b)

cos

public void cos()

sin

public void sin()