forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): use StrictMath for pow(a,b)
- Loading branch information
1 parent
c136a26
commit 3cfc30f
Showing
14 changed files
with
114 additions
and
6 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,30 @@ | ||
package org.tron.common.math; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.tron.core.store.DynamicPropertiesStore; | ||
|
||
@Component | ||
@Slf4j(topic = "math") | ||
public class Maths { | ||
|
||
private static DynamicPropertiesStore dynamicPropertiesStore; | ||
|
||
@Autowired | ||
public Maths(@Autowired DynamicPropertiesStore dynamicPropertiesStore) { | ||
Maths.dynamicPropertiesStore = dynamicPropertiesStore; | ||
} | ||
|
||
/** | ||
* Returns the value of the first argument raised to the power of the second argument. | ||
* Note dynamicPropertiesStore must be inited before calling this method. | ||
* @param a the base. | ||
* @param b the exponent. | ||
* @return the value {@code a}<sup>{@code b}</sup>. | ||
*/ | ||
public static double pow(double a, double b) { | ||
boolean useStrictMath = dynamicPropertiesStore.allowStrictMath(); | ||
return useStrictMath ? StrictMathWrapper.pow(a, b) : MathWrapper.pow(a, b); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.tron.common.math; | ||
|
||
public class MathWrapper { | ||
|
||
public static double pow(double a, double b) { | ||
return Math.pow(a, b); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
common/src/main/java/org/tron/common/math/StrictMathWrapper.java
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,8 @@ | ||
package org.tron.common.math; | ||
|
||
public class StrictMathWrapper { | ||
|
||
public static double pow(double a, double b) { | ||
return StrictMath.pow(a, b); | ||
} | ||
} |
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
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