Package ghidra.pcode.floatformat
Class BigFloat
- java.lang.Object
-
- ghidra.pcode.floatformat.BigFloat
-
- All Implemented Interfaces:
java.lang.Comparable<BigFloat>
public class BigFloat extends java.lang.Object implements java.lang.Comparable<BigFloat>
An IEEE 754 floating point class.Values represented:
- QUIET_NAN, SIGNALED_NAN
- -INF, +INF
- value = sign * unscaled * 2 ^ (scale-fracbits)
Operations compute exact result then round to nearest even.
-
-
Constructor Summary
Constructors Constructor Description BigFloat(int fracbits, int expbits, ghidra.pcode.floatformat.FloatKind kind, int sign, java.math.BigInteger unscaled, int scale)
Construct a BigFloat.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abs()
this=abs(this)
static BigFloat
abs(BigFloat a)
void
add(BigFloat other)
this+=other
static BigFloat
add(BigFloat a, BigFloat b)
protected void
add0(BigFloat other)
void
ceil()
this=ceil(this)
static BigFloat
ceil(BigFloat a)
int
compareTo(BigFloat other)
BigFloat
copy()
protected void
copyFrom(BigFloat other)
void
div(BigFloat other)
this/=other
static BigFloat
div(BigFloat a, BigFloat b)
boolean
equals(java.lang.Object obj)
void
floor()
this=floor(this)
static BigFloat
floor(BigFloat a)
protected int
getLeadBitPos()
int
hashCode()
static BigFloat
infinity(int fracbits, int expbits, int sign)
protected void
internalRound(boolean eps)
This function is used internally to round after a computation.boolean
isInfinite()
boolean
isNaN()
boolean
isNormal()
boolean
isZero()
protected void
makeQuietNaN()
protected void
makeSignalingNaN()
protected void
makeZero()
void
mul(BigFloat other)
this*=other
static BigFloat
mul(BigFloat a, BigFloat b)
void
negate()
this*=-1
static BigFloat
negate(BigFloat a)
static BigFloat
quietNaN(int fracbits, int expbits, int sign)
Return the BigFloat with the given number of bits representing (quiet) NaN.void
round()
this=round(this)
static BigFloat
round(BigFloat a)
protected void
scaleUpTo(int newLength)
void
sqrt()
this=sqrt(this)
static BigFloat
sqrt(BigFloat a)
void
sub(BigFloat other)
this-=other
static BigFloat
sub(BigFloat a, BigFloat b)
protected void
sub0(BigFloat other)
java.math.BigDecimal
toBigDecimal()
If finite, the returned BigDecimal is exactly equal to this.java.math.BigInteger
toBigInteger()
java.lang.String
toBinaryString()
void
trunc()
this=trunc(this)
(round toward zero)static BigFloat
trunc(BigFloat a)
static BigFloat
valueOf(int fracbits, int expbits, java.math.BigInteger i)
Return the BigFloat with the given number of bits representing the given BigInteger.static BigFloat
zero(int fracbits, int expbits)
Return the BigFloat with the given number of bits representing (positive) zero.static BigFloat
zero(int fracbits, int expbits, int sign)
Return the BigFloat with the given number of bits representing zero.
-
-
-
Constructor Detail
-
BigFloat
public BigFloat(int fracbits, int expbits, ghidra.pcode.floatformat.FloatKind kind, int sign, java.math.BigInteger unscaled, int scale)
Construct a BigFloat. If kind is FINITE, the value issign*unscaled*2^(scale-fracbits)
- Parameters:
fracbits
- number of fractional bitsexpbits
- maximum number of bits in exponentkind
- the Kind, FINITE, INFINITE, ...sign
- +1 or -1unscaled
- the value's mantissascale
- value's scale
-
-
Method Detail
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
valueOf
public static BigFloat valueOf(int fracbits, int expbits, java.math.BigInteger i)
Return the BigFloat with the given number of bits representing the given BigInteger.- Parameters:
fracbits
- number of fractional bitsexpbits
- number of bits in the exponenti
- an integer- Returns:
- a BigFloat representing i
-
zero
public static BigFloat zero(int fracbits, int expbits, int sign)
Return the BigFloat with the given number of bits representing zero.- Parameters:
fracbits
- number of fractional bitsexpbits
- number of bits in the exponentsign
- +1 or -1- Returns:
- a BigFloat representing +zero or -zero
-
zero
public static BigFloat zero(int fracbits, int expbits)
Return the BigFloat with the given number of bits representing (positive) zero.- Parameters:
fracbits
- number of fractional bitsexpbits
- number of bits in the exponent- Returns:
- a BigFloat representing +zero
-
infinity
public static BigFloat infinity(int fracbits, int expbits, int sign)
- Parameters:
fracbits
- number of fractional bitsexpbits
- number of bits in the exponentsign
- +1 or -1- Returns:
- +inf or -inf
-
quietNaN
public static BigFloat quietNaN(int fracbits, int expbits, int sign)
Return the BigFloat with the given number of bits representing (quiet) NaN.- Parameters:
fracbits
- number of fractional bitsexpbits
- number of bits in the exponentsign
- +1 or -1- Returns:
- a BigFloat representing (quiet) NaN
-
scaleUpTo
protected void scaleUpTo(int newLength)
-
isNormal
public boolean isNormal()
- Returns:
true
if this BigFloat is FINITE and normal
-
internalRound
protected void internalRound(boolean eps)
This function is used internally to round after a computation.Assume that the true value is
sign * (unscaled + eps) * 2 ^ (scale-fracbits) and unscaled.bitLength() > fracbits+1 (or the value is subnormal with at least 1 bit of extra precision)
- Parameters:
eps
- < 1
-
getLeadBitPos
protected int getLeadBitPos()
-
toBigDecimal
public java.math.BigDecimal toBigDecimal()
If finite, the returned BigDecimal is exactly equal to this. If not finite, one of the FloatFormat.BIG_* constants is returned.- Returns:
- a BigDecimal
-
toBinaryString
public java.lang.String toBinaryString()
-
makeSignalingNaN
protected void makeSignalingNaN()
-
makeQuietNaN
protected void makeQuietNaN()
-
isNaN
public boolean isNaN()
- Returns:
true
if this BigFloat is NaN
-
makeZero
protected void makeZero()
-
isInfinite
public boolean isInfinite()
- Returns:
true
if this BigFloat is infinite
-
isZero
public boolean isZero()
- Returns:
true
if this BigFloat is zero
-
copy
public BigFloat copy()
- Returns:
- a copy of this BigFloat
-
copyFrom
protected void copyFrom(BigFloat other)
-
div
public static BigFloat div(BigFloat a, BigFloat b)
- Parameters:
a
- a BigFloatb
- a BigFloat- Returns:
a/b
-
div
public void div(BigFloat other)
this/=other
- Parameters:
other
- a BigFloat
-
mul
public static BigFloat mul(BigFloat a, BigFloat b)
- Parameters:
a
- a BigFloatb
- a BigFloat- Returns:
a*b
-
mul
public void mul(BigFloat other)
this*=other
- Parameters:
other
- a BigFloat
-
add
public static BigFloat add(BigFloat a, BigFloat b)
- Parameters:
a
- a BigFloatb
- a BigFloat- Returns:
a+b
-
add
public void add(BigFloat other)
this+=other
- Parameters:
other
- a BigFloat
-
sub
public static BigFloat sub(BigFloat a, BigFloat b)
- Parameters:
a
- a BigFloatb
- a BigFloat- Returns:
a-b
-
sub
public void sub(BigFloat other)
this-=other
- Parameters:
other
- a BigFloat
-
add0
protected void add0(BigFloat other)
-
sub0
protected void sub0(BigFloat other)
-
sqrt
public static BigFloat sqrt(BigFloat a)
- Parameters:
a
- a BigFloat- Returns:
- the square root of
a
-
sqrt
public void sqrt()
this=sqrt(this)
Square root by abacus algorithm, Martin Guy @ UKC, June 1985. From a book on programming abaci by Mr C. Woo. Argument is a positive integer, as is result.
adapted from http://medialab.freaknet.org/martin/src/sqrt/sqrt.c
-
floor
public void floor()
this=floor(this)
-
ceil
public void ceil()
this=ceil(this)
-
trunc
public static BigFloat trunc(BigFloat a)
- Parameters:
a
- a BigFloat- Returns:
trunc(a)
(round toward zero)
-
trunc
public void trunc()
this=trunc(this)
(round toward zero)
-
negate
public void negate()
this*=-1
-
abs
public void abs()
this=abs(this)
-
toBigInteger
public java.math.BigInteger toBigInteger()
- Returns:
- the truncated integer form of this BigFloat
-
round
public void round()
this=round(this)
-
-