Core Function DiffCalc
From Sputnik Wiki
DiffCalc( <first>, <second>, <useDouble> )
Contents |
Description
Calculate the difference between two values and return the diff type Same/Add/Sub with a raw diff which can be added to the base value to make it become the second and a non-raw diff that must be added or subbed for first to become second
Parameters
first
The first value to calculate (source value).
second
The second value to calculate (destination value).
useDouble
Optional; If TRUE then the calculation will be made using Double instead of Int64
Default: False
Return Value
Success: A three element array with the following:
[0] = Type (Same/Add/Sub) [1] = Difference (to be used with Type so if type if Sub you -= the difference [2] = Raw Difference can be applied directly to the first value with += or -=
Remarks
None.
Example
// get a diff on double using the double flag PrintDiff(100.0, 50.0, true); // now get the diff on some ints PrintDiff(0x411C88, 0x40230F); PrintDiff(0x40230F, 0x411C88); Function PrintDiff($first, $second) { // Get the diff my List($Type, $Diff, $RawDiff) = DiffCalc($first, $second); // Print its info say "Type: $Type | Diff: $Diff | RawDiff: $RawDiff"; // To make the second from first we do my $remade = $first + $RawDiff; say "Remade: " . $remade . " | InHex: " . Hex($remade); } // PRINTS // Type: Sub | Diff: 50 | RawDiff: -50 // Remade: 50 | InHex: 32 // Type: Sub | Diff: 63865 | RawDiff: -63865 // Remade: 4203279 | InHex: 40230F // Type: Add | Diff: 63865 | RawDiff: 63865 // Remade: 4267144 | InHex: 411C88