From 13106165e22699d703247d2d150364b9a414a1fe Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 7 Dec 2022 21:46:44 +0100 Subject: [PATCH] [chip-tool] Add support for INFINITY and -INFINITY argument to float/double arguments (#23888) --- .../chip-tool/commands/common/Command.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index ebfb99bad5c9e5..0c5777e825df3b 100644 --- a/examples/chip-tool/commands/common/Command.cpp +++ b/examples/chip-tool/commands/common/Command.cpp @@ -24,6 +24,8 @@ #include #include +#include // For INFINITY + #include #include #include @@ -541,6 +543,18 @@ bool Command::InitArgument(size_t argIndex, char * argValue) case ArgumentType::Float: { isValidArgument = HandleNullableOptional(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; @@ -551,6 +565,18 @@ bool Command::InitArgument(size_t argIndex, char * argValue) case ArgumentType::Double: { isValidArgument = HandleNullableOptional(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;