mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-31 14:52:11 +01:00
[util] Support parsing floating point arguments
This commit is contained in:
parent
8db2eb51fa
commit
9671055538
@ -755,6 +755,66 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
bool Config::parseOptionValue(
|
||||
const std::string& value,
|
||||
float& result) {
|
||||
if (value.size() == 0)
|
||||
return false;
|
||||
|
||||
// Parse sign
|
||||
size_t pos = 0;
|
||||
bool negate = false;
|
||||
|
||||
if (value[0] == '-') {
|
||||
negate = true;
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
// Parse integer part
|
||||
uint64_t intPart = 0;
|
||||
|
||||
if (value[pos] == '.')
|
||||
return false;
|
||||
|
||||
while (pos < value.size()) {
|
||||
if (value[pos] == '.') {
|
||||
if (++pos == value.size())
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (value[pos] < '0' || value[pos] > '9')
|
||||
return false;
|
||||
|
||||
intPart *= 10;
|
||||
intPart += value[pos] - '0';
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
// Parse fractional part
|
||||
uint64_t fractPart = 0;
|
||||
uint64_t fractDivisor = 1;
|
||||
|
||||
while (pos < value.size()) {
|
||||
if (value[pos] < '0' || value[pos] > '9')
|
||||
return false;
|
||||
|
||||
fractDivisor *= 10;
|
||||
fractPart *= 10;
|
||||
fractPart += value[pos] - '0';
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
// Compute final number, not super accurate but this should do
|
||||
result = float((double(fractPart) / double(fractDivisor)) + double(intPart));
|
||||
|
||||
if (negate)
|
||||
result = -result;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Config::parseOptionValue(
|
||||
const std::string& value,
|
||||
Tristate& result) {
|
||||
|
@ -123,6 +123,10 @@ namespace dxvk {
|
||||
const std::string& value,
|
||||
int32_t& result);
|
||||
|
||||
static bool parseOptionValue(
|
||||
const std::string& value,
|
||||
float& result);
|
||||
|
||||
static bool parseOptionValue(
|
||||
const std::string& value,
|
||||
Tristate& result);
|
||||
|
Loading…
x
Reference in New Issue
Block a user