Skip to content

Commit

Permalink
no float magic
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Jan 23, 2024
1 parent 871e7df commit e0e6185
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
36 changes: 18 additions & 18 deletions crates/concrete_driver/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,27 @@ fn test_import() {
#[test]
fn test_floats() {
let source = r#"
mod Simple {
fn main() -> i64 {
let a: f32 = my_f32(2.0, 4.0);
let b: f64 = my_f64(2.0, 4.0);
return 1;
}
mod Simple {
fn main() -> i64 {
let a: f32 = my_f32(2.0, 4.0);
let b: f64 = my_f64(2.0, 4.0);
return 1;
}
fn my_f32(x: f32, y: f32) -> f32 {
let literal: f32 = 2.0;
let literal2: f32 = 2.;
let literal3: f32 = .1;
return x + y + literal2 + literal3;
}
fn my_f32(x: f32, y: f32) -> f32 {
let literal: f32 = 2.0;
let literal2: f32 = 2.001;
let literal3: f32 = 0.1;
return x + y + literal2 + literal3;
}
fn my_f64(x: f64, y: f64) -> f64 {
let literal: f64 = 2.0;
let literal2: f64 = 2.;
let literal3: f64 = .1;
return x + y + literal2 + literal3;
}
fn my_f64(x: f64, y: f64) -> f64 {
let literal: f64 = 2.0;
let literal2: f64 = 2.002;
let literal3: f64 = 0.02;
return x + y + literal2 + literal3;
}
}
"#;

let result = compile_program(source, "floats", false).expect("failed to compile");
Expand Down
2 changes: 1 addition & 1 deletion crates/concrete_parser/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub enum Token {
// Literals
#[regex(r"\d+", |lex| lex.slice().parse::<u128>().unwrap(), priority = 2)]
Integer(u128),
#[regex(r"([0-9]+([.][0-9]*)?|[.][0-9]+)", |lex| lex.slice().to_string(), priority = 1)]
#[regex(r"\d+\.\d+", |lex| lex.slice().to_string(), priority = 1)]
Float(String),
#[regex(r#""(?:[^"]|\\")*""#, |lex| {
let slice = lex.slice();
Expand Down
8 changes: 4 additions & 4 deletions examples/floats.con
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

fn my_f32(x: f32, y: f32) -> f32 {
let literal: f32 = 2.0;
let literal2: f32 = 2.;
let literal3: f32 = .1;
let literal2: f32 = 2.001;
let literal3: f32 = 0.1;
return x + y + literal2 + literal3;
}

fn my_f64(x: f64, y: f64) -> f64 {
let literal: f64 = 2.0;
let literal2: f64 = 2.;
let literal3: f64 = .1;
let literal2: f64 = 2.002;
let literal3: f64 = 0.02;
return x + y + literal2 + literal3;
}
}

0 comments on commit e0e6185

Please sign in to comment.