Skip to content

Commit

Permalink
LegacyTokenData: relax float check, round up max
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 16, 2024
1 parent 28856ff commit 392138f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
Expand Up @@ -2,6 +2,9 @@ package scala.meta
package internal
package tokenizers

import java.math.MathContext
import java.math.RoundingMode

import scala.meta.inputs._

trait LegacyTokenData {
Expand Down Expand Up @@ -114,6 +117,9 @@ trait LegacyTokenData {
}

object LegacyTokenData {
private val bigDecimalMaxFloat = BigDecimal(Float.MaxValue)
private val bigDecimalMaxDouble = BigDecimal(Double.MaxValue)
// add a bit more, JS doesn't handle it well
private val bigDecimalMaxFloat =
BigDecimal.binary(Float.MaxValue, new MathContext(8, RoundingMode.UP))
private val bigDecimalMaxDouble =
BigDecimal.binary(Double.MaxValue, new MathContext(32, RoundingMode.UP))
}
Expand Up @@ -389,8 +389,8 @@ class LitSuite extends ParseSuite {
("0L", 0L),
("0x80000000", -2147483648),
("0x8000000000000000L", -9223372036854775808L),
("3.40e+38f", 3.40e+38f),
("-3.40e+38f", -3.40e+38f),
("3.4028235e38f", Float.MaxValue),
("-3.4028235e38f", Float.MinValue),
("1.7976931348623157e+308d", Double.MaxValue),
("-1.7976931348623157e+308d", Double.MinValue),
("0b00101010", 42),
Expand Down Expand Up @@ -476,19 +476,6 @@ class LitSuite extends ParseSuite {
|.f
|^""".stripMargin
),
// these two are actually within range
(
"3.4028235e38f",
"""|<input>:1: error: floating-point value out of range for Float
|3.4028235e38f
|^""".stripMargin
),
(
"-3.4028235e38f",
"""|<input>:1: error: floating-point value out of range for Float
|-3.4028235e38f
| ^""".stripMargin
),
(
"3.4028236e38f",
"""|<input>:1: error: floating-point value out of range for Float
Expand Down
Expand Up @@ -1493,18 +1493,18 @@ class TokenizerSuite extends BaseTokenizerSuite {
|""".stripMargin
),
(
"3.40e+38f",
"3.4028235e38f",
"""|BOF [0..0)
|Constant.Float(3.40e+38f) [0..9)
|EOF [9..9)
|Constant.Float(3.4028235e38f) [0..13)
|EOF [13..13)
|""".stripMargin
),
(
"-3.40e+38f",
"-3.4028235e38f",
"""|BOF [0..0)
|Ident(-) [0..1)
|Constant.Float(3.40e+38f) [1..10)
|EOF [10..10)
|Constant.Float(3.4028235e38f) [1..14)
|EOF [14..14)
|""".stripMargin
),
(
Expand Down Expand Up @@ -1597,19 +1597,6 @@ class TokenizerSuite extends BaseTokenizerSuite {
|0b0123
| ^""".stripMargin
),
// these two are actually within range
(
"3.4028235e38f",
"""|<input>:1: error: floating-point value out of range for Float
|3.4028235e38f
|^""".stripMargin
),
(
"-3.4028235e38f",
"""|<input>:1: error: floating-point value out of range for Float
|-3.4028235e38f
| ^""".stripMargin
),
(
"3.4028236e38f",
"""|<input>:1: error: floating-point value out of range for Float
Expand Down

0 comments on commit 392138f

Please sign in to comment.