@@ -158,17 +158,38 @@ pub mod ast_ty {
158
158
. build_lit ( aster:: AstBuilder :: new ( ) . lit ( ) . byte_str ( string) )
159
159
}
160
160
161
- pub fn float_expr ( f : f64 ) -> P < ast:: Expr > {
161
+ pub fn float_expr ( ctx : & BindgenContext ,
162
+ f : f64 )
163
+ -> Result < P < ast:: Expr > , ( ) > {
162
164
use aster:: symbol:: ToSymbol ;
163
- let mut string = f. to_string ( ) ;
164
165
165
- // So it gets properly recognised as a floating point constant.
166
- if !string. contains ( '.' ) {
167
- string. push ( '.' ) ;
166
+ if f. is_finite ( ) {
167
+ let mut string = f. to_string ( ) ;
168
+
169
+ // So it gets properly recognised as a floating point constant.
170
+ if !string. contains ( '.' ) {
171
+ string. push ( '.' ) ;
172
+ }
173
+
174
+ let kind = ast:: LitKind :: FloatUnsuffixed ( string. as_str ( ) . to_symbol ( ) ) ;
175
+ return Ok ( aster:: AstBuilder :: new ( ) . expr ( ) . lit ( ) . build_lit ( kind) )
176
+ }
177
+
178
+ let prefix = ctx. trait_prefix ( ) ;
179
+ if f. is_nan ( ) {
180
+ return Ok ( quote_expr ! ( ctx. ext_cx( ) , :: $prefix:: f64 :: NAN ) ) ;
181
+ }
182
+
183
+ if f. is_infinite ( ) {
184
+ return Ok ( if f. is_sign_positive ( ) {
185
+ quote_expr ! ( ctx. ext_cx( ) , :: $prefix:: f64 :: INFINITY )
186
+ } else {
187
+ quote_expr ! ( ctx. ext_cx( ) , :: $prefix:: f64 :: NEG_INFINITY )
188
+ } ) ;
168
189
}
169
190
170
- let kind = ast :: LitKind :: FloatUnsuffixed ( string . as_str ( ) . to_symbol ( ) ) ;
171
- aster :: AstBuilder :: new ( ) . expr ( ) . lit ( ) . build_lit ( kind )
191
+ warn ! ( "Unknown non-finite float number: {:?}" , f ) ;
192
+ return Err ( ( ) ) ;
172
193
}
173
194
174
195
pub fn arguments_from_signature ( signature : & FunctionSig ,
0 commit comments