mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 03:24:09 +00:00
Add accessors for the largest-magnitude, smallest-magnitude, and
smallest-normalized-magnitude values in a given FP semantics. Provide an APFloat-to-string conversion which I am quite ready to admit could be much more efficient. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92126 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -8,10 +8,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@ -21,6 +23,13 @@ static double convertToDoubleFromString(const char *Str) {
|
||||
return F.convertToDouble();
|
||||
}
|
||||
|
||||
static std::string convertToString(double d, unsigned Prec, unsigned Pad) {
|
||||
llvm::SmallVector<char, 100> Buffer;
|
||||
llvm::APFloat F(d);
|
||||
F.toString(Buffer, Prec, Pad);
|
||||
return std::string(Buffer.data(), Buffer.size());
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(APFloatTest, Zero) {
|
||||
@ -313,6 +322,17 @@ TEST(APFloatTest, fromHexadecimalString) {
|
||||
EXPECT_EQ(2.71828, convertToDoubleFromString("2.71828"));
|
||||
}
|
||||
|
||||
TEST(APFloatTest, toString) {
|
||||
ASSERT_EQ("10", convertToString(10.0, 6, 3));
|
||||
ASSERT_EQ("1.0E+1", convertToString(10.0, 6, 0));
|
||||
ASSERT_EQ("10100", convertToString(1.01E+4, 5, 2));
|
||||
ASSERT_EQ("1.01E+4", convertToString(1.01E+4, 4, 2));
|
||||
ASSERT_EQ("1.01E+4", convertToString(1.01E+4, 5, 1));
|
||||
ASSERT_EQ("0.0101", convertToString(1.01E-2, 5, 2));
|
||||
ASSERT_EQ("1.01E-2", convertToString(1.01E-2, 4, 2));
|
||||
ASSERT_EQ("1.01E-2", convertToString(1.01E-2, 5, 1));
|
||||
}
|
||||
|
||||
#ifdef GTEST_HAS_DEATH_TEST
|
||||
TEST(APFloatTest, SemanticsDeath) {
|
||||
EXPECT_DEATH(APFloat(APFloat::IEEEsingle, 0.0f).convertToDouble(), "Float semantics are not IEEEdouble");
|
||||
|
Reference in New Issue
Block a user