MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / float_limits

Function float_limits

cranelift/fuzzgen/src/passes/fcvt.rs:39–64  ·  view source on GitHub ↗

Gets the max and min float values for this integer type Inserts fconst instructions with these values. When converting to integers, floats are truncated. This means that the maximum float value that can be converted into an i8 is 127.99999. And surprisingly the minimum float for an u8 is -0.99999! So get the limits of this type as a float value by adding or subtracting 1.0 from its min and max in

(
    pos: &mut FuncCursor,
    float_ty: Type,
    int_ty: Type,
    is_signed: bool,
)

Source from the content-addressed store, hash-verified

37// u8 is -0.99999! So get the limits of this type as a float value by adding or subtracting
38// 1.0 from its min and max integer values.
39fn float_limits(
40 pos: &mut FuncCursor,
41 float_ty: Type,
42 int_ty: Type,
43 is_signed: bool,
44) -> (Value, Value) {
45 let (min_int, max_int) = int_ty.bounds(is_signed);
46
47 if float_ty == F32 {
48 let (min, max) = if is_signed {
49 ((min_int as i128) as f32, (max_int as i128) as f32)
50 } else {
51 (min_int as f32, max_int as f32)
52 };
53
54 (pos.ins().f32const(min - 1.0), pos.ins().f32const(max + 1.0))
55 } else {
56 let (min, max) = if is_signed {
57 ((min_int as i128) as f64, (max_int as i128) as f64)
58 } else {
59 (min_int as f64, max_int as f64)
60 };
61
62 (pos.ins().f64const(min - 1.0), pos.ins().f64const(max + 1.0))
63 }
64}
65
66/// Prepend instructions to inst to avoid traps
67fn insert_fcvt_sequence(pos: &mut FuncCursor, inst: Inst) {

Callers 1

insert_fcvt_sequenceFunction · 0.85

Calls 2

boundsMethod · 0.80
insMethod · 0.45

Tested by

no test coverage detected