Add support for the C99 function 'log2()' which is newly needed by 'gtk2_ardour/tempo...
authorJohn Emmas <johne53@tiscali.co.uk>
Sat, 10 Jan 2015 11:56:24 +0000 (11:56 +0000)
committerJohn Emmas <johne53@tiscali.co.uk>
Sat, 10 Jan 2015 11:56:24 +0000 (11:56 +0000)
These changes are MSVC specific and shouldn't affect the other builds.

(incidentally, libpbd already offers a function called 'fast_log2()'. Not sure if that could have been used instead...)

libs/pbd/msvc/msvc_pbd.cc
libs/pbd/pbd/msvc_pbd.h
msvc_extra_headers/ardourext/misc.h.input

index ddef9685699d3c4807e5d1697c34bad9f9c1c860..ab79d8f45de8950213ef467112d5e8879c34a600 100644 (file)
@@ -262,6 +262,25 @@ trunc(double x)
        return (floor(x));
 }
 
+//***************************************************************
+//
+//     log2()
+//
+// Emulates C99 log2() using log().
+//
+//     Returns:
+//
+//    On Success: The binary (base-2) logarithm of 'x'
+//                (e.g. log2(1024) == 10).
+//    On Failure: None, except that calling log(x) should generate
+//                an appropriate error for us (such as ERANGE etc).
+//
+LIBPBD_API double PBD_APICALLTYPE
+log2(double x)
+{
+       return (log(x) / log((double)2.0));
+}
+
 namespace PBD {
 
 //***************************************************************
index bee9b8b4a46dd6d30b783e0a9a7ca02e3757593a..7529619f1d984843eebadef3709a97c9cda02dff 100644 (file)
@@ -232,6 +232,7 @@ LIBPBD_API ssize_t                  PBD_APICALLTYPE pwrite(int handle, const void *buf, size_t
 LIBPBD_API int                         PBD_APICALLTYPE poll(struct pollfd *fds, nfds_t nfds, int timeout);
 LIBPBD_API double                      PBD_APICALLTYPE round(double x);
 LIBPBD_API double                      PBD_APICALLTYPE trunc(double x);
+LIBPBD_API double                      PBD_APICALLTYPE log2(double x);
 
 namespace PBD {
 
index 3ea4a806e9574f7b64b2417d9f937ce259d6f66b..5da7c41564ff2d4b23ddddac3406da8e9a2fb508 100644 (file)
@@ -254,6 +254,10 @@ inline int64_t abs(int64_t val) throw()
 #define rint(value)  round(value)
 #if !defined(LIBPBD_API) || defined(PBD_IS_IN_WIN_STATIC_LIB)
 extern  double round(double x);
+
+// log2().... MSVC doesn't offer the C99 function 'log2()'
+// so let's emulate it.
+extern  double log2(double x);
 #endif
 
 #endif /* __ardour_msvc_extensions_h__ */