Skip to content

Commit

Permalink
replace pow with exp2
Browse files Browse the repository at this point in the history
A boneheaded mistake when converting std::exp and std::log(2). exp2 is
simpler.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Mar 4, 2025
1 parent f5c2ce8 commit ce36d80
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3028,15 +3028,15 @@ 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;
}

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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/nikonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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*) {
Expand All @@ -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*) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/tags_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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.
Expand Down

0 comments on commit ce36d80

Please sign in to comment.