Class DoubleValue

java.lang.Object
io.matita08.value.Value
io.matita08.value.DoubleValue

public class DoubleValue extends Value
Concrete implementation of Value representing a multi-word value. This class stores values that span multiple memory locations, typically used for addresses in architectures with multi-word addressing or for extended precision values.

DoubleValue can operate in two modes based on Constants.getAddressSize():

  • Single-word mode: Uses one Value component (index 0)
  • Double-word mode: Uses two Value components (index 0 = MSB, index 1 = LSB)

The class provides automatic increment functionality useful for pointer arithmetic and address calculations, with proper overflow handling across word boundaries.

Since:
1.0
  • Constructor Details

    • DoubleValue

      public DoubleValue()
      Constructs a new DoubleValue with all components initialized to undefined values. The number of components depends on the current address size configuration.
    • DoubleValue

      public DoubleValue(int n)
      Constructs a new DoubleValue from a single integer value. For double-word mode, the value is split across MSB and LSB components. For single-word mode, the entire value is stored in component 0.
      Parameters:
      n - the integer value to store
    • DoubleValue

      public DoubleValue(Value v1)
      Constructs a new DoubleValue by copying from another Value. If the source is a DoubleValue, copies its components. Otherwise, stores the source value in component 0.
      Parameters:
      v1 - the value to copy from
    • DoubleValue

      public DoubleValue(Value v1, Value v2)
      Constructs a new DoubleValue from two separate Value components. This constructor is only valid for double-word mode.
      Parameters:
      v1 - the value for component 0 (MSB)
      v2 - the value for component 1 (LSB)
      Throws:
      IllegalArgumentException - if either parameter is already a DoubleValue
  • Method Details

    • unset

      public static String unset()

      For DoubleValue, returns a string representation of undefined state with question marks for each address component.

    • 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 DoubleValue, creates a new DoubleValue with the specified numeric 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)
    • set

      public void set(Value va)
      Sets this value to match another value. The default implementation extracts the numeric value and calls Value.set(int). Subclasses may override this for more sophisticated value copying.

      For DoubleValue, updates the internal components based on the source value type. Handles DoubleValue-to-DoubleValue copying, undefined value initialization, and SingleValue integration with intelligent component selection.

      Overrides:
      set in class Value
      Parameters:
      va - the value to copy from
    • 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 DoubleValue, performs addition by creating a new DoubleValue with the sum of both operands.

      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 DoubleValue, performs subtraction by creating a new DoubleValue with the difference of both operands.

      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 DoubleValue, multiplication is not intended to be used. This method throws an AssertionError if called.

      Specified by:
      mul in class Value
      Parameters:
      v2 - the value to multiply with this value
      Returns:
      a new value containing the product
      Throws:
      AssertionError - always, as this method is not intended for use
    • get

      public int get()
      Gets the numeric value as an integer. The default implementation delegates to Value.getUnsigned().

      For DoubleValue, combines all components into a single integer. In double-word mode, calculates MSB * ValueMax + LSB. In single-word mode, returns the value of component 0.

      Overrides:
      get in class Value
      Returns:
      the numeric value as an integer
    • getSigned

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

      For DoubleValue, delegates to get() as signed interpretation is the same as unsigned for the composite value.

      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 DoubleValue, delegates to get() for unsigned interpretation.

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

      public Value getAndInc()
      Returns the current value and then increments this DoubleValue. This method is useful for pointer arithmetic where you need both the current address and want to advance to the next location.

      Increment behavior:

      • Single-word mode: Increments component 0 with overflow to 0
      • Double-word mode: Increments LSB, carries over to MSB on overflow
      Returns:
      a copy of this DoubleValue before incrementing
    • toString

      public String toString()
      Returns a string representation of this value. The representation uses the radix specified by Constants.getRadix() and may show special indicators for undefined values.

      For DoubleValue, returns a string representation that shows undefined components as "?" and combines defined components appropriately based on the current radix setting.

      Overrides:
      toString in class Value
      Returns:
      a string representation of this value