166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//===- llvm/unittest/ADT/APFloat.cpp - APFloat unit tests ---------------------===// 266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// The LLVM Compiler Infrastructure 466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// This file is distributed under the University of Illinois Open Source 666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// License. See LICENSE.TXT for details. 766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//===----------------------------------------------------------------------===// 966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 1066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include <ostream> 1166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include <string> 1266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Support/raw_ostream.h" 1366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "gtest/gtest.h" 1466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/APFloat.h" 1566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/APSInt.h" 1666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/SmallString.h" 1766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/SmallVector.h" 1866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 1966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumanusing namespace llvm; 2066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 2166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumanstatic double convertToDoubleFromString(const char *Str) { 2266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::APFloat F(0.0); 2366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman F.convertFromString(Str, llvm::APFloat::rmNearestTiesToEven); 2466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return F.convertToDouble(); 2566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 2666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 2766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumanstatic std::string convertToString(double d, unsigned Prec, unsigned Pad) { 2866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::SmallVector<char, 100> Buffer; 2966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman llvm::APFloat F(d); 3066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman F.toString(Buffer, Prec, Pad); 3166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return std::string(Buffer.data(), Buffer.size()); 3266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 3366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 3466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumannamespace { 3566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 3666b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, Zero) { 3766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.0f, APFloat(0.0f).convertToFloat()); 3866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0f, APFloat(-0.0f).convertToFloat()); 3966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(-0.0f).isNegative()); 4066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 4166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.0, APFloat(0.0).convertToDouble()); 4266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(-0.0).convertToDouble()); 4366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(-0.0).isNegative()); 4466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 4566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 4666b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, fromZeroDecimalString) { 4766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0").convertToDouble()); 4866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0").convertToDouble()); 4966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0").convertToDouble()); 5066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 5166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.").convertToDouble()); 5266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.").convertToDouble()); 5366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.").convertToDouble()); 5466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 5566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0").convertToDouble()); 5666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0").convertToDouble()); 5766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0").convertToDouble()); 5866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 5966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0").convertToDouble()); 6066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0").convertToDouble()); 6166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0").convertToDouble()); 6266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 6366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "00000.").convertToDouble()); 6466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+00000.").convertToDouble()); 6566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-00000.").convertToDouble()); 6666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 6766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, ".00000").convertToDouble()); 6866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.00000").convertToDouble()); 6966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.00000").convertToDouble()); 7066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 7166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0000.00000").convertToDouble()); 7266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0000.00000").convertToDouble()); 7366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0000.00000").convertToDouble()); 7466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 7566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 7666b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, fromZeroDecimalSingleExponentString) { 7766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e1").convertToDouble()); 7866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e1").convertToDouble()); 7966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e1").convertToDouble()); 8066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 8166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e+1").convertToDouble()); 8266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e+1").convertToDouble()); 8366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e+1").convertToDouble()); 8466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 8566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e-1").convertToDouble()); 8666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e-1").convertToDouble()); 8766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e-1").convertToDouble()); 8866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 8966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 9066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.e1").convertToDouble()); 9166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e1").convertToDouble()); 9266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e1").convertToDouble()); 9366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 9466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.e+1").convertToDouble()); 9566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e+1").convertToDouble()); 9666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e+1").convertToDouble()); 9766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 9866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.e-1").convertToDouble()); 9966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e-1").convertToDouble()); 10066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e-1").convertToDouble()); 10166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 10266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0e1").convertToDouble()); 10366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e1").convertToDouble()); 10466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e1").convertToDouble()); 10566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 10666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0e+1").convertToDouble()); 10766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e+1").convertToDouble()); 10866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e+1").convertToDouble()); 10966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 11066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0e-1").convertToDouble()); 11166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e-1").convertToDouble()); 11266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e-1").convertToDouble()); 11366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 11466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 11566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0e1").convertToDouble()); 11666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e1").convertToDouble()); 11766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e1").convertToDouble()); 11866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 11966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0e+1").convertToDouble()); 12066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e+1").convertToDouble()); 12166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e+1").convertToDouble()); 12266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 12366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0e-1").convertToDouble()); 12466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e-1").convertToDouble()); 12566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e-1").convertToDouble()); 12666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 12766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 12866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "000.0000e1").convertToDouble()); 12966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+000.0000e+1").convertToDouble()); 13066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-000.0000e+1").convertToDouble()); 13166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 13266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 13366b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, fromZeroDecimalLargeExponentString) { 13466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e1234").convertToDouble()); 13566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e1234").convertToDouble()); 13666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e1234").convertToDouble()); 13766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 13866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e+1234").convertToDouble()); 13966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e+1234").convertToDouble()); 14066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e+1234").convertToDouble()); 14166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 14266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e-1234").convertToDouble()); 14366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e-1234").convertToDouble()); 14466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e-1234").convertToDouble()); 14566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 14666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, "000.0000e1234").convertToDouble()); 14766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, "000.0000e-1234").convertToDouble()); 14866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 14966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, StringRef("0e1234\02", 6)).convertToDouble()); 15066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 15166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 15266b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, fromZeroHexadecimalString) { 15366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p1").convertToDouble()); 15466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p1").convertToDouble()); 15566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p1").convertToDouble()); 15666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 15766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p+1").convertToDouble()); 15866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p+1").convertToDouble()); 15966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p+1").convertToDouble()); 16066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 16166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p-1").convertToDouble()); 16266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p-1").convertToDouble()); 16366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p-1").convertToDouble()); 16466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 16566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 16666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1").convertToDouble()); 16766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p1").convertToDouble()); 16866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p1").convertToDouble()); 16966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 17066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p+1").convertToDouble()); 17166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p+1").convertToDouble()); 17266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p+1").convertToDouble()); 17366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 17466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p-1").convertToDouble()); 17566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p-1").convertToDouble()); 17666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p-1").convertToDouble()); 17766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 17866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 17966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.0p1").convertToDouble()); 18066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p1").convertToDouble()); 18166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p1").convertToDouble()); 18266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 18366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.0p+1").convertToDouble()); 18466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p+1").convertToDouble()); 18566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p+1").convertToDouble()); 18666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 18766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.0p-1").convertToDouble()); 18866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p-1").convertToDouble()); 18966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p-1").convertToDouble()); 19066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 19166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 19266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.0p1").convertToDouble()); 19366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p1").convertToDouble()); 19466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p1").convertToDouble()); 19566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 19666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.0p+1").convertToDouble()); 19766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p+1").convertToDouble()); 19866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p+1").convertToDouble()); 19966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 20066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.0p-1").convertToDouble()); 20166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p-1").convertToDouble()); 20266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p-1").convertToDouble()); 20366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 20466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 20566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x00000.p1").convertToDouble()); 20666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0000.00000p1").convertToDouble()); 20766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.00000p1").convertToDouble()); 20866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1").convertToDouble()); 20966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p1234").convertToDouble()); 21066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p1234").convertToDouble()); 21166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x00000.p1234").convertToDouble()); 21266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0000.00000p1234").convertToDouble()); 21366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.00000p1234").convertToDouble()); 21466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1234").convertToDouble()); 21566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 21666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 21766b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, fromDecimalString) { 21866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble, "1").convertToDouble()); 21966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.0, APFloat(APFloat::IEEEdouble, "2.").convertToDouble()); 22066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.5, APFloat(APFloat::IEEEdouble, ".5").convertToDouble()); 22166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble, "1.0").convertToDouble()); 22266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-2").convertToDouble()); 22366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-4.0, APFloat(APFloat::IEEEdouble, "-4.").convertToDouble()); 22466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.5, APFloat(APFloat::IEEEdouble, "-.5").convertToDouble()); 22566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-1.5, APFloat(APFloat::IEEEdouble, "-1.5").convertToDouble()); 22666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.25e12, APFloat(APFloat::IEEEdouble, "1.25e12").convertToDouble()); 22766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.25e+12, APFloat(APFloat::IEEEdouble, "1.25e+12").convertToDouble()); 22866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.25e-12, APFloat(APFloat::IEEEdouble, "1.25e-12").convertToDouble()); 22966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1024.0, APFloat(APFloat::IEEEdouble, "1024.").convertToDouble()); 23066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1024.05, APFloat(APFloat::IEEEdouble, "1024.05000").convertToDouble()); 23166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0.05, APFloat(APFloat::IEEEdouble, ".05000").convertToDouble()); 23266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.0, APFloat(APFloat::IEEEdouble, "2.").convertToDouble()); 23366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.0e2, APFloat(APFloat::IEEEdouble, "2.e2").convertToDouble()); 23466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.0e+2, APFloat(APFloat::IEEEdouble, "2.e+2").convertToDouble()); 23566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.0e-2, APFloat(APFloat::IEEEdouble, "2.e-2").convertToDouble()); 23666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.05e2, APFloat(APFloat::IEEEdouble, "002.05000e2").convertToDouble()); 23766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.05e+2, APFloat(APFloat::IEEEdouble, "002.05000e+2").convertToDouble()); 23866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.05e-2, APFloat(APFloat::IEEEdouble, "002.05000e-2").convertToDouble()); 23966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.05e12, APFloat(APFloat::IEEEdouble, "002.05000e12").convertToDouble()); 24066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.05e+12, APFloat(APFloat::IEEEdouble, "002.05000e+12").convertToDouble()); 24166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.05e-12, APFloat(APFloat::IEEEdouble, "002.05000e-12").convertToDouble()); 24266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 24366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // These are "carefully selected" to overflow the fast log-base 24466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // calculations in APFloat.cpp 24566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "99e99999").isInfinity()); 24666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "-99e99999").isInfinity()); 24766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "1e-99999").isPosZero()); 24866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "-1e-99999").isNegZero()); 24966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 25066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 25166b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, fromHexadecimalString) { 25266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble, "0x1p0").convertToDouble()); 25366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p0").convertToDouble()); 25466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p0").convertToDouble()); 25566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 25666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble, "0x1p+0").convertToDouble()); 25766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p+0").convertToDouble()); 25866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p+0").convertToDouble()); 25966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 26066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble, "0x1p-0").convertToDouble()); 26166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p-0").convertToDouble()); 26266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p-0").convertToDouble()); 26366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 26466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 26566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble, "0x1p1").convertToDouble()); 26666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble, "+0x1p1").convertToDouble()); 26766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-0x1p1").convertToDouble()); 26866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 26966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble, "0x1p+1").convertToDouble()); 27066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble, "+0x1p+1").convertToDouble()); 27166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-0x1p+1").convertToDouble()); 27266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 27366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.5, APFloat(APFloat::IEEEdouble, "0x1p-1").convertToDouble()); 27466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.5, APFloat(APFloat::IEEEdouble, "+0x1p-1").convertToDouble()); 27566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.5, APFloat(APFloat::IEEEdouble, "-0x1p-1").convertToDouble()); 27666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 27766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 27866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble, "0x1.8p1").convertToDouble()); 27966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble, "+0x1.8p1").convertToDouble()); 28066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble, "-0x1.8p1").convertToDouble()); 28166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 28266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble, "0x1.8p+1").convertToDouble()); 28366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble, "+0x1.8p+1").convertToDouble()); 28466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble, "-0x1.8p+1").convertToDouble()); 28566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 28666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.75, APFloat(APFloat::IEEEdouble, "0x1.8p-1").convertToDouble()); 28766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.75, APFloat(APFloat::IEEEdouble, "+0x1.8p-1").convertToDouble()); 28866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.75, APFloat(APFloat::IEEEdouble, "-0x1.8p-1").convertToDouble()); 28966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 29066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 29166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000.000p1").convertToDouble()); 29266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p1").convertToDouble()); 29366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p1").convertToDouble()); 29466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 29566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000.000p+1").convertToDouble()); 29666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p+1").convertToDouble()); 29766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p+1").convertToDouble()); 29866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 29966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble, "0x1000.000p-1").convertToDouble()); 30066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p-1").convertToDouble()); 30166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p-1").convertToDouble()); 30266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 30366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 30466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000p1").convertToDouble()); 30566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000p1").convertToDouble()); 30666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000p1").convertToDouble()); 30766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 30866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000p+1").convertToDouble()); 30966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000p+1").convertToDouble()); 31066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000p+1").convertToDouble()); 31166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 31266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble, "0x1000p-1").convertToDouble()); 31366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble, "+0x1000p-1").convertToDouble()); 31466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble, "-0x1000p-1").convertToDouble()); 31566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 31666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 31766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble, "0x10p10").convertToDouble()); 31866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble, "+0x10p10").convertToDouble()); 31966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble, "-0x10p10").convertToDouble()); 32066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 32166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble, "0x10p+10").convertToDouble()); 32266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble, "+0x10p+10").convertToDouble()); 32366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble, "-0x10p+10").convertToDouble()); 32466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 32566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ( 0.015625, APFloat(APFloat::IEEEdouble, "0x10p-10").convertToDouble()); 32666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(+0.015625, APFloat(APFloat::IEEEdouble, "+0x10p-10").convertToDouble()); 32766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(-0.015625, APFloat(APFloat::IEEEdouble, "-0x10p-10").convertToDouble()); 32866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 32966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.0625, APFloat(APFloat::IEEEdouble, "0x1.1p0").convertToDouble()); 33066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble, "0x1p0").convertToDouble()); 33166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 33266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2.71828, convertToDoubleFromString("2.71828")); 33366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 33466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 33566b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, toString) { 33666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("10", convertToString(10.0, 6, 3)); 33766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("1.0E+1", convertToString(10.0, 6, 0)); 33866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("10100", convertToString(1.01E+4, 5, 2)); 33966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("1.01E+4", convertToString(1.01E+4, 4, 2)); 34066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("1.01E+4", convertToString(1.01E+4, 5, 1)); 34166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("0.0101", convertToString(1.01E-2, 5, 2)); 34266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("0.0101", convertToString(1.01E-2, 4, 2)); 34366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("1.01E-2", convertToString(1.01E-2, 5, 1)); 34466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("0.7853981633974483", convertToString(0.78539816339744830961, 0, 3)); 34566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("4.940656458412465E-324", convertToString(4.9406564584124654e-324, 0, 3)); 34666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("873.1834", convertToString(873.1834, 0, 1)); 34766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ("8.731834E+2", convertToString(873.1834, 0, 0)); 34866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 34966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 35066b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, toInteger) { 35166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool isExact = false; 35266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APSInt result(5, /*isUnsigned=*/true); 35366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 35466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APFloat::opOK, 35566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat(APFloat::IEEEdouble, "10") 35666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman .convertToInteger(result, APFloat::rmTowardZero, &isExact)); 35766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(isExact); 35866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APSInt(APInt(5, 10), true), result); 35966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 36066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APFloat::opInvalidOp, 36166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat(APFloat::IEEEdouble, "-10") 36266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman .convertToInteger(result, APFloat::rmTowardZero, &isExact)); 36366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(isExact); 36466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APSInt::getMinValue(5, true), result); 36566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 36666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APFloat::opInvalidOp, 36766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat(APFloat::IEEEdouble, "32") 36866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman .convertToInteger(result, APFloat::rmTowardZero, &isExact)); 36966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(isExact); 37066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APSInt::getMaxValue(5, true), result); 37166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 37266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APFloat::opInexact, 37366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat(APFloat::IEEEdouble, "7.9") 37466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman .convertToInteger(result, APFloat::rmTowardZero, &isExact)); 37566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(isExact); 37666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APSInt(APInt(5, 7), true), result); 37766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 37866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman result.setIsUnsigned(false); 37966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APFloat::opOK, 38066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat(APFloat::IEEEdouble, "-10") 38166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman .convertToInteger(result, APFloat::rmTowardZero, &isExact)); 38266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(isExact); 38366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APSInt(APInt(5, -10, true), false), result); 38466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 38566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APFloat::opInvalidOp, 38666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat(APFloat::IEEEdouble, "-17") 38766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman .convertToInteger(result, APFloat::rmTowardZero, &isExact)); 38866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(isExact); 38966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APSInt::getMinValue(5, false), result); 39066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 39166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APFloat::opInvalidOp, 39266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat(APFloat::IEEEdouble, "16") 39366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman .convertToInteger(result, APFloat::rmTowardZero, &isExact)); 39466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(isExact); 39566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(APSInt::getMaxValue(5, false), result); 39666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 39766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 39866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumanstatic APInt nanbits(const fltSemantics &Sem, 39966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman bool SNaN, bool Negative, uint64_t fill) { 40066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APInt apfill(64, fill); 40166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman if (SNaN) 40266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return APFloat::getSNaN(Sem, Negative, &apfill).bitcastToAPInt(); 40366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman else 40466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return APFloat::getQNaN(Sem, Negative, &apfill).bitcastToAPInt(); 40566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 40666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 40766b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, makeNaN) { 40866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7fc00000, nanbits(APFloat::IEEEsingle, false, false, 0)); 40966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0xffc00000, nanbits(APFloat::IEEEsingle, false, true, 0)); 41066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7fc0ae72, nanbits(APFloat::IEEEsingle, false, false, 0xae72)); 41166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7fffae72, nanbits(APFloat::IEEEsingle, false, false, 0xffffae72)); 41266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7fa00000, nanbits(APFloat::IEEEsingle, true, false, 0)); 41366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0xffa00000, nanbits(APFloat::IEEEsingle, true, true, 0)); 41466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7f80ae72, nanbits(APFloat::IEEEsingle, true, false, 0xae72)); 41566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7fbfae72, nanbits(APFloat::IEEEsingle, true, false, 0xffffae72)); 41666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 41766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7ff8000000000000ULL, nanbits(APFloat::IEEEdouble, false, false, 0)); 41866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0xfff8000000000000ULL, nanbits(APFloat::IEEEdouble, false, true, 0)); 41966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7ff800000000ae72ULL, nanbits(APFloat::IEEEdouble, false, false, 0xae72)); 42066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7fffffffffffae72ULL, nanbits(APFloat::IEEEdouble, false, false, 0xffffffffffffae72ULL)); 42166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7ff4000000000000ULL, nanbits(APFloat::IEEEdouble, true, false, 0)); 42266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0xfff4000000000000ULL, nanbits(APFloat::IEEEdouble, true, true, 0)); 42366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7ff000000000ae72ULL, nanbits(APFloat::IEEEdouble, true, false, 0xae72)); 42466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ASSERT_EQ(0x7ff7ffffffffae72ULL, nanbits(APFloat::IEEEdouble, true, false, 0xffffffffffffae72ULL)); 42566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 42666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 42766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#ifdef GTEST_HAS_DEATH_TEST 42866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#ifndef NDEBUG 42966b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, SemanticsDeath) { 43066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEsingle, 0.0f).convertToDouble(), "Float semantics are not IEEEdouble"); 43166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, 0.0 ).convertToFloat(), "Float semantics are not IEEEsingle"); 43266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 43366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 43466b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, StringDecimalDeath) { 43566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ""), "Invalid string length"); 43666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+"), "String has no digits"); 43766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-"), "String has no digits"); 43866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 43966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("\0", 1)), "Invalid character in significand"); 44066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\0", 2)), "Invalid character in significand"); 44166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\02", 3)), "Invalid character in significand"); 44266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\02e1", 5)), "Invalid character in significand"); 44366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e\0", 3)), "Invalid character in exponent"); 44466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e1\0", 4)), "Invalid character in exponent"); 44566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e1\02", 5)), "Invalid character in exponent"); 44666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 44766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0f"), "Invalid character in significand"); 44866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 44966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".."), "String contains multiple dots"); 45066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "..0"), "String contains multiple dots"); 45166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0.0"), "String contains multiple dots"); 45266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 45366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 45466b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, StringDecimalSignificandDeath) { 45566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "."), "Significand has no digits"); 45666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+."), "Significand has no digits"); 45766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-."), "Significand has no digits"); 45866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 45966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 46066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "e"), "Significand has no digits"); 46166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+e"), "Significand has no digits"); 46266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-e"), "Significand has no digits"); 46366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 46466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "e1"), "Significand has no digits"); 46566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+e1"), "Significand has no digits"); 46666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-e1"), "Significand has no digits"); 46766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 46866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".e1"), "Significand has no digits"); 46966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.e1"), "Significand has no digits"); 47066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.e1"), "Significand has no digits"); 47166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 47266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 47366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".e"), "Significand has no digits"); 47466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.e"), "Significand has no digits"); 47566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.e"), "Significand has no digits"); 47666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 47766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 47866b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, StringDecimalExponentDeath) { 47966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e"), "Exponent has no digits"); 48066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+1e"), "Exponent has no digits"); 48166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-1e"), "Exponent has no digits"); 48266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 48366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.e"), "Exponent has no digits"); 48466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+1.e"), "Exponent has no digits"); 48566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-1.e"), "Exponent has no digits"); 48666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 48766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e"), "Exponent has no digits"); 48866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.1e"), "Exponent has no digits"); 48966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.1e"), "Exponent has no digits"); 49066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.1e"), "Exponent has no digits"); 49266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+1.1e"), "Exponent has no digits"); 49366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-1.1e"), "Exponent has no digits"); 49466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e+"), "Exponent has no digits"); 49766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e-"), "Exponent has no digits"); 49866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e"), "Exponent has no digits"); 50066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e+"), "Exponent has no digits"); 50166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e-"), "Exponent has no digits"); 50266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 50366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e"), "Exponent has no digits"); 50466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e+"), "Exponent has no digits"); 50566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e-"), "Exponent has no digits"); 50666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 50766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 50866b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, StringHexadecimalDeath) { 50966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x"), "Invalid string"); 51066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x"), "Invalid string"); 51166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x"), "Invalid string"); 51266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 51366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x0"), "Hex strings require an exponent"); 51466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0"), "Hex strings require an exponent"); 51566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0"), "Hex strings require an exponent"); 51666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 51766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x0."), "Hex strings require an exponent"); 51866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0."), "Hex strings require an exponent"); 51966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0."), "Hex strings require an exponent"); 52066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 52166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.0"), "Hex strings require an exponent"); 52266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.0"), "Hex strings require an exponent"); 52366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.0"), "Hex strings require an exponent"); 52466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 52566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x0.0"), "Hex strings require an exponent"); 52666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0.0"), "Hex strings require an exponent"); 52766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0.0"), "Hex strings require an exponent"); 52866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 52966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x\0", 3)), "Invalid character in significand"); 53066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\0", 4)), "Invalid character in significand"); 53166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\02", 5)), "Invalid character in significand"); 53266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\02p1", 7)), "Invalid character in significand"); 53366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p\0", 5)), "Invalid character in exponent"); 53466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p1\0", 6)), "Invalid character in exponent"); 53566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p1\02", 7)), "Invalid character in exponent"); 53666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 53766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p0f"), "Invalid character in exponent"); 53866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 53966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x..p1"), "String contains multiple dots"); 54066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x..0p1"), "String contains multiple dots"); 54166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.0.0p1"), "String contains multiple dots"); 54266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 54366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 54466b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, StringHexadecimalSignificandDeath) { 54566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x."), "Significand has no digits"); 54666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x."), "Significand has no digits"); 54766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x."), "Significand has no digits"); 54866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 54966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0xp"), "Significand has no digits"); 55066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp"), "Significand has no digits"); 55166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp"), "Significand has no digits"); 55266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 55366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0xp+"), "Significand has no digits"); 55466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp+"), "Significand has no digits"); 55566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp+"), "Significand has no digits"); 55666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 55766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0xp-"), "Significand has no digits"); 55866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp-"), "Significand has no digits"); 55966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp-"), "Significand has no digits"); 56066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 56166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 56266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.p"), "Significand has no digits"); 56366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p"), "Significand has no digits"); 56466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p"), "Significand has no digits"); 56566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 56666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.p+"), "Significand has no digits"); 56766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p+"), "Significand has no digits"); 56866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p+"), "Significand has no digits"); 56966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 57066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.p-"), "Significand has no digits"); 57166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p-"), "Significand has no digits"); 57266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p-"), "Significand has no digits"); 57366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 57466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 57566b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, StringHexadecimalExponentDeath) { 57666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p"), "Exponent has no digits"); 57766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p"), "Exponent has no digits"); 57866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p"), "Exponent has no digits"); 57966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 58066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p+"), "Exponent has no digits"); 58166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p+"), "Exponent has no digits"); 58266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p+"), "Exponent has no digits"); 58366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 58466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p-"), "Exponent has no digits"); 58566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p-"), "Exponent has no digits"); 58666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p-"), "Exponent has no digits"); 58766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 58866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 58966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.p"), "Exponent has no digits"); 59066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p"), "Exponent has no digits"); 59166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p"), "Exponent has no digits"); 59266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 59366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.p+"), "Exponent has no digits"); 59466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p+"), "Exponent has no digits"); 59566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p+"), "Exponent has no digits"); 59666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 59766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.p-"), "Exponent has no digits"); 59866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p-"), "Exponent has no digits"); 59966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p-"), "Exponent has no digits"); 60066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 60166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 60266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.1p"), "Exponent has no digits"); 60366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p"), "Exponent has no digits"); 60466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p"), "Exponent has no digits"); 60566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 60666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.1p+"), "Exponent has no digits"); 60766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p+"), "Exponent has no digits"); 60866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p+"), "Exponent has no digits"); 60966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 61066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.1p-"), "Exponent has no digits"); 61166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p-"), "Exponent has no digits"); 61266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p-"), "Exponent has no digits"); 61366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 61466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 61566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.1p"), "Exponent has no digits"); 61666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p"), "Exponent has no digits"); 61766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p"), "Exponent has no digits"); 61866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 61966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.1p+"), "Exponent has no digits"); 62066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p+"), "Exponent has no digits"); 62166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p+"), "Exponent has no digits"); 62266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 62366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.1p-"), "Exponent has no digits"); 62466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p-"), "Exponent has no digits"); 62566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p-"), "Exponent has no digits"); 62666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 62766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#endif 62866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#endif 62966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 63066b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, exactInverse) { 63166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman APFloat inv(0.0f); 63266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 63366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Trivial operation. 63466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(2.0).getExactInverse(&inv)); 63566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(0.5))); 63666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(2.0f).getExactInverse(&inv)); 63766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(0.5f))); 63866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 63966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // FLT_MIN 64066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(APFloat(1.17549435e-38f).getExactInverse(&inv)); 64166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(8.5070592e+37f))); 64266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 64366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Large float, inverse is a denormal. 64466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(APFloat(1.7014118e38f).getExactInverse(0)); 64566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Zero 64666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(APFloat(0.0).getExactInverse(0)); 64766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Denormalized float 64866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(APFloat(1.40129846e-45f).getExactInverse(0)); 64966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 65066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 65166b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanTEST(APFloatTest, getLargest) { 65266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(3.402823466e+38f, APFloat::getLargest(APFloat::IEEEsingle).convertToFloat()); 65366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble).convertToDouble()); 65466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 65566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 65666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 657