Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Addition of two whole integer numbers. Numbers fed into this function must meet certain requirements in order for proper execution:<br>
- *
- * <b>Case 1:</b> <b><i>a</i></b> is positive, <b><i>b</i></b> is positive.
- * <ul>
- * <li>a < 2147483647</li>
- * <li>b < 2147483647</li>
- * <li>a + b < 2147483647</li>
- * </ul>
- * <b>Case 2:</b> <b><i>a</i></b> is positive, <b><i>b</i></b> is negative.
- * <ul>
- * <li>a < 2147483647</li>
- * <li>b > -2147483648</li>
- * <li>a - b < 2147483647</li>
- * <li>b - a > -2147483648</li>
- * </ul>
- * <b>Case 3:</b> <b><i>a</i></b> is negative, <b><i>b</i></b> is negative.
- * <ul>
- * <li>a > -2147483648</li>
- * <li>b > -2147483648</li>
- * <li>a + b > -2147483648</li>
- * </ul>
- <b>Case 4:</b> <b><i>a</i></b> is negative, <b><i>b</i></b> is positive.
- * <ul>
- * <li>a > -2147483648</li>
- * <li>b < 2147483647</li>
- * <li>a - b > -2147483648</li>
- * <li>b - a < 2147483647</li>
- * </ul>
- * <hr>
- * <b>Example Usage:</b>
- * <pre>
- * // Parameter numbers, pre-verified to match all the conditions required of inputs
- * int ten = 10; // BIN: 1010
- * int two = 2; // BIN: 0010
- * //
- * // 1010 = 10
- * // +0010 = 2
- * // -----
- * // 1100 = 12
- * //
- * int twelve = add(10, 2);
- * </pre>
- * <hr>
- * <b>Compilation:</b>
- * <pre>
- * public static add(II)I
- * L0
- * ILOAD 0 // Push "a" to stack
- * ILOAD 1 // Push "b" to stack
- * IADD // Add top two stack values, "a" and "b" respectively, push sum to stack
- * IRETURN // Return "a + b" evaluation
- * L1
- * LOCALVARIABLE a I L0 L1 0 // Local var information for "a"
- * LOCALVARIABLE b I L0 L1 1 // Local var information for "b"
- * MAXSTACK = 2 // Maximum number of items on the stack in this method at any one point
- * MAXLOCALS = 2 // Number of local variables used in the method
- * </pre>
- *
- * @param a
- * The first integer number to add to the second integer number parameter, <b><i>b</i></b>.
- * @param b
- * The second integer number to add to the first integer number parameter, <b><i>a</i></b>.
- * @return The summation of the two given parameter integers, <b><i>a</i></b> and <b><i>b</i></b> respectively.
- */
- public static int add(int a, int b) {
- // Take two parameter values and use the addition operator as such:
- // ($V1) + ($V2)
- // Then return the value of the expression for further usage in the caller function.
- return a + b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement