testFloatValues method Null safety

Future<void> testFloatValues()

Implementation

Future<void> testFloatValues() async {
  await test('Float Value constants', () async {
    await expect(Value.zero, Value.fromDouble(0.0));
    await expect(Value.fMaxValue, Value.fromDouble(9.999999999e99));
    await expect(Value.fMinValue, Value.fromDouble(-9.999999999e99));
  });
  await test('Float Value internal representation', () async {
    Model m = newModel();
    m.displayMode = DisplayMode.float(4);
    await expect(m.tryParseValue('0')!.internal, BigInt.from(0));
    await expect(
        m.tryParseValue('42')!.internal, BigInt.from(0x04200000000001));
    await expect(m.tryParseValue('-42')!.internal,
        BigInt.parse('94200000000001', radix: 16));
    await expect(
        m.tryParseValue('1e42')!.internal, BigInt.from(0x1000000000042));
    await expect(
        m.tryParseValue('1e-42')!.internal, BigInt.from(0x1000000000958));
  });
  await test('FloatValue from double to double', () async {
    await expect(fd(Value.fromDouble(42.0).asDouble), fd(42.0));
    await expect(fd(Value.fromDouble(-42.0).asDouble), fd(-42.0));
    await expect(Value.fromDouble(-42).negateAsFloat(), Value.fromDouble(42));
    await expect(fd(Value.fromDouble(12.3456e78).asDouble), fd(12.3456e78));
    await expect(fd(Value.fromDouble(-12.3456e78).asDouble), fd(-12.3456e78));
    await expect(fd(Value.fromDouble(12.3456e-78).asDouble), fd(12.3456e-78));
    await expect(
        fd(Value.fromDouble(-12.3456e-78).asDouble), fd(-12.3456e-78));
    await expect(
        fd(Value.fromDouble(9.999999999e-99).asDouble), fd(9.999999999e-99));
    await expect(fd(Value.fromDouble(-9.999999999e-99).asDouble),
        fd(-9.999999999e-99));
  });
  await test('Float rounding to zero', () async {
    await expect(Value.fromDouble(1e-100), Value.zero);
    await expect(Value.fromDouble(-1e-100), Value.zero);
    await expect(fd(Value.fromDouble(1e-100).asDouble), fd(0.0));
    await expect(fd(Value.fromDouble(-1e-100).asDouble), fd(0.0));
    await expect(fd(Value.fromDouble(1e-101).asDouble), fd(0.0));
    await expect(fd(Value.fromDouble(-1e-101).asDouble), fd(0.0));
  });
  await test('Float rounding to infinity', () async {
    await expect(Value.fromDouble(9.9999999996e99), Value.fInfinity);
    await expect(Value.fromDouble(-9.9999999996e99), Value.fNegativeInfinity);
    await expect(Value.fromDouble(9.9999999996e99), Value.fInfinity);
    await expect(Value.fromDouble(-9.9999999996e99), Value.fNegativeInfinity);
  });
}