@@ -0,0 +1,2113 @@
+/**%0A * Copyright %C2%A9 2014  Mattias Andr%C3%A9e (maandree@member.fsf.org)%0A * %0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Affero General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A * %0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU Affero General Public License for more details.%0A * %0A * You should have received a copy of the GNU Affero General Public License%0A * along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0Apackage algorithms.bits;%0A%0A%0A/**%0A * Compute the minimum or maximum of two integers%0A */%0Apublic class MinMax%0A%7B%0A%C2%A3%3Cfor T_S in char_15 byte_7 short_15 int_31 long_63; do%0A  T=$%7BT_S%25_*%7D%0A%C2%A3%3ES=$%7BT_S#*_%7D%0A    /**%0A     * Compute the minimum of two integers%0A     * %0A     * @param   a  One of the integers%0A     * @param   b  The other of the integers%0A     * @return     The minimum of the two integers%0A     */%0A    public static %C2%A3%7BT%7D min(%C2%A3%7BT%7D a, %C2%A3%7BT%7D b)%0A    %7B%0A%09return (%C2%A3%7BT%7D)(b %5E (%C2%A3%7BT%7D)((a %5E b) & ((a - b) %3E%3E %C2%A3%7BS%7D)));%0A%09/* In C you can also do:%0A%09 *     b %5E ((a %5E b) & -(a %3C b))%0A%09 */%0A%09/*%0A%09 * Other version that can be faster:%0A%09 *     (a %3C b) ? a : b%0A%09 *     Assuming you now that INT_MIN %3C= x - y %3C= INT_MAX:%0A%09 *         b + ((a - b) & ((a - b) %3E%3E (sizeof(%C2%A3%7BT%7D) * CHAR_BITS - 1)))%0A%09 */%0A    %7D%0A    %0A    /**%0A     * Compute the maximum of two integers%0A     * %0A     * @param   a  One of the integers%0A     * @param   b  The other of the integers%0A     * @return     The maximum of the two integers%0A     */%0A    public static %C2%A3%7BT%7D max(%C2%A3%7BT%7D a, %C2%A3%7BT%7D b)%0A    %7B%0A%09return (%C2%A3%7BT%7D)(a %5E (%C2%A3%7BT%7D)((a %5E b) & ((a - b) %3E%3E %C2%A3%7BS%7D)));%0A%09/* In C you can also do:%0A%09 *    a %5E ((a %5E b) & -(a %3C b))%0A%09 */%0A%09/*%0A%09 * Other version that can be faster:%0A%09 *     (a %3C b) ? b : a%0A%09 *     Assuming you now that INT_MIN %3C= x - y %3C= INT_MAX:%0A%09 *         a - ((a - b) & ((a - b) %3E%3E (sizeof(%C2%A3%7BT%7D) * CHAR_BITS - 1)))%0A%09 */%0A    %7D%0A    %0A%C2%A3%3Edone%0A%7D%0A%0A

add min max