Skip to content

Commit

Permalink
Change 'typeFraction' to 'typeMantissa' in FloatImmediate
Browse files Browse the repository at this point in the history
This is better aligned with conventions and the rest of the code.
  • Loading branch information
FrancescoConti committed Nov 9, 2024
1 parent 7a0f666 commit a4c6604
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions Deeploy/AbstractDataTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def checkValue(cls, value: Union[int, Iterable[int]], ctxt: Optional[_NetworkCon


class FloatImmediate(Immediate[Union[float, Iterable[float]], _ImmediateType]):
# FIXME: check typeFraction vs typeMantissa
typeFraction: int #: int: Represents the number of bits reserved for the fraction part
typeMantissa: int #: int: Represents the number of bits reserved for the mantissa part
typeExponent: int #: int: Represents the number of bits reserved for the exponent part

@_classproperty
Expand All @@ -253,7 +252,7 @@ def typeExponentOffset(cls) -> int:
@classmethod
def partialOrderUpcast(cls, otherCls: Type[Immediate]) -> bool:
if issubclass(otherCls, FloatImmediate):
return cls.typeFraction >= otherCls.typeFraction and cls.typeExponent >= otherCls.typeExponent
return cls.typeMantissa >= otherCls.typeMantissa and cls.typeExponent >= otherCls.typeExponent
else:
return False

Expand Down Expand Up @@ -296,8 +295,8 @@ def checkValue(cls, value: Union[float, Iterable[float]], ctxt: Optional[_Networ
if (cls.typeExponentOffset + exponent) > cls.typeExponentMax or (cls.typeExponentOffset + exponent) < 0:
return False

# Check if mantissa is representable. Implicit assumption is that cls.typeFraction < 52 (like in FP64)
truncated_mantissa = 1 + math.floor((2**cls.typeFraction) * (mantissa - 1)) / (2**cls.typeFraction)
# Check if mantissa is representable. Implicit assumption is that cls.typeMantissa < 52 (like in FP64)
truncated_mantissa = 1 + math.floor((2**cls.typeMantissa) * (mantissa - 1)) / (2**cls.typeMantissa)
if math.fabs(truncated_mantissa - mantissa) > 0.0:
return False

Expand Down
4 changes: 2 additions & 2 deletions Deeploy/CommonExtensions/DataTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class uint64_t(IntegerImmediate):
class float16alt(FloatImmediate):
typeName = "float16alt"
typeWidth = 16
typeFraction = 7
typeMantissa = 7
typeExponent = 8


class float32(FloatImmediate):
typeName = "float"
typeWidth = 32
typeFraction = 23
typeMantissa = 23
typeExponent = 8


Expand Down

0 comments on commit a4c6604

Please sign in to comment.