Skip to content

Commit

Permalink
[chip-tool] Add support for INFINITY and -INFINITY argument to float/…
Browse files Browse the repository at this point in the history
…double arguments (#23888)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 5, 2023
1 parent 67c94d2 commit 1098502
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <sys/socket.h>
#include <sys/types.h>

#include <math.h> // For INFINITY

#include <lib/core/CHIPSafeCasts.h>
#include <lib/support/BytesToHex.h>
#include <lib/support/CHIPMem.h>
Expand Down Expand Up @@ -541,6 +543,18 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Float: {
isValidArgument = HandleNullableOptional<float>(arg, argValue, [&](auto * value) {
if (strcmp(argValue, "Infinity") == 0)
{
*value = INFINITY;
return true;
}

if (strcmp(argValue, "-Infinity") == 0)
{
*value = -INFINITY;
return true;
}

std::stringstream ss;
ss << argValue;
ss >> *value;
Expand All @@ -551,6 +565,18 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Double: {
isValidArgument = HandleNullableOptional<double>(arg, argValue, [&](auto * value) {
if (strcmp(argValue, "Infinity") == 0)
{
*value = INFINITY;
return true;
}

if (strcmp(argValue, "-Infinity") == 0)
{
*value = -INFINITY;
return true;
}

std::stringstream ss;
ss << argValue;
ss >> *value;
Expand Down

0 comments on commit 1098502

Please sign in to comment.