From ce36d80eb346b48895121fed61adff5a20cd7c46 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 3 Mar 2025 18:42:58 -0800 Subject: [PATCH] replace pow with exp2 A boneheaded mistake when converting std::exp and std::log(2). exp2 is simpler. Signed-off-by: Rosen Penev --- src/canonmn_int.cpp | 4 ++-- src/nikonmn_int.cpp | 10 +++++----- src/tags_int.cpp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index d40145ba21..a95562feb0 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -3028,7 +3028,7 @@ std::ostream& CanonMakerNote::printLe0x0000(std::ostream& os, const Value& value std::ostream& CanonMakerNote::printSi0x0001(std::ostream& os, const Value& value, const ExifData*) { if (value.typeId() == unsignedShort && value.count() > 0) { - os << std::pow(2.0F, canonEv(value.toInt64()) / 32) * 100.0F; + os << std::exp2(canonEv(value.toInt64()) / 32) * 100.0F; } return os; } @@ -3036,7 +3036,7 @@ std::ostream& CanonMakerNote::printSi0x0001(std::ostream& os, const Value& value std::ostream& CanonMakerNote::printSi0x0002(std::ostream& os, const Value& value, const ExifData*) { if (value.typeId() == unsignedShort && value.count() > 0) { // Ported from Exiftool by Will Stokes - os << std::pow(2.0F, canonEv(value.toInt64())) * 100.0F / 32.0F; + os << std::exp2(canonEv(value.toInt64())) * (100.0F / 32.0F); } return os; } diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index 17e7137ba1..19baf27b85 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -1045,7 +1045,7 @@ static void printFlashCompensationValue(std::ostream& os, const unsigned char va } const auto mod = value % 6; auto temp = (value < 6) ? 0 : (value - mod) / 6; - os << "1/" << std::pow(2, temp); + os << "1/" << std::exp2(temp); if (mod != 0) { os << " (-"; switch (mod) { @@ -1740,7 +1740,7 @@ const TagInfo* Nikon3MakerNote::tagListLd4() { } std::ostream& Nikon3MakerNote::printIiIso(std::ostream& os, const Value& value, const ExifData*) { - auto v = std::lround(100.0 * std::pow(2.0, (value.toInt64() / 12.0) - 5)); + auto v = std::lround(100.0 * std::exp2((value.toInt64() / 12.0) - 5)); return os << v; } @@ -3304,7 +3304,7 @@ std::ostream& Nikon3MakerNote::printAperture(std::ostream& os, const Value& valu if (val == 0) return os << _("n/a"); - return os << stringFormat("F{:.1f}", std::pow(2.0, val / 24.0)); + return os << stringFormat("F{:.1f}", std::exp2(val / 24.0)); } std::ostream& Nikon3MakerNote::printFocal(std::ostream& os, const Value& value, const ExifData*) { @@ -3315,7 +3315,7 @@ std::ostream& Nikon3MakerNote::printFocal(std::ostream& os, const Value& value, if (val == 0) return os << _("n/a"); - return os << stringFormat("{:.1f} mm", 5.0 * std::pow(2.0, val / 24.0)); + return os << stringFormat("{:.1f} mm", 5.0 * std::exp2(val / 24.0)); } std::ostream& Nikon3MakerNote::printFStops(std::ostream& os, const Value& value, const ExifData*) { @@ -3919,7 +3919,7 @@ std::ostream& Nikon3MakerNote::printApertureLd4(std::ostream& os, const Value& v if (temp == 0) return os << _("n/a"); - return os << stringFormat("F{:.1f}", std::pow(2.0, (temp / 384.0) - 1.0)); + return os << stringFormat("F{:.1f}", std::exp2((temp / 384.0) - 1.0)); } std::ostream& Nikon3MakerNote::printFocalLd4(std::ostream& os, const Value& value, const ExifData*) { if (value.count() != 1 || value.typeId() != unsignedShort) { diff --git a/src/tags_int.cpp b/src/tags_int.cpp index a9ef750b1a..e82a0a44d5 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2592,7 +2592,7 @@ std::ostream& printBitmask(std::ostream& os, const Value& value, const ExifData* } float fnumber(float apertureValue) { - float result = std::pow(2.0F, apertureValue / 2.F); + float result = std::exp2(apertureValue / 2.F); if (std::abs(result - 3.5) < 0.1) { result = 3.5; } @@ -2601,7 +2601,7 @@ float fnumber(float apertureValue) { URational exposureTime(float shutterSpeedValue) { URational ur(1, 1); - const double tmp = std::pow(2.0, shutterSpeedValue); + const double tmp = std::exp2(shutterSpeedValue); if (tmp > 1) { const double x = std::round(tmp); // Check that x is within the range of a uint32_t before casting.