n_log2.c revision 1.1
11.1Smartin/* $NetBSD: n_log2.c,v 1.1 2014/03/06 10:57:01 martin Exp $ */ 21.1Smartin/*- 31.1Smartin * Copyright (c) 2014 The NetBSD Foundation, Inc. 41.1Smartin * All rights reserved. 51.1Smartin * 61.1Smartin * This code is derived from software contributed to The NetBSD Foundation 71.1Smartin * by Martin Husemann <martin@NetBSD.org>. 81.1Smartin * 91.1Smartin * Redistribution and use in source and binary forms, with or without 101.1Smartin * modification, are permitted provided that the following conditions 111.1Smartin * are met: 121.1Smartin * 1. Redistributions of source code must retain the above copyright 131.1Smartin * notice, this list of conditions and the following disclaimer. 141.1Smartin * 2. Redistributions in binary form must reproduce the above copyright 151.1Smartin * notice, this list of conditions and the following disclaimer in the 161.1Smartin * documentation and/or other materials provided with the distribution. 171.1Smartin * 181.1Smartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 191.1Smartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 201.1Smartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 211.1Smartin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 221.1Smartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 231.1Smartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 241.1Smartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 251.1Smartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 261.1Smartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 271.1Smartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 281.1Smartin * POSSIBILITY OF SUCH DAMAGE. 291.1Smartin */ 301.1Smartin 311.1Smartin/* LOG2(X) 321.1Smartin * RETURN THE BASE 10 LOGARITHM OF x 331.1Smartin * 341.1Smartin * Required kernel function: 351.1Smartin * log(x) 361.1Smartin * 371.1Smartin * Method : 381.1Smartin * log(x) 391.1Smartin * log2(x) = --------- 401.1Smartin * log(2) 411.1Smartin */ 421.1Smartin 431.1Smartin#define _LIBM_STATIC 441.1Smartin#include "mathimpl.h" 451.1Smartin 461.1Smartin 471.1Smartinstatic const double ln2 = .6931471805599453094172321214581765680755; 481.1Smartin 491.1Smartindouble 501.1Smartinlog2(double x) 511.1Smartin{ 521.1Smartin return log(x)/ln2; 531.1Smartin} 541.1Smartin 551.1Smartinfloat 561.1Smartinlog2f(float x) 571.1Smartin{ 581.1Smartin return logf(x)/ln2; 591.1Smartin} 60