c72c7e6575
Date: Mon, 22 Apr 2013 19:09:04 +0200 From: Laurent de Soras <laurent.de.soras@free.fr> To: Adrian Knoth <adi@drcomp.erfurt.thur.de> Subject: Re: License of FastLog Hi Adrian, > Several open-source projects like Ardour use the code below which has > no explicit license. > > If you agree (read: reply), we'd like to add the MIT license to this > file, that is, change the copyright statement to the following text: Nowadays I license my code under the WTFPL, which should be compatible with the traditional open source licenses. So please use this one instead: <http://www.wtfpl.net/about/> -- Laurent de Soras | Ohm Force DSP developer & Software designer | Digital Audio Software http://ldesoras.free.fr | http://www.ohmforce.com
45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
/*
|
|
Copyright © 2013 Laurent de Soras <laurent.de.soras@free.fr>
|
|
|
|
This work is free. You can redistribute it and/or modify it under the
|
|
terms of the Do What The Fuck You Want To Public License, Version 2,
|
|
as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
|
|
*/
|
|
#ifndef __pbd_fastlog_h__
|
|
#define __pbd_fastlog_h__
|
|
|
|
#include <math.h> /* for HUGE_VAL */
|
|
|
|
static inline float fast_log2 (float val)
|
|
{
|
|
/* don't use reinterpret_cast<> because that prevents this
|
|
from being used by pure C code (for example, GnomeCanvasItems)
|
|
*/
|
|
union {float f; int i;} t;
|
|
t.f = val;
|
|
int * const exp_ptr = &t.i;
|
|
int x = *exp_ptr;
|
|
const int log_2 = ((x >> 23) & 255) - 128;
|
|
x &= ~(255 << 23);
|
|
x += 127 << 23;
|
|
*exp_ptr = x;
|
|
|
|
val = ((-1.0f/3) * t.f + 2) * t.f - 2.0f/3;
|
|
|
|
return (val + log_2);
|
|
}
|
|
|
|
static inline float fast_log (const float val)
|
|
{
|
|
return (fast_log2 (val) * 0.69314718f);
|
|
}
|
|
|
|
static inline float fast_log10 (const float val)
|
|
{
|
|
return fast_log2(val) / 3.312500f;
|
|
}
|
|
|
|
static inline float minus_infinity(void) { return -HUGE_VAL; }
|
|
|
|
#endif /* __pbd_fastlog_h__ */
|