Class SingleValue
SingleValue supports both signed and unsigned interpretations of the same bit pattern, allowing for flexible arithmetic operations and proper handling of different data types within the CPU simulation.
- Since:
- 1.0
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionSingleValue(int n) Constructs a new SingleValue with the specified numeric value.SingleValue(int n, boolean sign) Constructs a new SingleValue with the specified numeric value and sign interpretation. -
Method Summary
Modifier and TypeMethodDescriptionPerforms addition with another value.intGets the value interpreted as a signed integer.intGets the value interpreted as an unsigned integer.Performs multiplication with another value.set(int n) Sets this value to the specified numeric value.Performs subtraction with another value.static Stringunset()Methods inherited from class io.matita08.value.Value
create, create, equals, get, getNew, getNewAddress, isUndefined, set, toString
-
Constructor Details
-
SingleValue
public SingleValue(int n) Constructs a new SingleValue with the specified numeric value. The value is treated as unsigned by default.- Parameters:
n- the numeric value to store
-
SingleValue
public SingleValue(int n, boolean sign) Constructs a new SingleValue with the specified numeric value and sign interpretation.- Parameters:
n- the numeric value to storesign- true for signed interpretation, false for unsigned
-
-
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 SingleValue, returns the stored value with sign interpretation applied. If this value is marked as signed, returns the value as-is. Otherwise, converts from unsigned to signed representation.
-
getUnsigned
public int getUnsigned()Gets the value interpreted as an unsigned integer. All negative representations are treated as positive values.For SingleValue, returns the stored value as an unsigned integer. If this value is marked as signed, converts to unsigned representation. Otherwise, returns the value as-is.
- Specified by:
getUnsignedin classValue- Returns:
- the value as an unsigned integer
-
set
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 SingleValue, updates the stored value and returns this instance for method chaining.
-
add
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 SingleValue, performs signed addition and returns a new SingleValue containing the result.
-
sub
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 SingleValue, performs signed subtraction and returns a new SingleValue containing the result.
-
mul
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 SingleValue, performs signed multiplication and returns a new SingleValue containing the result.
-
unset
For SingleValue, returns "?" to indicate an uninitialized state.
-