mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Add f16
and f128
support
This commit is contained in:
parent
da27b89ca5
commit
d5db933f9d
28 changed files with 384 additions and 73 deletions
|
@ -489,6 +489,8 @@ impl ast::Byte {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rustc_apfloat::ieee::Quad as f128;
|
||||
|
||||
use crate::ast::{self, make, FloatNumber, IntNumber};
|
||||
|
||||
fn check_float_suffix<'a>(lit: &str, expected: impl Into<Option<&'a str>>) {
|
||||
|
@ -499,14 +501,16 @@ mod tests {
|
|||
assert_eq!(IntNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into());
|
||||
}
|
||||
|
||||
fn check_float_value(lit: &str, expected: impl Into<Option<f64>> + Copy) {
|
||||
// FIXME(#17451) Use `expected: f128` once `f128` is stabilised.
|
||||
fn check_float_value(lit: &str, expected: &str) {
|
||||
let expected = Some(expected.parse::<f128>().unwrap());
|
||||
assert_eq!(
|
||||
FloatNumber { syntax: make::tokens::literal(lit) }.value_string().parse::<f64>().ok(),
|
||||
expected.into()
|
||||
FloatNumber { syntax: make::tokens::literal(lit) }.value_string().parse::<f128>().ok(),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
IntNumber { syntax: make::tokens::literal(lit) }.value_string().parse::<f64>().ok(),
|
||||
expected.into()
|
||||
IntNumber { syntax: make::tokens::literal(lit) }.value_string().parse::<f128>().ok(),
|
||||
expected
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -520,9 +524,9 @@ mod tests {
|
|||
check_float_suffix("123f32", "f32");
|
||||
check_float_suffix("123.0e", None);
|
||||
check_float_suffix("123.0e4", None);
|
||||
check_float_suffix("123.0ef32", "f32");
|
||||
check_float_suffix("123.0ef16", "f16");
|
||||
check_float_suffix("123.0E4f32", "f32");
|
||||
check_float_suffix("1_2_3.0_f32", "f32");
|
||||
check_float_suffix("1_2_3.0_f128", "f128");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -589,8 +593,10 @@ bcde", b"abcde",
|
|||
|
||||
#[test]
|
||||
fn test_value_underscores() {
|
||||
check_float_value("1.234567891011121_f64", 1.234567891011121_f64);
|
||||
check_float_value("1__0.__0__f32", 10.0);
|
||||
check_float_value("1.3_4665449586950493453___6_f128", "1.346654495869504934536");
|
||||
check_float_value("1.234567891011121_f64", "1.234567891011121");
|
||||
check_float_value("1__0.__0__f32", "10.0");
|
||||
check_float_value("3._0_f16", "3.0");
|
||||
check_int_value("0b__1_0_", 2);
|
||||
check_int_value("1_1_1_1_1_1", 111111);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue