Class UndefinedDoubleValue

java.lang.Object
io.matita08.value.Value
io.matita08.value.UndefinedDoubleValue
All Implemented Interfaces:
Cloneable

public class UndefinedDoubleValue extends Value implements Cloneable
Concrete implementation of Value representing an undefined multi-word value. This class simulates uninitialized memory for double-word values by returning random values for all operations, helping to identify programming errors where uninitialized address values or extended precision values are used.

UndefinedDoubleValue implements the Cloneable interface but returns the same instance when cloned, as all undefined values exhibit the same random behavior.

All arithmetic operations with undefined values result in undefined values, and comparison operations always return false to prevent undefined behavior from appearing as valid comparisons.

Since:
1.0
  • Method Details

    • getSigned

      public int getSigned()
      Gets the value interpreted as a signed integer. The sign interpretation depends on the value type and configuration.

      For UndefinedDoubleValue, returns a random value in the signed range by subtracting ValueMax from the random value to center it around zero.

      Specified by:
      getSigned in class Value
      Returns:
      the value as a signed integer
    • getUnsigned

      public int getUnsigned()
      Gets the value interpreted as an unsigned integer. All negative representations are treated as positive values.

      For UndefinedDoubleValue, returns a random value in the unsigned range by taking the modulo with ValueMax.

      Specified by:
      getUnsigned in class Value
      Returns:
      the value as an unsigned integer
    • clone

      public UndefinedDoubleValue clone()
      Returns the same UndefinedDoubleValue instance. Since all undefined values exhibit the same behavior, cloning returns the same instance for efficiency.
      Overrides:
      clone in class Object
      Returns:
      this instance
    • set

      public Value set(int n)
      Sets this value to the specified numeric value. The behavior depends on the concrete value type - some types may return a new instance while others modify the current instance.

      For UndefinedDoubleValue, setting a concrete value creates a new SingleValue with that value, effectively "defining" the undefined value as a single-word value.

      Specified by:
      set in class Value
      Parameters:
      n - the new numeric value
      Returns:
      the value instance (may be this instance or a new one)
    • isUndefined

      public boolean isUndefined()
      Checks if this value is in an undefined state. Undefined values represent uninitialized memory or registers.

      For UndefinedDoubleValue, always returns true since the value is not defined.

      Overrides:
      isUndefined in class Value
      Returns:
      true if this value is undefined, false for concrete values
    • add

      public Value add(Value v2)
      Performs addition with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or overflow based on the value types involved.

      For UndefinedDoubleValue, any arithmetic operation results in an undefined value, so returns this instance.

      Specified by:
      add in class Value
      Parameters:
      v2 - the value to add to this value
      Returns:
      a new value containing the sum
    • sub

      public Value sub(Value v2)
      Performs subtraction with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or underflow based on the value types involved.

      For UndefinedDoubleValue, any arithmetic operation results in an undefined value, so returns this instance.

      Specified by:
      sub in class Value
      Parameters:
      v2 - the value to subtract from this value
      Returns:
      a new value containing the difference
    • mul

      public Value mul(Value v2)
      Performs multiplication with another value. The operation is performed using the appropriate numeric representation and may handle overflow based on the value types involved.

      For UndefinedDoubleValue, any arithmetic operation results in an undefined value, so returns this instance.

      Specified by:
      mul in class Value
      Parameters:
      v2 - the value to multiply with this value
      Returns:
      a new value containing the product
    • equals

      public boolean equals(int n)
      Checks if this value equals the specified numeric value. The comparison is performed against both signed and unsigned interpretations to handle cases where the same bit pattern can represent different values.

      For UndefinedDoubleValue, always returns false since equality with an undefined value is undefined and should not be relied upon.

      Overrides:
      equals in class Value
      Parameters:
      n - the numeric value to compare against
      Returns:
      true if either the signed or unsigned interpretation matches the specified value