From 78ee28054f94760f2f1d27380c452ee964b427b4 Mon Sep 17 00:00:00 2001 From: Fan Guo Date: Mon, 10 Sep 2012 10:08:46 -0700 Subject: [PATCH] support -nan in conversion Summary: Folly supports -inf and nan but not -nan, instead it raised unexpected exceptions not handled in the upstream. This diff is separated out from D569816 -- Diff1. Test Plan: std::isnan(folly::to(-nan)) Reviewed By: tudorb@fb.com FB internal diff: D569939 --- folly/Conv.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/folly/Conv.h b/folly/Conv.h index c64b52ef..98c66b3d 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -836,6 +836,16 @@ to(StringPiece *const src) { return std::numeric_limits::quiet_NaN(); } + // "-nan"? + if (src->size() >= 4 && + toupper((*src)[0]) == '-' && + toupper((*src)[1]) == 'N' && + toupper((*src)[2]) == 'A' && + toupper((*src)[3]) == 'N') { + src->advance(4); + return -std::numeric_limits::quiet_NaN(); + } + // All bets are off throw std::range_error("Unable to convert \"" + src->toString() + "\" to a floating point value."); -- 2.34.1