/*
* cs101 Math utilities
* $Id: MoreMath.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $
*
* Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group.
* For more information, see the
* CS101 homepage or email .
*
* Copyright (C) 1996 Massachusetts Institute of Technology.
* Please do not redistribute without obtaining permission.
*/
package cs101.util;
/**
* cs101.util.MoreMath is an extension of the java.lang.Math library.
*
* Copyright 1996 Massachusetts Institute of Technology
*
* @author Todd C. Parnell, tparnell@ai.mit.edu
* @author Lynn Andrea Stein, las@ai.mit.edu
*
*/
public class MoreMath {
/**
* Generate a random int between 0 and range. Note that if range is
* negative, this returns a negative number.
*
* @param range desired maximum int.
*/
public static int randomInt(int range)
{
return (int) Math.round(Math.random() * range);
}
/**
* Returns the square of the input. No checks are made for MaxInt overflow.
*
* @param x the number to square
*/
public static int square(int x)
{
return(x * x);
}
/**
* Returns 1 if the input is positive, -1 if it is negative, and 0 otherwise.
*
* @param x the number to get the sign of
*/
public static int sign(int x)
{
if(x == 0)
{
return(0);
}
else if(x > 0)
{
return(1);
}
return(-1);
}
/**
* Prevent instantiation
*/
private MoreMath() {}
}
/*
* $Log: MoreMath.java,v $
* Revision 1.1.1.1 2002/06/05 21:56:32 root
* CS101 comes to Olin finally.
*
* Revision 1.5 1999/08/17 18:37:02 emarcus
* Added sign and square methods.
*
* Revision 1.4 1998/07/24 17:19:30 tparnell
* Placate new javadoc behavior
*
* Revision 1.3 1998/07/21 19:38:19 tparnell
* added more javadoc & private MoreMath()
*
* Revision 1.2 1998/06/03 19:47:44 tparnell
* added header, javadoc and logging
* */