程序包 cn.wjybxx.base

类 MathCommon

java.lang.Object
cn.wjybxx.base.MathCommon

public class MathCommon extends Object
作者:
wjybxx date 2023/3/31
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final float
     
    static final float
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final long
    有符号48位整数的最大值(140737488355327L)
    static final long
    有符号48位整数的最小值(-140737488355328L)
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final int
     
    static final Random
     
    static final long
    32位无符号整数的最大值
    static final long
    48位无符号整数的最大值
  • 构造器概要

    构造器
    限定符
    构造器
    说明
    protected
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static double
    clamp(double value, double min, double max)
     
    static float
    clamp(float value, float min, float max)
     
    static int
    clamp(int value, int min, int max)
     
    static long
    clamp(long value, long min, long max)
     
    static double
    clamp01(double value)
     
    static float
    clamp01(float value)
     
    static long
    composeIntToLong(int higher, int lower)
    将两个int聚合为long
    static int
    composeShortToInt(short higher, short lower)
    将两个short聚合为int
    static int
    higherIntOfLong(long value)
     
    static short
    higherShortOfInt(int value)
     
    static boolean
    isBetween(double value, double min, double max)
     
    static boolean
    isBetween(float value, float min, float max)
     
    static boolean
    isBetween(int value, int min, int max)
     
    static boolean
    isBetween(long value, long min, long max)
     
    static boolean
    isBetween(short value, short min, short max)
     
    static boolean
    isEqual(double a, double b)
     
    static boolean
    isEqual(double a, double b, double tolerance)
     
    static boolean
    isEqual(float a, float b)
     
    static boolean
    isEqual(float a, float b, float tolerance)
     
    static boolean
    isEven(int x)
     
    static boolean
    isInt48(long value)
    判断一个数是否是有效的int48
    static boolean
    isOdd(int x)
     
    static boolean
    isPowerOfTwo(int x)
    判断一个值是否是2的整次幂
    static boolean
    isUInt32(long value)
    判断一个数是否是有效的uint32
    static boolean
    isUInt48(long value)
    判断一个数是否是有效的uint48
    static boolean
    isZero(double value)
     
    static boolean
    isZero(double value, double tolerance)
     
    static boolean
    isZero(float value)
     
    static boolean
    isZero(float value, float tolerance)
     
    static int
    lowerIntOfLong(long value)
     
    static short
    lowerShortOfInt(int value)
     
    static double
    max(double a, double b, double c)
     
    static float
    max(float a, float b, float c)
     
    static int
    max(int a, int b, int c)
     
    static long
    max(long a, long b, long c)
     
    static int
    max(short a, short b)
     
    static int
    max(short a, short b, short c)
     
    static double
    min(double a, double b, double c)
     
    static float
    min(float a, float b, float c)
     
    static int
    min(int a, int b, int c)
     
    static long
    min(long a, long b, long c)
     
    static int
    min(short a, short b)
     
    static int
    min(short a, short b, short c)
     
    static int
    multiplyToInt(short a, short b)
    两个short安全相乘,返回一个int,避免越界;相乘之后再强转可能越界.
    static long
    multiplyToLong(int a, int b)
    两个int安全相乘,返回一个long,避免越界;相乘之后再强转可能越界。
    static int
    nextPowerOfTwo(int num)
    计算num最接近下一个整2次幂;如果自身是2的整次幂,则会返回自身
    static long
    nextPowerOfTwo(long num)
    计算num最接近下一个整2次幂;如果自身是2的整次幂,则会返回自身

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • MAX_POWER_OF_TWO

      public static final int MAX_POWER_OF_TWO
      另请参阅:
    • LONG_MAX_POWER_OF_TWO

      public static final long LONG_MAX_POWER_OF_TWO
      另请参阅:
    • FLOAT_ROUNDING_ERROR

      public static final float FLOAT_ROUNDING_ERROR
      另请参阅:
    • DOUBLE_ROUNDING_ERROR

      public static final float DOUBLE_ROUNDING_ERROR
      另请参阅:
    • UINT32_MAX_VALUE

      public static final long UINT32_MAX_VALUE
      32位无符号整数的最大值
      另请参阅:
    • UINT48_MAX_VALUE

      public static final long UINT48_MAX_VALUE
      48位无符号整数的最大值
      另请参阅:
    • INT48_MAX_VALUE

      public static final long INT48_MAX_VALUE
      有符号48位整数的最大值(140737488355327L)
      另请参阅:
    • INT48_MIN_VALUE

      public static final long INT48_MIN_VALUE
      有符号48位整数的最小值(-140737488355328L)
      另请参阅:
    • INT_MASK4

      public static final int INT_MASK4
      另请参阅:
    • INT_MASK3

      public static final int INT_MASK3
      另请参阅:
    • INT_MASK2

      public static final int INT_MASK2
      另请参阅:
    • INT_MASK1

      public static final int INT_MASK1
      另请参阅:
    • LONG_MASK8

      public static final long LONG_MASK8
      另请参阅:
    • LONG_MASK7

      public static final long LONG_MASK7
      另请参阅:
    • LONG_MASK6

      public static final long LONG_MASK6
      另请参阅:
    • LONG_MASK5

      public static final long LONG_MASK5
      另请参阅:
    • LONG_MASK4

      public static final long LONG_MASK4
      另请参阅:
    • LONG_MASK3

      public static final long LONG_MASK3
      另请参阅:
    • LONG_MASK2

      public static final long LONG_MASK2
      另请参阅:
    • LONG_MASK1

      public static final long LONG_MASK1
      另请参阅:
    • SHARED_RANDOM

      public static final Random SHARED_RANDOM
  • 构造器详细资料

    • MathCommon

      protected MathCommon()
  • 方法详细资料

    • isPowerOfTwo

      public static boolean isPowerOfTwo(int x)
      判断一个值是否是2的整次幂
    • nextPowerOfTwo

      public static int nextPowerOfTwo(int num)
      计算num最接近下一个整2次幂;如果自身是2的整次幂,则会返回自身
    • nextPowerOfTwo

      public static long nextPowerOfTwo(long num)
      计算num最接近下一个整2次幂;如果自身是2的整次幂,则会返回自身
    • isEven

      public static boolean isEven(int x)
      返回:
      如果给定参数是【偶数】则返回true
    • isOdd

      public static boolean isOdd(int x)
      返回:
      如果给定参数是【奇数】则返回true
    • isUInt32

      public static boolean isUInt32(long value)
      判断一个数是否是有效的uint32
    • isUInt48

      public static boolean isUInt48(long value)
      判断一个数是否是有效的uint48
    • isInt48

      public static boolean isInt48(long value)
      判断一个数是否是有效的int48
    • composeIntToLong

      public static long composeIntToLong(int higher, int lower)
      将两个int聚合为long
      参数:
      higher - 高32位
      lower - 低32位
      返回:
      long
    • higherIntOfLong

      public static int higherIntOfLong(long value)
    • lowerIntOfLong

      public static int lowerIntOfLong(long value)
    • composeShortToInt

      public static int composeShortToInt(short higher, short lower)
      将两个short聚合为int
      参数:
      higher - 高16位
      lower - 低16位
      返回:
      int
    • higherShortOfInt

      public static short higherShortOfInt(int value)
    • lowerShortOfInt

      public static short lowerShortOfInt(int value)
    • multiplyToLong

      public static long multiplyToLong(int a, int b)
      两个int安全相乘,返回一个long,避免越界;相乘之后再强转可能越界。
    • multiplyToInt

      public static int multiplyToInt(short a, short b)
      两个short安全相乘,返回一个int,避免越界;相乘之后再强转可能越界.
    • clamp

      public static int clamp(int value, int min, int max)
    • clamp

      public static long clamp(long value, long min, long max)
    • clamp

      public static float clamp(float value, float min, float max)
    • clamp

      public static double clamp(double value, double min, double max)
    • clamp01

      public static float clamp01(float value)
    • clamp01

      public static double clamp01(double value)
    • min

      public static int min(int a, int b, int c)
    • max

      public static int max(int a, int b, int c)
    • min

      public static long min(long a, long b, long c)
    • max

      public static long max(long a, long b, long c)
    • min

      public static float min(float a, float b, float c)
    • max

      public static float max(float a, float b, float c)
    • min

      public static double min(double a, double b, double c)
    • max

      public static double max(double a, double b, double c)
    • min

      public static int min(short a, short b)
    • max

      public static int max(short a, short b)
    • min

      public static int min(short a, short b, short c)
    • max

      public static int max(short a, short b, short c)
    • isBetween

      public static boolean isBetween(short value, short min, short max)
    • isBetween

      public static boolean isBetween(int value, int min, int max)
    • isBetween

      public static boolean isBetween(long value, long min, long max)
    • isBetween

      public static boolean isBetween(float value, float min, float max)
    • isBetween

      public static boolean isBetween(double value, double min, double max)
    • isZero

      public static boolean isZero(float value)
    • isZero

      public static boolean isZero(float value, float tolerance)
    • isEqual

      public static boolean isEqual(float a, float b)
    • isEqual

      public static boolean isEqual(float a, float b, float tolerance)
    • isZero

      public static boolean isZero(double value)
    • isZero

      public static boolean isZero(double value, double tolerance)
    • isEqual

      public static boolean isEqual(double a, double b)
    • isEqual

      public static boolean isEqual(double a, double b, double tolerance)