Here you can find the source of signum(final int n)
Parameter | Description |
---|---|
n | the integer value whose signum is to be returned |
public static int signum(final int n)
//package com.java2s; /* Util.java//w w w . j a v a 2 s . c om * * Copyright (C) 2015, Tom? Pecina <tomas@pecina.cz> * * This file is part of cz.pecina.retro, retro 8-bit computer emulators. * * This application is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This application is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Returns the signum function of the argument; zero if the argument is * zero, 1 if the argument is greater than zero, -1 if the argument is * less than zero. * * @param n the integer value whose signum is to be returned * @return the signum function of the argument */ public static int signum(final int n) { if (n > 0) { return 1; } else if (n < 0) { return -1; } else { return 0; } } /** * Returns the signum function of the argument; zero if the argument is * zero, 1 if the argument is greater than zero, -1 if the argument is * less than zero. * * @param n the long value whose signum is to be returned * @return the signum function of the argument */ public static long signum(final long n) { if (n > 0) { return 1; } else if (n < 0) { return -1; } else { return 0; } } }