File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -492,8 +492,15 @@ impl Literal {
492
492
Literal ( s. to_string ( ) )
493
493
}
494
494
495
- pub fn float ( s : f64 ) -> Literal {
496
- Literal ( s. to_string ( ) )
495
+ pub fn float ( n : f64 ) -> Literal {
496
+ if !n. is_finite ( ) {
497
+ panic ! ( "Invalid float literal {}" , n) ;
498
+ }
499
+ let mut s = n. to_string ( ) ;
500
+ if !s. contains ( '.' ) {
501
+ s += ".0" ;
502
+ }
503
+ Literal ( s)
497
504
}
498
505
499
506
pub fn integer ( s : i64 ) -> Literal {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ fn symbols() {
19
19
fn literals ( ) {
20
20
assert_eq ! ( Literal :: string( "foo" ) . to_string( ) , "\" foo\" " ) ;
21
21
assert_eq ! ( Literal :: string( "\" " ) . to_string( ) , "\" \\ \" \" " ) ;
22
+ assert_eq ! ( Literal :: float( 10.0 ) . to_string( ) , "10.0" ) ;
22
23
}
23
24
24
25
#[ test]
You can’t perform that action at this time.
0 commit comments