n_log2.c revision 1.2
11.2Sriastrad/*      $NetBSD: n_log2.c,v 1.2 2024/07/16 14:52:50 riastradh 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.2Sriastrad#include <sys/cdefs.h>
321.2Sriastrad__RCSID("$NetBSD: n_log2.c,v 1.2 2024/07/16 14:52:50 riastradh Exp $");
331.2Sriastrad
341.1Smartin/* LOG2(X)
351.1Smartin * RETURN THE BASE 10 LOGARITHM OF x
361.1Smartin *
371.1Smartin * Required kernel function:
381.1Smartin *	log(x)
391.1Smartin *
401.1Smartin * Method :
411.1Smartin *			    log(x)
421.1Smartin *		log2(x) =  ---------
431.1Smartin *			    log(2)
441.1Smartin */
451.1Smartin
461.2Sriastrad#include "namespace.h"
471.2Sriastrad
481.1Smartin#define _LIBM_STATIC
491.1Smartin#include "mathimpl.h"
501.1Smartin
511.2Sriastrad__weak_alias(log2l, _log2l)
521.2Sriastrad__strong_alias(_log2l, _log2)
531.1Smartin
541.1Smartinstatic const double ln2 = .6931471805599453094172321214581765680755;
551.1Smartin
561.2Sriastrad__weak_alias(log2, _log2)
571.1Smartindouble
581.1Smartinlog2(double x)
591.1Smartin{
601.1Smartin	return log(x)/ln2;
611.1Smartin}
621.1Smartin
631.2Sriastrad__weak_alias(log2f, _log2f)
641.1Smartinfloat
651.1Smartinlog2f(float x)
661.1Smartin{
671.1Smartin	return logf(x)/ln2;
681.1Smartin}
69