Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Replaced if structure with std::clamp() #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,7 @@ uint8_t adcToTemp(uint8_t* rxbuf) {
int32_t lookupIndex = voltage * 100 - 148;

// clamp index to range [0, 69]
if (lookupIndex < 0) {
lookupIndex = 0;
} else if (lookupIndex > g_kMaxVoltageIndex) {
lookupIndex = g_kMaxVoltageIndex;
}
lookupIndex = std::clamp<int32_t>(lookupIndex, 0, g_kMaxVoltageIndex);

// fetch linearly interpolable range (e.g. 0-5 degrees C)
auto& interpolationSegment = g_voltageToTemp[lookupIndex];
Expand Down