diff options
Diffstat (limited to 'libs/pbd/pbd/fastlog.h')
-rw-r--r-- | libs/pbd/pbd/fastlog.h | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/libs/pbd/pbd/fastlog.h b/libs/pbd/pbd/fastlog.h index 80b02e9522..57de7db8e2 100644 --- a/libs/pbd/pbd/fastlog.h +++ b/libs/pbd/pbd/fastlog.h @@ -1,10 +1,10 @@ /* -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. -*/ + * 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__ @@ -15,15 +15,17 @@ as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. 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) - */ + * 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; + 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; |