| ... | ... | @@ -11161,6 +11161,38 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) { |
| 11161 | 11161 | } |
| 11162 | 11162 | } |
| 11163 | 11163 | |
| 11164 | static void value_to_bigfloat(BigFloat *out, ZigValue *val) { |
| 11165 | switch (val->type->id) { |
| 11166 | case ZigTypeIdInt: |
| 11167 | case ZigTypeIdComptimeInt: |
| 11168 | bigfloat_init_bigint(out, &val->data.x_bigint); |
| 11169 | return; |
| 11170 | case ZigTypeIdComptimeFloat: |
| 11171 | *out = val->data.x_bigfloat; |
| 11172 | return; |
| 11173 | case ZigTypeIdFloat: switch (val->type->data.floating.bit_count) { |
| 11174 | case 16: |
| 11175 | bigfloat_init_16(out, val->data.x_f16); |
| 11176 | return; |
| 11177 | case 32: |
| 11178 | bigfloat_init_32(out, val->data.x_f32); |
| 11179 | return; |
| 11180 | case 64: |
| 11181 | bigfloat_init_64(out, val->data.x_f64); |
| 11182 | return; |
| 11183 | case 80: |
| 11184 | zig_panic("TODO"); |
| 11185 | case 128: |
| 11186 | bigfloat_init_128(out, val->data.x_f128); |
| 11187 | return; |
| 11188 | default: |
| 11189 | zig_unreachable(); |
| 11190 | } |
| 11191 | default: |
| 11192 | zig_unreachable(); |
| 11193 | } |
| 11194 | } |
| 11195 | |
| 11164 | 11196 | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction, ZigType *other_type, |
| 11165 | 11197 | bool explicit_cast) |
| 11166 | 11198 | { |
| ... | ... | @@ -15825,39 +15857,31 @@ never_mind_just_calculate_it_normally: |
| 15825 | 15857 | |
| 15826 | 15858 | // Handle the case where one of the two operands is a fp value and the other |
| 15827 | 15859 | // is an integer value |
| 15828 | | ZigValue **int_val, **float_val; |
| 15829 | | |
| 15860 | ZigValue *float_val; |
| 15830 | 15861 | if (op1_is_int && op2_is_float) { |
| 15831 | | int_val = &op1_val; |
| 15832 | | float_val = &op2_val; |
| 15862 | float_val = op2_val; |
| 15833 | 15863 | } else if (op1_is_float && op2_is_int) { |
| 15834 | | int_val = &op2_val; |
| 15835 | | float_val = &op1_val; |
| 15864 | float_val = op1_val; |
| 15836 | 15865 | } else { |
| 15837 | 15866 | zig_unreachable(); |
| 15838 | 15867 | } |
| 15839 | 15868 | |
| 15840 | 15869 | // They can never be equal if the fp value has a non-zero decimal part |
| 15841 | 15870 | if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) { |
| 15842 | | if (float_has_fraction(*float_val)) { |
| 15871 | if (float_has_fraction(float_val)) { |
| 15843 | 15872 | out_val->special = ConstValSpecialStatic; |
| 15844 | 15873 | out_val->data.x_bool = op_id == IrBinOpCmpNotEq; |
| 15845 | | |
| 15846 | 15874 | return nullptr; |
| 15847 | 15875 | } |
| 15848 | 15876 | } |
| 15849 | 15877 | |
| 15850 | 15878 | // Cast the integer operand into a fp value to perform the comparison |
| 15851 | | { |
| 15852 | | IrInstruction *tmp = ir_const_noval(ira, source_instr); |
| 15853 | | tmp->value = *int_val; |
| 15854 | | IrInstruction *casted = ir_implicit_cast(ira, tmp, (*float_val)->type); |
| 15855 | | if (casted == ira->codegen->invalid_instruction) |
| 15856 | | return ira->codegen->trace_err; |
| 15857 | | *int_val = casted->value; |
| 15858 | | } |
| 15879 | BigFloat op1_bigfloat; |
| 15880 | BigFloat op2_bigfloat; |
| 15881 | value_to_bigfloat(&op1_bigfloat, op1_val); |
| 15882 | value_to_bigfloat(&op2_bigfloat, op2_val); |
| 15859 | 15883 | |
| 15860 | | Cmp cmp_result = bigfloat_cmp(&op1_val->data.x_bigfloat, &op2_val->data.x_bigfloat); |
| 15884 | Cmp cmp_result = bigfloat_cmp(&op1_bigfloat, &op2_bigfloat); |
| 15861 | 15885 | out_val->special = ConstValSpecialStatic; |
| 15862 | 15886 | out_val->data.x_bool = resolve_cmp_op_id(op_id, cmp_result); |
| 15863 | 15887 | |