Skip to content

Commit

Permalink
make of vs from more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 committed Oct 23, 2024
1 parent 5681791 commit a3bd3a5
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FloatingPoint16Value extends FloatingPointValue {
/// Return the [FloatingPoint16Value] representing the constant specified
factory FloatingPoint16Value.getFloatingPointConstant(
FloatingPointConstants constantFloatingPoint) =>
FloatingPoint16Value.fromLogicValue(
FloatingPoint16Value.ofLogicValue(
FloatingPointValue.getFloatingPointConstant(
constantFloatingPoint, exponentWidth, mantissaWidth)
.value);
Expand Down Expand Up @@ -68,15 +68,15 @@ class FloatingPoint16Value extends FloatingPointValue {
: super.ofInts();

/// Numeric conversion of a [FloatingPoint16Value] from a host double
factory FloatingPoint16Value.fromDouble(double inDouble) {
final fpv = FloatingPointValue.fromDouble(inDouble,
factory FloatingPoint16Value.ofDouble(double inDouble) {
final fpv = FloatingPointValue.ofDouble(inDouble,
exponentWidth: exponentWidth, mantissaWidth: mantissaWidth);

return FloatingPoint16Value.fromLogicValue(fpv.value);
return FloatingPoint16Value.ofLogicValue(fpv.value);
}

/// Construct a [FloatingPoint16Value] from a Logic word
factory FloatingPoint16Value.fromLogicValue(LogicValue val) =>
FloatingPointValue.buildFromLogicValue(
factory FloatingPoint16Value.ofLogicValue(LogicValue val) =>
FloatingPointValue.buildOfLogicValue(
FloatingPoint16Value.new, exponentWidth, mantissaWidth, val);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FloatingPoint32Value extends FloatingPointValue {
/// Return the [FloatingPoint32Value] representing the constant specified
factory FloatingPoint32Value.getFloatingPointConstant(
FloatingPointConstants constantFloatingPoint) =>
FloatingPoint32Value.fromLogicValue(
FloatingPoint32Value.ofLogicValue(
FloatingPointValue.getFloatingPointConstant(
constantFloatingPoint, exponentWidth, mantissaWidth)
.value);
Expand Down Expand Up @@ -69,7 +69,7 @@ class FloatingPoint32Value extends FloatingPointValue {
: super.ofInts();

/// Numeric conversion of a [FloatingPoint32Value] from a host double
factory FloatingPoint32Value.fromDouble(double inDouble) {
factory FloatingPoint32Value.ofDouble(double inDouble) {
final byteData = ByteData(4)..setFloat32(0, inDouble);
final accum = byteData.buffer
.asUint8List()
Expand All @@ -83,7 +83,7 @@ class FloatingPoint32Value extends FloatingPointValue {
}

/// Construct a [FloatingPoint32Value] from a Logic word
factory FloatingPoint32Value.fromLogicValue(LogicValue val) =>
FloatingPointValue.buildFromLogicValue(
factory FloatingPoint32Value.ofLogicValue(LogicValue val) =>
FloatingPointValue.buildOfLogicValue(
FloatingPoint32Value.new, exponentWidth, mantissaWidth, val);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FloatingPoint64Value extends FloatingPointValue {
/// Return the [FloatingPoint64Value] representing the constant specified
factory FloatingPoint64Value.getFloatingPointConstant(
FloatingPointConstants constantFloatingPoint) =>
FloatingPoint64Value.fromLogicValue(
FloatingPoint64Value.ofLogicValue(
FloatingPointValue.getFloatingPointConstant(
constantFloatingPoint, exponentWidth, mantissaWidth)
.value);
Expand Down Expand Up @@ -61,7 +61,7 @@ class FloatingPoint64Value extends FloatingPointValue {
: super.ofInts();

/// Numeric conversion of a [FloatingPoint64Value] from a host double
factory FloatingPoint64Value.fromDouble(double inDouble) {
factory FloatingPoint64Value.ofDouble(double inDouble) {
final byteData = ByteData(8)..setFloat64(0, inDouble);
final accum = byteData.buffer
.asUint8List()
Expand All @@ -75,7 +75,7 @@ class FloatingPoint64Value extends FloatingPointValue {
}

/// Construct a [FloatingPoint32Value] from a Logic word
factory FloatingPoint64Value.fromLogicValue(LogicValue val) =>
FloatingPointValue.buildFromLogicValue(
factory FloatingPoint64Value.ofLogicValue(LogicValue val) =>
FloatingPointValue.buildOfLogicValue(
FloatingPoint64Value.new, exponentWidth, mantissaWidth, val);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ class FloatingPoint8E4M3Value extends FloatingPointValue {
: super.ofInts();

/// Numeric conversion of a [FloatingPoint8E4M3Value] from a host double
factory FloatingPoint8E4M3Value.fromDouble(double inDouble) {
factory FloatingPoint8E4M3Value.ofDouble(double inDouble) {
if ((inDouble.abs() > maxValue) |
((inDouble != 0) & (inDouble.abs() < minValue))) {
throw RohdHclException('Number exceeds E4M3 range');
}
final fpv = FloatingPointValue.fromDouble(inDouble,
final fpv = FloatingPointValue.ofDouble(inDouble,
exponentWidth: exponentWidth, mantissaWidth: mantissaWidth);
return FloatingPoint8E4M3Value(
sign: fpv.sign, exponent: fpv.exponent, mantissa: fpv.mantissa);
}

/// Construct a [FloatingPoint8E4M3Value] from a Logic word
factory FloatingPoint8E4M3Value.fromLogicValue(LogicValue val) =>
FloatingPointValue.buildFromLogicValue(
factory FloatingPoint8E4M3Value.ofLogicValue(LogicValue val) =>
FloatingPointValue.buildOfLogicValue(
FloatingPoint8E4M3Value.new, exponentWidth, mantissaWidth, val);
}

Expand Down Expand Up @@ -141,19 +141,19 @@ class FloatingPoint8E5M2Value extends FloatingPointValue {
: super.ofInts();

/// Numeric conversion of a [FloatingPoint8E5M2Value] from a host double
factory FloatingPoint8E5M2Value.fromDouble(double inDouble) {
factory FloatingPoint8E5M2Value.ofDouble(double inDouble) {
if ((inDouble.abs() > maxValue) |
((inDouble != 0) & (inDouble.abs() < minValue))) {
throw RohdHclException('Number exceeds E5M2 range');
}
final fpv = FloatingPointValue.fromDouble(inDouble,
final fpv = FloatingPointValue.ofDouble(inDouble,
exponentWidth: exponentWidth, mantissaWidth: mantissaWidth);
return FloatingPoint8E5M2Value(
sign: fpv.sign, exponent: fpv.exponent, mantissa: fpv.mantissa);
}

/// Construct a [FloatingPoint8E5M2Value] from a Logic word
factory FloatingPoint8E5M2Value.fromLogicValue(LogicValue val) =>
FloatingPointValue.buildFromLogicValue(
factory FloatingPoint8E5M2Value.ofLogicValue(LogicValue val) =>
FloatingPointValue.buildOfLogicValue(
FloatingPoint8E5M2Value.new, exponentWidth, mantissaWidth, val);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FloatingPointBF16Value extends FloatingPointValue {
/// Return the [FloatingPointBF16Value] representing the constant specified
factory FloatingPointBF16Value.getFloatingPointConstant(
FloatingPointConstants constantFloatingPoint) =>
FloatingPointBF16Value.fromLogicValue(
FloatingPointBF16Value.ofLogicValue(
FloatingPointValue.getFloatingPointConstant(
constantFloatingPoint, exponentWidth, mantissaWidth)
.value);
Expand Down Expand Up @@ -68,15 +68,15 @@ class FloatingPointBF16Value extends FloatingPointValue {
: super.ofInts();

/// Numeric conversion of a [FloatingPointBF16Value] from a host double
factory FloatingPointBF16Value.fromDouble(double inDouble) {
final fpv = FloatingPointValue.fromDouble(inDouble,
factory FloatingPointBF16Value.ofDouble(double inDouble) {
final fpv = FloatingPointValue.ofDouble(inDouble,
exponentWidth: exponentWidth, mantissaWidth: mantissaWidth);

return FloatingPointBF16Value.fromLogicValue(fpv.value);
return FloatingPointBF16Value.ofLogicValue(fpv.value);
}

/// Construct a [FloatingPointBF16Value] from a Logic word
factory FloatingPointBF16Value.fromLogicValue(LogicValue val) =>
FloatingPointValue.buildFromLogicValue(
factory FloatingPointBF16Value.ofLogicValue(LogicValue val) =>
FloatingPointValue.buildOfLogicValue(
FloatingPointBF16Value.new, exponentWidth, mantissaWidth, val);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FloatingPointTF32Value extends FloatingPointValue {
/// Return the [FloatingPointTF32Value] representing the constant specified
factory FloatingPointTF32Value.getFloatingPointConstant(
FloatingPointConstants constantFloatingPoint) =>
FloatingPointTF32Value.fromLogicValue(
FloatingPointTF32Value.ofLogicValue(
FloatingPointValue.getFloatingPointConstant(
constantFloatingPoint, exponentWidth, mantissaWidth)
.value);
Expand Down Expand Up @@ -68,14 +68,14 @@ class FloatingPointTF32Value extends FloatingPointValue {
: super.ofInts();

/// Numeric conversion of a [FloatingPointTF32Value] from a host double
factory FloatingPointTF32Value.fromDouble(double inDouble) {
final fpv = FloatingPointValue.fromDouble(inDouble,
factory FloatingPointTF32Value.ofDouble(double inDouble) {
final fpv = FloatingPointValue.ofDouble(inDouble,
exponentWidth: exponentWidth, mantissaWidth: mantissaWidth);
return FloatingPointTF32Value.fromLogicValue(fpv.value);
return FloatingPointTF32Value.ofLogicValue(fpv.value);
}

/// Construct a [FloatingPointTF32Value] from a Logic word
factory FloatingPointTF32Value.fromLogicValue(LogicValue val) =>
FloatingPointValue.buildFromLogicValue(
factory FloatingPointTF32Value.ofLogicValue(LogicValue val) =>
FloatingPointValue.buildOfLogicValue(
FloatingPointTF32Value.new, exponentWidth, mantissaWidth, val);
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ class FloatingPointValue implements Comparable<FloatingPointValue> {
LogicValue.ofBigInt(BigInt.from(mantissa), mantissaWidth));

/// Construct a [FloatingPointValue] from a [LogicValue]
factory FloatingPointValue.fromLogicValue(
factory FloatingPointValue.ofLogicValue(
int exponentWidth, int mantissaWidth, LogicValue val) =>
buildFromLogicValue(
buildOfLogicValue(
FloatingPointValue.new, exponentWidth, mantissaWidth, val);

/// A helper function for [FloatingPointValue.fromLogicValue] and base classes
/// A helper function for [FloatingPointValue.ofLogicValue] and base classes
/// which performs some width checks and slicing.
@protected
static T buildFromLogicValue<T extends FloatingPointValue>(
static T buildOfLogicValue<T extends FloatingPointValue>(
T Function(
{required LogicValue sign,
required LogicValue exponent,
Expand Down Expand Up @@ -363,18 +363,18 @@ class FloatingPointValue implements Comparable<FloatingPointValue> {
}

/// Convert from double using its native binary representation
factory FloatingPointValue.fromDouble(double inDouble,
factory FloatingPointValue.ofDouble(double inDouble,
{required int exponentWidth,
required int mantissaWidth,
FloatingPointRoundingMode roundingMode =
FloatingPointRoundingMode.roundNearestEven}) {
if ((exponentWidth == 8) && (mantissaWidth == 23)) {
return FloatingPoint32Value.fromDouble(inDouble);
return FloatingPoint32Value.ofDouble(inDouble);
} else if ((exponentWidth == 11) && (mantissaWidth == 52)) {
return FloatingPoint64Value.fromDouble(inDouble);
return FloatingPoint64Value.ofDouble(inDouble);
}

final fp64 = FloatingPoint64Value.fromDouble(inDouble);
final fp64 = FloatingPoint64Value.ofDouble(inDouble);
final exponent64 = fp64.exponent;

var expVal = (exponent64.toInt() - fp64.bias) +
Expand Down Expand Up @@ -442,12 +442,12 @@ class FloatingPointValue implements Comparable<FloatingPointValue> {

/// Convert a floating point number into a [FloatingPointValue]
/// representation. This form performs NO ROUNDING.
factory FloatingPointValue.fromDoubleIter(double inDouble,
factory FloatingPointValue.ofDoubleUnrounded(double inDouble,
{required int exponentWidth, required int mantissaWidth}) {
if ((exponentWidth == 8) && (mantissaWidth == 23)) {
return FloatingPoint32Value.fromDouble(inDouble);
return FloatingPoint32Value.ofDouble(inDouble);
} else if ((exponentWidth == 11) && (mantissaWidth == 52)) {
return FloatingPoint64Value.fromDouble(inDouble);
return FloatingPoint64Value.ofDouble(inDouble);
}

var doubleVal = inDouble;
Expand Down Expand Up @@ -645,7 +645,7 @@ class FloatingPointValue implements Comparable<FloatingPointValue> {
'multiplicand must have the same mantissa and exponent widths');
}

return FloatingPointValue.fromDouble(op(toDouble(), other.toDouble()),
return FloatingPointValue.ofDouble(op(toDouble(), other.toDouble()),
mantissaWidth: mantissa.width, exponentWidth: exponent.width);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
fa.put(fva);
fb.put(fvb);

final expectedNoRound = FloatingPointValue.fromDoubleIter(
final expectedNoRound = FloatingPointValue.ofDoubleUnrounded(
fva.toDouble() + fvb.toDouble(),
exponentWidth: eWidth,
mantissaWidth: mWidth);
Expand Down Expand Up @@ -65,7 +65,7 @@ void main() {
fa.put(fva);
fb.put(fvb);
// No rounding
final expected = FloatingPointValue.fromDoubleIter(
final expected = FloatingPointValue.ofDoubleUnrounded(
fva.toDouble() + fvb.toDouble(),
exponentWidth: eWidth,
mantissaWidth: mWidth);
Expand Down Expand Up @@ -259,7 +259,7 @@ void main() {
fa.put(fva);
fb.put(fvb);

final expectedNoRound = FloatingPointValue.fromDoubleIter(
final expectedNoRound = FloatingPointValue.ofDoubleUnrounded(
fva.toDouble() + fvb.toDouble(),
exponentWidth: eWidth,
mantissaWidth: mWidth);
Expand Down Expand Up @@ -304,7 +304,7 @@ void main() {

fa.put(fva);
fb.put(fvb);
final expectedNoRound = FloatingPointValue.fromDoubleIter(
final expectedNoRound = FloatingPointValue.ofDoubleUnrounded(
fva.toDouble() + fvb.toDouble(),
exponentWidth: eWidth,
mantissaWidth: mWidth);
Expand Down Expand Up @@ -345,7 +345,7 @@ void main() {
exponentWidth: eWidth, mantissaWidth: mWidth);
fa.put(fva);
fb.put(fvb);
final expectedNoRound = FloatingPointValue.fromDoubleIter(
final expectedNoRound = FloatingPointValue.ofDoubleUnrounded(
fva.toDouble() + fvb.toDouble(),
exponentWidth: eWidth,
mantissaWidth: mWidth);
Expand Down
Loading

0 comments on commit a3bd3a5

Please sign in to comment.