diff --git a/libs/pbd/msvc/msvc_pbd.cc b/libs/pbd/msvc/msvc_pbd.cc index ddef968569..ab79d8f45d 100644 --- a/libs/pbd/msvc/msvc_pbd.cc +++ b/libs/pbd/msvc/msvc_pbd.cc @@ -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 { //*************************************************************** diff --git a/libs/pbd/pbd/msvc_pbd.h b/libs/pbd/pbd/msvc_pbd.h index bee9b8b4a4..7529619f1d 100644 --- a/libs/pbd/pbd/msvc_pbd.h +++ b/libs/pbd/pbd/msvc_pbd.h @@ -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 { diff --git a/msvc_extra_headers/ardourext/misc.h.input b/msvc_extra_headers/ardourext/misc.h.input index 3ea4a806e9..5da7c41564 100644 --- a/msvc_extra_headers/ardourext/misc.h.input +++ b/msvc_extra_headers/ardourext/misc.h.input @@ -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__ */