Module arithmetic

Source
Expand description

§Vax floating-point arithmetic

In order to perform most of the arithmetic on VAX floating-point types, they need to be converted into an intermediate form. The intermediate form is the VaxFloatingPoint type.

The VaxFloatingPoint structure separates the sign, exponent, and fractional protions of the underlying floating-point type. The floating-point arithmetic is based off the implementation in SimH VAX. This project assumes that the SimH VAX floating-point implementation would match the VAX hardware.

VaxFloatingPoint supports adding, subtracting, multiplication, and division. It also supports shift right and left operations which just modify the exponent value. A shift left multiplies the value of the float by 2 and a shift right divides it by 2. It also suports reading from a string and displaying to a string.

VaxFloatingPoint provides higher precision then the native floating point types, because the fractional value uses all of the bits of the underlying floating point type. For example, the F_floating type uses 23 bits for the fractional value, but when converted into a VaxFloatingPoint, the fractional value uses 32 bits. If the higher precision is needed, then VaxFloatingPoint values can be used directly.

Constant versions of all mathmatical operations and conversions from the Rust data types (including from an ASCII string slice) are available. Since the arithmetic operations are not particularly fast, doing them at compile time as constant operations is preferable.

The Display (and LowerExp and UpperExp) implementations fall into the slow but accurate category, since they use the VAX mathmatical operations to do the conversions.

§Floating-point Type Differences between VAX and IEEE 754

  • The VAX uses a unique byte ordering for the floating-point values. Each set of 16-bit values is in little endian order, but the 16-bit byte-pairs are in big-endian order. The first (lowest address) 16-bits of the VAX floating-point types contain the sign bit, the exponent, and, usually, the most significant bits of the fraction. The last (highest addressed) 16-bits of the VAX floating-point types contain the least significant bits of the fraction.
  • The VAX doesn’t support negative zero. An exponent value of zero with a sign bit of 1 is a reserved value and would trigger a reserved operand fault.
  • The VAX doesn’t support subnormal numbers. All values with a sign bit clear and a exponent value of zero are considered to be zero.
  • The VAX doesn’t have an Infinity value, which gives it one more exponent value.
  • The VAX exponent bias is 2 more than the ones used in IEEE 754. Since VAX doesn’t support an infinity state, it has symetrical exponent values. For example, the F_floating type has an exponent range from 127 to -127, whereas, the single-precision floating-point type defined in IEEE 754 has an exponent range from 128 to -125. (see note about differences between exponents referred to in this documentation and how it is referenced to by Wikipedia)
  • The VAX rounds differently than Rust. The VAX always rounds ties up, whereas, the f32 and f64 types round according to the roundTiesToEven direction defined in IEEE 754-2008.

§Notes

§Wikipedia Exponents

There is a difference between the exponent values in the Wikipedia reference documentation for IEEE 754, and exponent values in this documentation, the VAX documentation, and as defined in Rust as the MIN_EXP and MAX_EXP values in f32 and f64).

It comes down to how the implicit bit in the fraction portion of the floating-point is treated. In Wikipedia, the implicit bit is the least-significant non-fractional bit, and here it is the most-significant fractional bit.

On Wikipedia, the range for values with exponent 0 is ≥ 1.0 and < 2.0. Here, the range for exponent 0 is ≥ 0.5 and < 1.0. Therefore, our exponent 0 is equal to Wikipedia’s exponent -1.

Structs§

VaxFloatingPoint
Intermediate floating-point type used to perform arithmetic operations for the VAX floating-point types.

Enums§

Fault
VAX floating-point number fault
Sign
Sign of the floating-point number.