-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7208b2
commit 69261fd
Showing
16 changed files
with
1,091 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package dev.progames723.hmmm; | ||
|
||
import java.lang.annotation.Native; | ||
import java.math.BigDecimal; | ||
|
||
public class GMP extends Number { | ||
static { | ||
registerNatives(); | ||
} | ||
|
||
public static void init() { | ||
//yes | ||
} | ||
|
||
@Native | ||
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"}) | ||
private boolean isCleared = false; | ||
|
||
@Override | ||
public native int intValue(); | ||
|
||
@Override | ||
public native long longValue(); | ||
|
||
@Override | ||
public native float floatValue(); | ||
|
||
@Override | ||
public native double doubleValue(); | ||
|
||
public native String getAsString(); | ||
|
||
private static native void registerNatives(); | ||
|
||
public BigDecimal getAsBigDecimal() { | ||
if (getAsString().matches("[^\\-0-9.]")) return BigDecimal.ZERO;//default impl | ||
return new BigDecimal(getAsString()); | ||
} | ||
|
||
public GMP(String string) { | ||
if (!string.matches("[^\\-0-9.]")) create(string); | ||
else create(0); | ||
} | ||
|
||
public GMP() { | ||
this(0); | ||
} | ||
|
||
public GMP(int i) { | ||
this((long) i); | ||
} | ||
|
||
public GMP(long l) { | ||
this((double) l); | ||
} | ||
|
||
public GMP(double d) { | ||
create(d); | ||
} | ||
|
||
public GMP(float f) { | ||
this((double) f); | ||
} | ||
|
||
private native void create(double d); | ||
|
||
private native void create(String s); | ||
|
||
//math operations | ||
public native GMP multiply(GMP gmp); | ||
public native GMP multiply(String string); | ||
public native GMP divide(GMP gmp); | ||
public native GMP divide(String string); | ||
public native GMP pow(GMP gmp); | ||
public native GMP pow(String string); | ||
public native GMP sqrt(); | ||
public GMP nthRoot(GMP gmp) { | ||
GMP temp = new GMP(1); | ||
try {return pow(temp.divide(gmp));} finally {temp.clear();} | ||
} | ||
public GMP nthRoot(String string) { | ||
GMP temp = new GMP(1); | ||
try {return pow(temp.divide(string));} finally {temp.clear();} | ||
} | ||
public native GMP add(GMP gmp); | ||
public native GMP add(String string); | ||
public native GMP subtract(GMP gmp); | ||
public native GMP subtract(String string); | ||
public native GMP ceil(); | ||
public native GMP floor(); | ||
public native GMP abs(); | ||
public native GMP truncate(); | ||
//end of math operations | ||
|
||
//helper methods | ||
public native void clear(); | ||
public static void clear(GMP... gmps) { | ||
for (GMP gmp : gmps) gmp.clear(); | ||
} | ||
public native GMP set(GMP gmp); | ||
public native GMP set(String str); | ||
//end of helper methods | ||
|
||
|
||
@Override | ||
public native boolean equals(Object obj); | ||
|
||
@Override | ||
public int hashCode() { | ||
double precision = (super.hashCode() - getAsBigDecimal().hashCode()) * doubleValue(); | ||
return (int) precision; | ||
} | ||
|
||
public boolean isCleared() { | ||
return isCleared; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.