[libc-commits] [libc] d7cc760 - [libc][NFC] Fix typo and unused variable
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Fri Oct 29 12:43:11 PDT 2021
Author: Guillaume Chatelet
Date: 2021-10-29T19:42:51Z
New Revision: d7cc760f3b4971c220cdfaa3fc28a1809aebc710
URL: https://github.com/llvm/llvm-project/commit/d7cc760f3b4971c220cdfaa3fc28a1809aebc710
DIFF: https://github.com/llvm/llvm-project/commit/d7cc760f3b4971c220cdfaa3fc28a1809aebc710.diff
LOG: [libc][NFC] Fix typo and unused variable
Differential Revision: https://reviews.llvm.org/D112823
Added:
Modified:
libc/src/__support/high_precision_decimal.h
libc/src/__support/str_to_float.h
libc/test/src/__support/high_precision_decimal_test.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/high_precision_decimal.h b/libc/src/__support/high_precision_decimal.h
index b7fe1296e86b0..ae8aac37605ad 100644
--- a/libc/src/__support/high_precision_decimal.h
+++ b/libc/src/__support/high_precision_decimal.h
@@ -24,7 +24,7 @@ struct LShiftTableEntry {
// This is based on the HPD data structure described as part of the Simple
// Decimal Conversion algorithm by Nigel Tao, described at this link:
// https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
-class HighPrecsisionDecimal {
+class HighPrecisionDecimal {
// This precomputed table speeds up left shifts by having the number of new
// digits that will be added by multiplying 5^i by 2^i. If the number is less
@@ -277,9 +277,8 @@ class HighPrecsisionDecimal {
public:
// numString is assumed to be a string of numeric characters. It doesn't
// handle leading spaces.
- HighPrecsisionDecimal(const char *__restrict numString) {
+ HighPrecisionDecimal(const char *__restrict numString) {
bool sawDot = false;
- bool sawDigit = false;
while (isdigit(*numString) || *numString == '.') {
if (*numString == '.') {
if (sawDot) {
@@ -288,7 +287,6 @@ class HighPrecsisionDecimal {
this->decimalPoint = this->numDigits;
sawDot = true;
} else {
- sawDigit = true;
if (*numString == '0' && this->numDigits == 0) {
--this->decimalPoint;
++numString;
diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h
index 1ceba1561a5f6..b62e8ff4c4dc3 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -197,7 +197,7 @@ simpleDecimalConversion(const char *__restrict numStart,
uint32_t *outputExp2) {
int32_t exp2 = 0;
- HighPrecsisionDecimal hpd = HighPrecsisionDecimal(numStart);
+ HighPrecisionDecimal hpd = HighPrecisionDecimal(numStart);
if (hpd.getNumDigits() == 0) {
*outputMantissa = 0;
diff --git a/libc/test/src/__support/high_precision_decimal_test.cpp b/libc/test/src/__support/high_precision_decimal_test.cpp
index 02344269938e1..526452f23694b 100644
--- a/libc/test/src/__support/high_precision_decimal_test.cpp
+++ b/libc/test/src/__support/high_precision_decimal_test.cpp
@@ -11,8 +11,8 @@
#include "utils/UnitTest/Test.h"
TEST(LlvmLibcHighPrecisionDecimalTest, BasicInit) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal("1.2345");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal("1.2345");
uint8_t *digits = hpd.getDigits();
EXPECT_EQ(digits[0], uint8_t(1));
@@ -25,8 +25,8 @@ TEST(LlvmLibcHighPrecisionDecimalTest, BasicInit) {
}
TEST(LlvmLibcHighPrecisionDecimalTest, BasicShift) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal("1");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal("1");
uint8_t *digits = hpd.getDigits();
hpd.shift(1); // shift left 1, equal to multiplying by 2.
@@ -37,8 +37,8 @@ TEST(LlvmLibcHighPrecisionDecimalTest, BasicShift) {
}
TEST(LlvmLibcHighPrecisionDecimalTest, SmallShift) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal("1.2345");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal("1.2345");
uint8_t *digits = hpd.getDigits();
hpd.shift(-1); // shift right one, equal to dividing by 2
@@ -86,8 +86,8 @@ TEST(LlvmLibcHighPrecisionDecimalTest, SmallShift) {
}
TEST(LlvmLibcHighPrecisionDecimalTest, MediumShift) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal(".299792458");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal(".299792458");
uint8_t *digits = hpd.getDigits();
hpd.shift(-3); // shift right three, equal to dividing by 8
@@ -123,8 +123,8 @@ TEST(LlvmLibcHighPrecisionDecimalTest, MediumShift) {
}
TEST(LlvmLibcHighPrecisionDecimalTest, BigShift) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal(".299792458");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal(".299792458");
uint8_t *digits = hpd.getDigits();
hpd.shift(-29); // shift right 29, equal to dividing by 536,870,912
@@ -178,8 +178,8 @@ TEST(LlvmLibcHighPrecisionDecimalTest, BigShift) {
}
TEST(LlvmLibcHighPrecisionDecimalTest, BigShiftInSteps) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal("1");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal("1");
uint8_t *digits = hpd.getDigits();
hpd.shift(60); // shift left 60, equal to multiplying by
@@ -275,8 +275,8 @@ TEST(LlvmLibcHighPrecisionDecimalTest, BigShiftInSteps) {
}
TEST(LlvmLibcHighPrecisionDecimalTest, VeryBigShift) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal("1");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal("1");
uint8_t *digits = hpd.getDigits();
hpd.shift(100); // shift left 100, equal to multiplying by
@@ -328,8 +328,8 @@ TEST(LlvmLibcHighPrecisionDecimalTest, VeryBigShift) {
}
TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) {
- __llvm_libc::internal::HighPrecsisionDecimal hpd =
- __llvm_libc::internal::HighPrecsisionDecimal("1.2345");
+ __llvm_libc::internal::HighPrecisionDecimal hpd =
+ __llvm_libc::internal::HighPrecisionDecimal("1.2345");
EXPECT_EQ(hpd.roundToIntegerType<uint32_t>(), uint32_t(1));
EXPECT_EQ(hpd.roundToIntegerType<uint64_t>(), uint64_t(1));
@@ -348,7 +348,7 @@ TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) {
EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(5));
// 2.5 is right between two integers, so we round to even (2)
- hpd = __llvm_libc::internal::HighPrecsisionDecimal("2.5");
+ hpd = __llvm_libc::internal::HighPrecisionDecimal("2.5");
EXPECT_EQ(hpd.roundToIntegerType<uint32_t>(), uint32_t(2));
EXPECT_EQ(hpd.roundToIntegerType<uint64_t>(), uint64_t(2));
@@ -366,13 +366,13 @@ TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) {
// handled, so int types that are too small are ignored for this test.)
// 1099511627776 = 2^40
- hpd = __llvm_libc::internal::HighPrecsisionDecimal("1099511627776");
+ hpd = __llvm_libc::internal::HighPrecisionDecimal("1099511627776");
EXPECT_EQ(hpd.roundToIntegerType<uint64_t>(), uint64_t(1099511627776));
EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(1099511627776));
// 1267650600228229401496703205376 = 2^100
- hpd = __llvm_libc::internal::HighPrecsisionDecimal(
+ hpd = __llvm_libc::internal::HighPrecisionDecimal(
"1267650600228229401496703205376");
__uint128_t result = __uint128_t(1) << 100;
More information about the libc-commits
mailing list