package username.functions; /** * The log function for a variety of bases. * * @author Samuel A. Rebelsky * @version 1.0 of April 2006 */ public class LogUIF implements UnaryIntegerFunction { // +--------+----------------------------------------------- // | Fields | // +--------+ int base; // +--------------+----------------------------------------- // | Constructors | // +--------------+ /** Build a new log function that uses base _base. */ public LogUIF(int _base) { this.base = _base; } // LogUIF(int) // +------------------+------------------------------------- // | Standard Methods | // +------------------+ public String toString() { return "log_" + this.base + "(x)"; } // +----------------+--------------------------------------- // | Public Methods | // +----------------+ public int apply(int x) { // Math tells me that log_b(x) = ln(x)/ln(b) return (int) (Math.log(x) / Math.log(this.base)); } // apply(int) } // LogUIF