From a222292e68fae7c7b7ca9ce1af94aaaf031ad070 Mon Sep 17 00:00:00 2001 From: John Emmas Date: Wed, 5 May 2021 17:50:41 +0100 Subject: [PATCH] Emulate exp2f() for older MS compilers where it wasn't available --- libs/pbd/msvc/msvc_pbd.cc | 18 ++++++++++++++++++ libs/pbd/pbd/msvc_pbd.h | 3 ++- msvc_extra_headers/ardourext/misc.h.input | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libs/pbd/msvc/msvc_pbd.cc b/libs/pbd/msvc/msvc_pbd.cc index 4d276eb85c..730672a31d 100644 --- a/libs/pbd/msvc/msvc_pbd.cc +++ b/libs/pbd/msvc/msvc_pbd.cc @@ -242,6 +242,24 @@ expm1(double x) return (exp(x) - (double)1.0); } +//*************************************************************** +// +// exp2f() +// +// Emulates C99 exp2f() using powf(). +// +// Returns: +// +// On Success: 2 raised to the power of 'x' +// On Failure: None, except that calling powf(x) should generate +// an appropriate error for us (such as INF etc). +// +LIBPBD_API float PBD_APICALLTYPE +exp2f(float x) +{ + return (powf(2.0f, x)); +} + //*************************************************************** // // log1p() diff --git a/libs/pbd/pbd/msvc_pbd.h b/libs/pbd/pbd/msvc_pbd.h index f717047c65..d631e5532c 100644 --- a/libs/pbd/pbd/msvc_pbd.h +++ b/libs/pbd/pbd/msvc_pbd.h @@ -172,9 +172,10 @@ LIBPBD_API ssize_t PBD_APICALLTYPE pread(int handle, void *buf, size_t nbytes, LIBPBD_API ssize_t PBD_APICALLTYPE pwrite(int handle, const void *buf, size_t nbytes, off_t offset); #if defined(_MSC_VER) && (_MSC_VER < 1800) -LIBPBD_API double PBD_APICALLTYPE expm1(double x); LIBPBD_API double PBD_APICALLTYPE log1p(double x); LIBPBD_API double PBD_APICALLTYPE round(double x); +LIBPBD_API double PBD_APICALLTYPE expm1(double x); +LIBPBD_API float PBD_APICALLTYPE exp2f(float x); LIBPBD_API float PBD_APICALLTYPE roundf(float x); #endif diff --git a/msvc_extra_headers/ardourext/misc.h.input b/msvc_extra_headers/ardourext/misc.h.input index 7471ccd649..497224a556 100644 --- a/msvc_extra_headers/ardourext/misc.h.input +++ b/msvc_extra_headers/ardourext/misc.h.input @@ -272,9 +272,10 @@ inline int64_t abs(int64_t val) throw() // Emulate some C99 math functions which MSVC itself didn't // implement until later in life. #if defined(_MSC_VER) && (_MSC_VER < 1800) -extern double expm1(double x); extern double log1p(double x); extern double round(double x); +extern double expm1(double x); +extern float exp2f(float x); extern float roundf(float x); #endif #if defined(_MSC_VER) && (_MSC_VER < 1900)