Skip to content

Commit a56e228

Browse files
authored
Fixed float literal parsing off-by-one and underscore handling (#31)
1 parent f31addb commit a56e228

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Sources/MacroToolkit/FloatLiteral.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public struct FloatLiteral: LiteralProtocol {
100100

101101
fractionalPartValue =
102102
Double(fractionalPartDigitsValue)
103-
/ pow(Double(radix), Double(fractionalPart.count - 1))
103+
/ pow(Double(radix), Double(fractionalPartWithoutUnderscores.count))
104104
} else {
105105
fractionalPartValue = 0
106106
}

Tests/MacroToolkitTests/MacroToolkitTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ final class MacroToolkitTests: XCTestCase {
360360
XCTAssertEqual(FloatLiteral(hexFloatLiteral)?.value, -0xFp-2_)
361361
XCTAssertEqual(
362362
FloatLiteral(hexFloatLiteralWithFractional)?.value, -0xF.0f_ep-2_, "Fair enough")
363+
364+
XCTAssertEqual(FloatLiteral("1.1" as ExprSyntax)?.value, 1.1)
365+
XCTAssertEqual(FloatLiteral("10.02" as ExprSyntax)?.value, 10.02)
363366
}
364367

365368
func testStringLiteralParsing() {

0 commit comments

Comments
 (0)