authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-17 02:57:07-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-17 02:57:07-04:00
log79120612267f55901029dd57290ee90c0a3ec987
tree60a30197720ccd8152db8112d0c271a595e725cf
parent06a26f0965deff3d752da3d448b34872010d80f3

remove integer and float casting syntax

* add `@intCast` * add `@floatCast` * add `@floatToInt` * add `@intToFloat` See #1061

85 files changed, 799 insertions(+), 413 deletions(-)

doc/langref.html.in+6-6
...@@ -1355,7 +1355,7 @@ var some_integers: [100]i32 = undefined;...@@ -1355,7 +1355,7 @@ var some_integers: [100]i32 = undefined;
13551355
1356test "modify an array" {1356test "modify an array" {
1357 for (some_integers) |*item, i| {1357 for (some_integers) |*item, i| {
1358 item.* = i32(i);1358 item.* = @intCast(i32, i);
1359 }1359 }
1360 assert(some_integers[10] == 10);1360 assert(some_integers[10] == 10);
1361 assert(some_integers[99] == 99);1361 assert(some_integers[99] == 99);
...@@ -1397,8 +1397,8 @@ var fancy_array = init: {...@@ -1397,8 +1397,8 @@ var fancy_array = init: {
1397 var initial_value: [10]Point = undefined;1397 var initial_value: [10]Point = undefined;
1398 for (initial_value) |*pt, i| {1398 for (initial_value) |*pt, i| {
1399 pt.* = Point{1399 pt.* = Point{
1400 .x = i32(i),1400 .x = @intCast(i32, i),
1401 .y = i32(i) * 2,1401 .y = @intCast(i32, i) * 2,
1402 };1402 };
1403 }1403 }
1404 break :init initial_value;1404 break :init initial_value;
...@@ -2410,7 +2410,7 @@ test "for basics" {...@@ -2410,7 +2410,7 @@ test "for basics" {
2410 var sum2: i32 = 0;2410 var sum2: i32 = 0;
2411 for (items) |value, i| {2411 for (items) |value, i| {
2412 assert(@typeOf(i) == usize);2412 assert(@typeOf(i) == usize);
2413 sum2 += i32(i);2413 sum2 += @intCast(i32, i);
2414 }2414 }
2415 assert(sum2 == 10);2415 assert(sum2 == 10);
2416}2416}
...@@ -5730,7 +5730,7 @@ comptime {...@@ -5730,7 +5730,7 @@ comptime {
5730 {#code_begin|test_err|attempt to cast negative value to unsigned integer#}5730 {#code_begin|test_err|attempt to cast negative value to unsigned integer#}
5731comptime {5731comptime {
5732 const value: i32 = -1;5732 const value: i32 = -1;
5733 const unsigned = u32(value);5733 const unsigned = @intCast(u32, value);
5734}5734}
5735 {#code_end#}5735 {#code_end#}
5736 <p>At runtime crashes with the message <code>attempt to cast negative value to unsigned integer</code> and a stack trace.</p>5736 <p>At runtime crashes with the message <code>attempt to cast negative value to unsigned integer</code> and a stack trace.</p>
...@@ -5744,7 +5744,7 @@ comptime {...@@ -5744,7 +5744,7 @@ comptime {
5744 {#code_begin|test_err|cast from 'u16' to 'u8' truncates bits#}5744 {#code_begin|test_err|cast from 'u16' to 'u8' truncates bits#}
5745comptime {5745comptime {
5746 const spartan_count: u16 = 300;5746 const spartan_count: u16 = 300;
5747 const byte = u8(spartan_count);5747 const byte = @intCast(u8, spartan_count);
5748}5748}
5749 {#code_end#}5749 {#code_end#}
5750 <p>At runtime crashes with the message <code>integer cast truncated bits</code> and a stack trace.</p>5750 <p>At runtime crashes with the message <code>integer cast truncated bits</code> and a stack trace.</p>
src/all_types.hpp+36
...@@ -1357,6 +1357,10 @@ enum BuiltinFnId {...@@ -1357,6 +1357,10 @@ enum BuiltinFnId {
1357 BuiltinFnIdMod,1357 BuiltinFnIdMod,
1358 BuiltinFnIdSqrt,1358 BuiltinFnIdSqrt,
1359 BuiltinFnIdTruncate,1359 BuiltinFnIdTruncate,
1360 BuiltinFnIdIntCast,
1361 BuiltinFnIdFloatCast,
1362 BuiltinFnIdIntToFloat,
1363 BuiltinFnIdFloatToInt,
1360 BuiltinFnIdIntType,1364 BuiltinFnIdIntType,
1361 BuiltinFnIdSetCold,1365 BuiltinFnIdSetCold,
1362 BuiltinFnIdSetRuntimeSafety,1366 BuiltinFnIdSetRuntimeSafety,
...@@ -2040,6 +2044,10 @@ enum IrInstructionId {...@@ -2040,6 +2044,10 @@ enum IrInstructionId {
2040 IrInstructionIdCmpxchg,2044 IrInstructionIdCmpxchg,
2041 IrInstructionIdFence,2045 IrInstructionIdFence,
2042 IrInstructionIdTruncate,2046 IrInstructionIdTruncate,
2047 IrInstructionIdIntCast,
2048 IrInstructionIdFloatCast,
2049 IrInstructionIdIntToFloat,
2050 IrInstructionIdFloatToInt,
2043 IrInstructionIdIntType,2051 IrInstructionIdIntType,
2044 IrInstructionIdBoolNot,2052 IrInstructionIdBoolNot,
2045 IrInstructionIdMemset,2053 IrInstructionIdMemset,
...@@ -2632,6 +2640,34 @@ struct IrInstructionTruncate {...@@ -2632,6 +2640,34 @@ struct IrInstructionTruncate {
2632 IrInstruction *target;2640 IrInstruction *target;
2633};2641};
26342642
2643struct IrInstructionIntCast {
2644 IrInstruction base;
2645
2646 IrInstruction *dest_type;
2647 IrInstruction *target;
2648};
2649
2650struct IrInstructionFloatCast {
2651 IrInstruction base;
2652
2653 IrInstruction *dest_type;
2654 IrInstruction *target;
2655};
2656
2657struct IrInstructionIntToFloat {
2658 IrInstruction base;
2659
2660 IrInstruction *dest_type;
2661 IrInstruction *target;
2662};
2663
2664struct IrInstructionFloatToInt {
2665 IrInstruction base;
2666
2667 IrInstruction *dest_type;
2668 IrInstruction *target;
2669};
2670
2635struct IrInstructionIntType {2671struct IrInstructionIntType {
2636 IrInstruction base;2672 IrInstruction base;
26372673
src/codegen.cpp+8
...@@ -4722,6 +4722,10 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -4722,6 +4722,10 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
4722 case IrInstructionIdPromiseResultType:4722 case IrInstructionIdPromiseResultType:
4723 case IrInstructionIdAwaitBookkeeping:4723 case IrInstructionIdAwaitBookkeeping:
4724 case IrInstructionIdAddImplicitReturnType:4724 case IrInstructionIdAddImplicitReturnType:
4725 case IrInstructionIdIntCast:
4726 case IrInstructionIdFloatCast:
4727 case IrInstructionIdIntToFloat:
4728 case IrInstructionIdFloatToInt:
4725 zig_unreachable();4729 zig_unreachable();
47264730
4727 case IrInstructionIdReturn:4731 case IrInstructionIdReturn:
...@@ -6310,6 +6314,10 @@ static void define_builtin_fns(CodeGen *g) {...@@ -6310,6 +6314,10 @@ static void define_builtin_fns(CodeGen *g) {
6310 create_builtin_fn(g, BuiltinFnIdCmpxchgStrong, "cmpxchgStrong", 6);6314 create_builtin_fn(g, BuiltinFnIdCmpxchgStrong, "cmpxchgStrong", 6);
6311 create_builtin_fn(g, BuiltinFnIdFence, "fence", 1);6315 create_builtin_fn(g, BuiltinFnIdFence, "fence", 1);
6312 create_builtin_fn(g, BuiltinFnIdTruncate, "truncate", 2);6316 create_builtin_fn(g, BuiltinFnIdTruncate, "truncate", 2);
6317 create_builtin_fn(g, BuiltinFnIdIntCast, "intCast", 2);
6318 create_builtin_fn(g, BuiltinFnIdFloatCast, "floatCast", 2);
6319 create_builtin_fn(g, BuiltinFnIdIntToFloat, "intToFloat", 2);
6320 create_builtin_fn(g, BuiltinFnIdFloatToInt, "floatToInt", 2);
6313 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);6321 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
6314 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);6322 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
6315 create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int6323 create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
src/ir.cpp+269-21
...@@ -460,6 +460,22 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) {...@@ -460,6 +460,22 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) {
460 return IrInstructionIdTruncate;460 return IrInstructionIdTruncate;
461}461}
462462
463static constexpr IrInstructionId ir_instruction_id(IrInstructionIntCast *) {
464 return IrInstructionIdIntCast;
465}
466
467static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatCast *) {
468 return IrInstructionIdFloatCast;
469}
470
471static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToFloat *) {
472 return IrInstructionIdIntToFloat;
473}
474
475static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatToInt *) {
476 return IrInstructionIdFloatToInt;
477}
478
463static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) {479static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) {
464 return IrInstructionIdIntType;480 return IrInstructionIdIntType;
465}481}
...@@ -1899,10 +1915,48 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1899,10 +1915,48 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s
1899 return &instruction->base;1915 return &instruction->base;
1900}1916}
19011917
1902static IrInstruction *ir_build_truncate_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *dest_type, IrInstruction *target) {1918static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
1903 IrInstruction *new_instruction = ir_build_truncate(irb, old_instruction->scope, old_instruction->source_node, dest_type, target);1919 IrInstructionIntCast *instruction = ir_build_instruction<IrInstructionIntCast>(irb, scope, source_node);
1904 ir_link_new_instruction(new_instruction, old_instruction);1920 instruction->dest_type = dest_type;
1905 return new_instruction;1921 instruction->target = target;
1922
1923 ir_ref_instruction(dest_type, irb->current_basic_block);
1924 ir_ref_instruction(target, irb->current_basic_block);
1925
1926 return &instruction->base;
1927}
1928
1929static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
1930 IrInstructionFloatCast *instruction = ir_build_instruction<IrInstructionFloatCast>(irb, scope, source_node);
1931 instruction->dest_type = dest_type;
1932 instruction->target = target;
1933
1934 ir_ref_instruction(dest_type, irb->current_basic_block);
1935 ir_ref_instruction(target, irb->current_basic_block);
1936
1937 return &instruction->base;
1938}
1939
1940static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
1941 IrInstructionIntToFloat *instruction = ir_build_instruction<IrInstructionIntToFloat>(irb, scope, source_node);
1942 instruction->dest_type = dest_type;
1943 instruction->target = target;
1944
1945 ir_ref_instruction(dest_type, irb->current_basic_block);
1946 ir_ref_instruction(target, irb->current_basic_block);
1947
1948 return &instruction->base;
1949}
1950
1951static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
1952 IrInstructionFloatToInt *instruction = ir_build_instruction<IrInstructionFloatToInt>(irb, scope, source_node);
1953 instruction->dest_type = dest_type;
1954 instruction->target = target;
1955
1956 ir_ref_instruction(dest_type, irb->current_basic_block);
1957 ir_ref_instruction(target, irb->current_basic_block);
1958
1959 return &instruction->base;
1906}1960}
19071961
1908static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_signed, IrInstruction *bit_count) {1962static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_signed, IrInstruction *bit_count) {
...@@ -3957,6 +4011,66 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -3957,6 +4011,66 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
3957 IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);4011 IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);
3958 return ir_lval_wrap(irb, scope, truncate, lval);4012 return ir_lval_wrap(irb, scope, truncate, lval);
3959 }4013 }
4014 case BuiltinFnIdIntCast:
4015 {
4016 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4017 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
4018 if (arg0_value == irb->codegen->invalid_instruction)
4019 return arg0_value;
4020
4021 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4022 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
4023 if (arg1_value == irb->codegen->invalid_instruction)
4024 return arg1_value;
4025
4026 IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);
4027 return ir_lval_wrap(irb, scope, result, lval);
4028 }
4029 case BuiltinFnIdFloatCast:
4030 {
4031 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4032 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
4033 if (arg0_value == irb->codegen->invalid_instruction)
4034 return arg0_value;
4035
4036 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4037 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
4038 if (arg1_value == irb->codegen->invalid_instruction)
4039 return arg1_value;
4040
4041 IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);
4042 return ir_lval_wrap(irb, scope, result, lval);
4043 }
4044 case BuiltinFnIdIntToFloat:
4045 {
4046 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4047 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
4048 if (arg0_value == irb->codegen->invalid_instruction)
4049 return arg0_value;
4050
4051 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4052 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
4053 if (arg1_value == irb->codegen->invalid_instruction)
4054 return arg1_value;
4055
4056 IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);
4057 return ir_lval_wrap(irb, scope, result, lval);
4058 }
4059 case BuiltinFnIdFloatToInt:
4060 {
4061 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4062 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
4063 if (arg0_value == irb->codegen->invalid_instruction)
4064 return arg0_value;
4065
4066 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4067 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
4068 if (arg1_value == irb->codegen->invalid_instruction)
4069 return arg1_value;
4070
4071 IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);
4072 return ir_lval_wrap(irb, scope, result, lval);
4073 }
3960 case BuiltinFnIdIntType:4074 case BuiltinFnIdIntType:
3961 {4075 {
3962 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);4076 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
...@@ -9948,34 +10062,37 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -9948,34 +10062,37 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
9948 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBoolToInt, false);10062 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBoolToInt, false);
9949 }10063 }
995010064
9951 // explicit widening or shortening cast10065 // explicit widening conversion
9952 if ((wanted_type->id == TypeTableEntryIdInt &&10066 if (wanted_type->id == TypeTableEntryIdInt &&
9953 actual_type->id == TypeTableEntryIdInt) ||10067 actual_type->id == TypeTableEntryIdInt &&
9954 (wanted_type->id == TypeTableEntryIdFloat &&10068 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&
9955 actual_type->id == TypeTableEntryIdFloat))10069 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)
9956 {10070 {
9957 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);10071 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
9958 }10072 }
995910073
9960 // explicit error set cast10074 // small enough unsigned ints can get casted to large enough signed ints
9961 if (wanted_type->id == TypeTableEntryIdErrorSet &&10075 if (wanted_type->id == TypeTableEntryIdInt && wanted_type->data.integral.is_signed &&
9962 actual_type->id == TypeTableEntryIdErrorSet)10076 actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed &&
10077 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)
9963 {10078 {
9964 return ir_analyze_err_set_cast(ira, source_instr, value, wanted_type);10079 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
9965 }10080 }
996610081
9967 // explicit cast from int to float10082 // explicit float widening conversion
9968 if (wanted_type->id == TypeTableEntryIdFloat &&10083 if (wanted_type->id == TypeTableEntryIdFloat &&
9969 actual_type->id == TypeTableEntryIdInt)10084 actual_type->id == TypeTableEntryIdFloat &&
10085 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)
9970 {10086 {
9971 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpIntToFloat, false);10087 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
9972 }10088 }
997310089
9974 // explicit cast from float to int10090
9975 if (wanted_type->id == TypeTableEntryIdInt &&10091 // explicit error set cast
9976 actual_type->id == TypeTableEntryIdFloat)10092 if (wanted_type->id == TypeTableEntryIdErrorSet &&
10093 actual_type->id == TypeTableEntryIdErrorSet)
9977 {10094 {
9978 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpFloatToInt, false);10095 return ir_analyze_err_set_cast(ira, source_instr, value, wanted_type);
9979 }10096 }
998010097
9981 // explicit cast from [N]T to []const T10098 // explicit cast from [N]T to []const T
...@@ -17365,7 +17482,126 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc...@@ -17365,7 +17482,126 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
17365 return dest_type;17482 return dest_type;
17366 }17483 }
1736717484
17368 ir_build_truncate_from(&ira->new_irb, &instruction->base, dest_type_value, target);17485 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,
17486 instruction->base.source_node, dest_type_value, target);
17487 ir_link_new_instruction(new_instruction, &instruction->base);
17488 return dest_type;
17489}
17490
17491static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
17492 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
17493 if (type_is_invalid(dest_type))
17494 return ira->codegen->builtin_types.entry_invalid;
17495
17496 if (dest_type->id != TypeTableEntryIdInt) {
17497 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
17498 return ira->codegen->builtin_types.entry_invalid;
17499 }
17500
17501 IrInstruction *target = instruction->target->other;
17502 if (type_is_invalid(target->value.type))
17503 return ira->codegen->builtin_types.entry_invalid;
17504
17505 if (target->value.type->id == TypeTableEntryIdComptimeInt) {
17506 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
17507 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type,
17508 CastOpNumLitToConcrete, false);
17509 if (type_is_invalid(result->value.type))
17510 return ira->codegen->builtin_types.entry_invalid;
17511 ir_link_new_instruction(result, &instruction->base);
17512 return dest_type;
17513 } else {
17514 return ira->codegen->builtin_types.entry_invalid;
17515 }
17516 }
17517
17518 if (target->value.type->id != TypeTableEntryIdInt) {
17519 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
17520 buf_ptr(&target->value.type->name)));
17521 return ira->codegen->builtin_types.entry_invalid;
17522 }
17523
17524 IrInstruction *result = ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);
17525 if (type_is_invalid(result->value.type))
17526 return ira->codegen->builtin_types.entry_invalid;
17527
17528 ir_link_new_instruction(result, &instruction->base);
17529 return dest_type;
17530}
17531
17532static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
17533 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
17534 if (type_is_invalid(dest_type))
17535 return ira->codegen->builtin_types.entry_invalid;
17536
17537 if (dest_type->id != TypeTableEntryIdFloat) {
17538 ir_add_error(ira, instruction->dest_type,
17539 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
17540 return ira->codegen->builtin_types.entry_invalid;
17541 }
17542
17543 IrInstruction *target = instruction->target->other;
17544 if (type_is_invalid(target->value.type))
17545 return ira->codegen->builtin_types.entry_invalid;
17546
17547 if (target->value.type->id == TypeTableEntryIdComptimeInt ||
17548 target->value.type->id == TypeTableEntryIdComptimeFloat)
17549 {
17550 if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
17551 CastOp op;
17552 if (target->value.type->id == TypeTableEntryIdComptimeInt) {
17553 op = CastOpIntToFloat;
17554 } else {
17555 op = CastOpNumLitToConcrete;
17556 }
17557 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, op, false);
17558 if (type_is_invalid(result->value.type))
17559 return ira->codegen->builtin_types.entry_invalid;
17560 ir_link_new_instruction(result, &instruction->base);
17561 return dest_type;
17562 } else {
17563 return ira->codegen->builtin_types.entry_invalid;
17564 }
17565 }
17566
17567 if (target->value.type->id != TypeTableEntryIdFloat) {
17568 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
17569 buf_ptr(&target->value.type->name)));
17570 return ira->codegen->builtin_types.entry_invalid;
17571 }
17572
17573 IrInstruction *result = ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);
17574 if (type_is_invalid(result->value.type))
17575 return ira->codegen->builtin_types.entry_invalid;
17576 ir_link_new_instruction(result, &instruction->base);
17577 return dest_type;
17578}
17579
17580static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
17581 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
17582 if (type_is_invalid(dest_type))
17583 return ira->codegen->builtin_types.entry_invalid;
17584
17585 IrInstruction *target = instruction->target->other;
17586 if (type_is_invalid(target->value.type))
17587 return ira->codegen->builtin_types.entry_invalid;
17588
17589 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat, false);
17590 ir_link_new_instruction(result, &instruction->base);
17591 return dest_type;
17592}
17593
17594static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
17595 TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
17596 if (type_is_invalid(dest_type))
17597 return ira->codegen->builtin_types.entry_invalid;
17598
17599 IrInstruction *target = instruction->target->other;
17600 if (type_is_invalid(target->value.type))
17601 return ira->codegen->builtin_types.entry_invalid;
17602
17603 IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
17604 ir_link_new_instruction(result, &instruction->base);
17369 return dest_type;17605 return dest_type;
17370}17606}
1737117607
...@@ -19899,6 +20135,14 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -19899,6 +20135,14 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
19899 return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction);20135 return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction);
19900 case IrInstructionIdTruncate:20136 case IrInstructionIdTruncate:
19901 return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction);20137 return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction);
20138 case IrInstructionIdIntCast:
20139 return ir_analyze_instruction_int_cast(ira, (IrInstructionIntCast *)instruction);
20140 case IrInstructionIdFloatCast:
20141 return ir_analyze_instruction_float_cast(ira, (IrInstructionFloatCast *)instruction);
20142 case IrInstructionIdIntToFloat:
20143 return ir_analyze_instruction_int_to_float(ira, (IrInstructionIntToFloat *)instruction);
20144 case IrInstructionIdFloatToInt:
20145 return ir_analyze_instruction_float_to_int(ira, (IrInstructionFloatToInt *)instruction);
19902 case IrInstructionIdIntType:20146 case IrInstructionIdIntType:
19903 return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction);20147 return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction);
19904 case IrInstructionIdBoolNot:20148 case IrInstructionIdBoolNot:
...@@ -20242,6 +20486,10 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -20242,6 +20486,10 @@ bool ir_has_side_effects(IrInstruction *instruction) {
20242 case IrInstructionIdPromiseResultType:20486 case IrInstructionIdPromiseResultType:
20243 case IrInstructionIdSqrt:20487 case IrInstructionIdSqrt:
20244 case IrInstructionIdAtomicLoad:20488 case IrInstructionIdAtomicLoad:
20489 case IrInstructionIdIntCast:
20490 case IrInstructionIdFloatCast:
20491 case IrInstructionIdIntToFloat:
20492 case IrInstructionIdFloatToInt:
20245 return false;20493 return false;
2024620494
20247 case IrInstructionIdAsm:20495 case IrInstructionIdAsm:
src/ir_print.cpp+44
...@@ -648,6 +648,38 @@ static void ir_print_truncate(IrPrint *irp, IrInstructionTruncate *instruction)...@@ -648,6 +648,38 @@ static void ir_print_truncate(IrPrint *irp, IrInstructionTruncate *instruction)
648 fprintf(irp->f, ")");648 fprintf(irp->f, ")");
649}649}
650650
651static void ir_print_int_cast(IrPrint *irp, IrInstructionIntCast *instruction) {
652 fprintf(irp->f, "@intCast(");
653 ir_print_other_instruction(irp, instruction->dest_type);
654 fprintf(irp->f, ", ");
655 ir_print_other_instruction(irp, instruction->target);
656 fprintf(irp->f, ")");
657}
658
659static void ir_print_float_cast(IrPrint *irp, IrInstructionFloatCast *instruction) {
660 fprintf(irp->f, "@floatCast(");
661 ir_print_other_instruction(irp, instruction->dest_type);
662 fprintf(irp->f, ", ");
663 ir_print_other_instruction(irp, instruction->target);
664 fprintf(irp->f, ")");
665}
666
667static void ir_print_int_to_float(IrPrint *irp, IrInstructionIntToFloat *instruction) {
668 fprintf(irp->f, "@intToFloat(");
669 ir_print_other_instruction(irp, instruction->dest_type);
670 fprintf(irp->f, ", ");
671 ir_print_other_instruction(irp, instruction->target);
672 fprintf(irp->f, ")");
673}
674
675static void ir_print_float_to_int(IrPrint *irp, IrInstructionFloatToInt *instruction) {
676 fprintf(irp->f, "@floatToInt(");
677 ir_print_other_instruction(irp, instruction->dest_type);
678 fprintf(irp->f, ", ");
679 ir_print_other_instruction(irp, instruction->target);
680 fprintf(irp->f, ")");
681}
682
651static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {683static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {
652 fprintf(irp->f, "@IntType(");684 fprintf(irp->f, "@IntType(");
653 ir_print_other_instruction(irp, instruction->is_signed);685 ir_print_other_instruction(irp, instruction->is_signed);
...@@ -1417,6 +1449,18 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1417,6 +1449,18 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1417 case IrInstructionIdTruncate:1449 case IrInstructionIdTruncate:
1418 ir_print_truncate(irp, (IrInstructionTruncate *)instruction);1450 ir_print_truncate(irp, (IrInstructionTruncate *)instruction);
1419 break;1451 break;
1452 case IrInstructionIdIntCast:
1453 ir_print_int_cast(irp, (IrInstructionIntCast *)instruction);
1454 break;
1455 case IrInstructionIdFloatCast:
1456 ir_print_float_cast(irp, (IrInstructionFloatCast *)instruction);
1457 break;
1458 case IrInstructionIdIntToFloat:
1459 ir_print_int_to_float(irp, (IrInstructionIntToFloat *)instruction);
1460 break;
1461 case IrInstructionIdFloatToInt:
1462 ir_print_float_to_int(irp, (IrInstructionFloatToInt *)instruction);
1463 break;
1420 case IrInstructionIdIntType:1464 case IrInstructionIdIntType:
1421 ir_print_int_type(irp, (IrInstructionIntType *)instruction);1465 ir_print_int_type(irp, (IrInstructionIntType *)instruction);
1422 break;1466 break;
src/main.cpp+1-1
...@@ -34,7 +34,7 @@ static int usage(const char *arg0) {...@@ -34,7 +34,7 @@ static int usage(const char *arg0) {
34 " --assembly [source] add assembly file to build\n"34 " --assembly [source] add assembly file to build\n"
35 " --cache-dir [path] override the cache directory\n"35 " --cache-dir [path] override the cache directory\n"
36 " --color [auto|off|on] enable or disable colored error messages\n"36 " --color [auto|off|on] enable or disable colored error messages\n"
37 " --emit [filetype] emit a specific file format as compilation output\n"37 " --emit [asm|bin|llvm-ir] emit a specific file format as compilation output\n"
38 " --enable-timing-info print timing diagnostics\n"38 " --enable-timing-info print timing diagnostics\n"
39 " --libc-include-dir [path] directory where libc stdlib.h resides\n"39 " --libc-include-dir [path] directory where libc stdlib.h resides\n"
40 " --name [name] override output name\n"40 " --name [name] override output name\n"
std/array_list.zig+4-4
...@@ -185,23 +185,23 @@ test "basic ArrayList test" {...@@ -185,23 +185,23 @@ test "basic ArrayList test" {
185 {185 {
186 var i: usize = 0;186 var i: usize = 0;
187 while (i < 10) : (i += 1) {187 while (i < 10) : (i += 1) {
188 list.append(i32(i + 1)) catch unreachable;188 list.append(@intCast(i32, i + 1)) catch unreachable;
189 }189 }
190 }190 }
191191
192 {192 {
193 var i: usize = 0;193 var i: usize = 0;
194 while (i < 10) : (i += 1) {194 while (i < 10) : (i += 1) {
195 assert(list.items[i] == i32(i + 1));195 assert(list.items[i] == @intCast(i32, i + 1));
196 }196 }
197 }197 }
198198
199 for (list.toSlice()) |v, i| {199 for (list.toSlice()) |v, i| {
200 assert(v == i32(i + 1));200 assert(v == @intCast(i32, i + 1));
201 }201 }
202202
203 for (list.toSliceConst()) |v, i| {203 for (list.toSliceConst()) |v, i| {
204 assert(v == i32(i + 1));204 assert(v == @intCast(i32, i + 1));
205 }205 }
206206
207 assert(list.pop() == 10);207 assert(list.pop() == 10);
std/base64.zig+2-2
...@@ -99,7 +99,7 @@ pub const Base64Decoder = struct {...@@ -99,7 +99,7 @@ pub const Base64Decoder = struct {
99 assert(!result.char_in_alphabet[c]);99 assert(!result.char_in_alphabet[c]);
100 assert(c != pad_char);100 assert(c != pad_char);
101101
102 result.char_to_index[c] = u8(i);102 result.char_to_index[c] = @intCast(u8, i);
103 result.char_in_alphabet[c] = true;103 result.char_in_alphabet[c] = true;
104 }104 }
105105
...@@ -284,7 +284,7 @@ pub const Base64DecoderUnsafe = struct {...@@ -284,7 +284,7 @@ pub const Base64DecoderUnsafe = struct {
284 };284 };
285 for (alphabet_chars) |c, i| {285 for (alphabet_chars) |c, i| {
286 assert(c != pad_char);286 assert(c != pad_char);
287 result.char_to_index[c] = u8(i);287 result.char_to_index[c] = @intCast(u8, i);
288 }288 }
289 return result;289 return result;
290 }290 }
std/crypto/blake2.zig+5-5
...@@ -79,7 +79,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -79,7 +79,7 @@ fn Blake2s(comptime out_len: usize) type {
79 mem.copy(u32, d.h[0..], iv[0..]);79 mem.copy(u32, d.h[0..], iv[0..]);
8080
81 // No key plus default parameters81 // No key plus default parameters
82 d.h[0] ^= 0x01010000 ^ u32(out_len >> 3);82 d.h[0] ^= 0x01010000 ^ @intCast(u32, out_len >> 3);
83 d.t = 0;83 d.t = 0;
84 d.buf_len = 0;84 d.buf_len = 0;
85 }85 }
...@@ -110,7 +110,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -110,7 +110,7 @@ fn Blake2s(comptime out_len: usize) type {
110110
111 // Copy any remainder for next pass.111 // Copy any remainder for next pass.
112 mem.copy(u8, d.buf[d.buf_len..], b[off..]);112 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
113 d.buf_len += u8(b[off..].len);113 d.buf_len += @intCast(u8, b[off..].len);
114 }114 }
115115
116 pub fn final(d: *Self, out: []u8) void {116 pub fn final(d: *Self, out: []u8) void {
...@@ -144,7 +144,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -144,7 +144,7 @@ fn Blake2s(comptime out_len: usize) type {
144 }144 }
145145
146 v[12] ^= @truncate(u32, d.t);146 v[12] ^= @truncate(u32, d.t);
147 v[13] ^= u32(d.t >> 32);147 v[13] ^= @intCast(u32, d.t >> 32);
148 if (last) v[14] = ~v[14];148 if (last) v[14] = ~v[14];
149149
150 const rounds = comptime []RoundParam{150 const rounds = comptime []RoundParam{
...@@ -345,7 +345,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -345,7 +345,7 @@ fn Blake2b(comptime out_len: usize) type {
345345
346 // Copy any remainder for next pass.346 // Copy any remainder for next pass.
347 mem.copy(u8, d.buf[d.buf_len..], b[off..]);347 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
348 d.buf_len += u8(b[off..].len);348 d.buf_len += @intCast(u8, b[off..].len);
349 }349 }
350350
351 pub fn final(d: *Self, out: []u8) void {351 pub fn final(d: *Self, out: []u8) void {
...@@ -377,7 +377,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -377,7 +377,7 @@ fn Blake2b(comptime out_len: usize) type {
377 }377 }
378378
379 v[12] ^= @truncate(u64, d.t);379 v[12] ^= @truncate(u64, d.t);
380 v[13] ^= u64(d.t >> 64);380 v[13] ^= @intCast(u64, d.t >> 64);
381 if (last) v[14] = ~v[14];381 if (last) v[14] = ~v[14];
382382
383 const rounds = comptime []RoundParam{383 const rounds = comptime []RoundParam{
std/crypto/md5.zig+3-3
...@@ -78,7 +78,7 @@ pub const Md5 = struct {...@@ -78,7 +78,7 @@ pub const Md5 = struct {
7878
79 // Copy any remainder for next pass.79 // Copy any remainder for next pass.
80 mem.copy(u8, d.buf[d.buf_len..], b[off..]);80 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
81 d.buf_len += u8(b[off..].len);81 d.buf_len += @intCast(u8, b[off..].len);
8282
83 // Md5 uses the bottom 64-bits for length padding83 // Md5 uses the bottom 64-bits for length padding
84 d.total_len +%= b.len;84 d.total_len +%= b.len;
...@@ -103,9 +103,9 @@ pub const Md5 = struct {...@@ -103,9 +103,9 @@ pub const Md5 = struct {
103 // Append message length.103 // Append message length.
104 var i: usize = 1;104 var i: usize = 1;
105 var len = d.total_len >> 5;105 var len = d.total_len >> 5;
106 d.buf[56] = u8(d.total_len & 0x1f) << 3;106 d.buf[56] = @intCast(u8, d.total_len & 0x1f) << 3;
107 while (i < 8) : (i += 1) {107 while (i < 8) : (i += 1) {
108 d.buf[56 + i] = u8(len & 0xff);108 d.buf[56 + i] = @intCast(u8, len & 0xff);
109 len >>= 8;109 len >>= 8;
110 }110 }
111111
std/crypto/sha1.zig+3-3
...@@ -78,7 +78,7 @@ pub const Sha1 = struct {...@@ -78,7 +78,7 @@ pub const Sha1 = struct {
7878
79 // Copy any remainder for next pass.79 // Copy any remainder for next pass.
80 mem.copy(u8, d.buf[d.buf_len..], b[off..]);80 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
81 d.buf_len += u8(b[off..].len);81 d.buf_len += @intCast(u8, b[off..].len);
8282
83 d.total_len += b.len;83 d.total_len += b.len;
84 }84 }
...@@ -102,9 +102,9 @@ pub const Sha1 = struct {...@@ -102,9 +102,9 @@ pub const Sha1 = struct {
102 // Append message length.102 // Append message length.
103 var i: usize = 1;103 var i: usize = 1;
104 var len = d.total_len >> 5;104 var len = d.total_len >> 5;
105 d.buf[63] = u8(d.total_len & 0x1f) << 3;105 d.buf[63] = @intCast(u8, d.total_len & 0x1f) << 3;
106 while (i < 8) : (i += 1) {106 while (i < 8) : (i += 1) {
107 d.buf[63 - i] = u8(len & 0xff);107 d.buf[63 - i] = @intCast(u8, len & 0xff);
108 len >>= 8;108 len >>= 8;
109 }109 }
110110
std/crypto/sha2.zig+6-6
...@@ -131,7 +131,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -131,7 +131,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
131131
132 // Copy any remainder for next pass.132 // Copy any remainder for next pass.
133 mem.copy(u8, d.buf[d.buf_len..], b[off..]);133 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
134 d.buf_len += u8(b[off..].len);134 d.buf_len += @intCast(u8, b[off..].len);
135135
136 d.total_len += b.len;136 d.total_len += b.len;
137 }137 }
...@@ -155,9 +155,9 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -155,9 +155,9 @@ fn Sha2_32(comptime params: Sha2Params32) type {
155 // Append message length.155 // Append message length.
156 var i: usize = 1;156 var i: usize = 1;
157 var len = d.total_len >> 5;157 var len = d.total_len >> 5;
158 d.buf[63] = u8(d.total_len & 0x1f) << 3;158 d.buf[63] = @intCast(u8, d.total_len & 0x1f) << 3;
159 while (i < 8) : (i += 1) {159 while (i < 8) : (i += 1) {
160 d.buf[63 - i] = u8(len & 0xff);160 d.buf[63 - i] = @intCast(u8, len & 0xff);
161 len >>= 8;161 len >>= 8;
162 }162 }
163163
...@@ -472,7 +472,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -472,7 +472,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
472472
473 // Copy any remainder for next pass.473 // Copy any remainder for next pass.
474 mem.copy(u8, d.buf[d.buf_len..], b[off..]);474 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
475 d.buf_len += u8(b[off..].len);475 d.buf_len += @intCast(u8, b[off..].len);
476476
477 d.total_len += b.len;477 d.total_len += b.len;
478 }478 }
...@@ -496,9 +496,9 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -496,9 +496,9 @@ fn Sha2_64(comptime params: Sha2Params64) type {
496 // Append message length.496 // Append message length.
497 var i: usize = 1;497 var i: usize = 1;
498 var len = d.total_len >> 5;498 var len = d.total_len >> 5;
499 d.buf[127] = u8(d.total_len & 0x1f) << 3;499 d.buf[127] = @intCast(u8, d.total_len & 0x1f) << 3;
500 while (i < 16) : (i += 1) {500 while (i < 16) : (i += 1) {
501 d.buf[127 - i] = u8(len & 0xff);501 d.buf[127 - i] = @intCast(u8, len & 0xff);
502 len >>= 8;502 len >>= 8;
503 }503 }
504504
std/debug/index.zig+4-4
...@@ -554,7 +554,7 @@ const LineNumberProgram = struct {...@@ -554,7 +554,7 @@ const LineNumberProgram = struct {
554 const file_name = try os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name);554 const file_name = try os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name);
555 errdefer self.file_entries.allocator.free(file_name);555 errdefer self.file_entries.allocator.free(file_name);
556 return LineInfo{556 return LineInfo{
557 .line = if (self.prev_line >= 0) usize(self.prev_line) else 0,557 .line = if (self.prev_line >= 0) @intCast(usize, self.prev_line) else 0,
558 .column = self.prev_column,558 .column = self.prev_column,
559 .file_name = file_name,559 .file_name = file_name,
560 .allocator = self.file_entries.allocator,560 .allocator = self.file_entries.allocator,
...@@ -1070,7 +1070,7 @@ fn readULeb128(in_stream: var) !u64 {...@@ -1070,7 +1070,7 @@ fn readULeb128(in_stream: var) !u64 {
10701070
1071 var operand: u64 = undefined;1071 var operand: u64 = undefined;
10721072
1073 if (@shlWithOverflow(u64, byte & 0b01111111, u6(shift), &operand)) return error.InvalidDebugInfo;1073 if (@shlWithOverflow(u64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;
10741074
1075 result |= operand;1075 result |= operand;
10761076
...@@ -1089,13 +1089,13 @@ fn readILeb128(in_stream: var) !i64 {...@@ -1089,13 +1089,13 @@ fn readILeb128(in_stream: var) !i64 {
10891089
1090 var operand: i64 = undefined;1090 var operand: i64 = undefined;
10911091
1092 if (@shlWithOverflow(i64, byte & 0b01111111, u6(shift), &operand)) return error.InvalidDebugInfo;1092 if (@shlWithOverflow(i64, byte & 0b01111111, @intCast(u6, shift), &operand)) return error.InvalidDebugInfo;
10931093
1094 result |= operand;1094 result |= operand;
1095 shift += 7;1095 shift += 7;
10961096
1097 if ((byte & 0b10000000) == 0) {1097 if ((byte & 0b10000000) == 0) {
1098 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << u6(shift));1098 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0) result |= -(i64(1) << @intCast(u6, shift));
1099 return result;1099 return result;
1100 }1100 }
1101 }1101 }
std/fmt/errol/index.zig+39-39
...@@ -29,11 +29,11 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro...@@ -29,11 +29,11 @@ pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: Ro
29 switch (mode) {29 switch (mode) {
30 RoundMode.Decimal => {30 RoundMode.Decimal => {
31 if (float_decimal.exp >= 0) {31 if (float_decimal.exp >= 0) {
32 round_digit = precision + usize(float_decimal.exp);32 round_digit = precision + @intCast(usize, float_decimal.exp);
33 } else {33 } else {
34 // if a small negative exp, then adjust we need to offset by the number34 // if a small negative exp, then adjust we need to offset by the number
35 // of leading zeros that will occur.35 // of leading zeros that will occur.
36 const min_exp_required = usize(-float_decimal.exp);36 const min_exp_required = @intCast(usize, -float_decimal.exp);
37 if (precision > min_exp_required) {37 if (precision > min_exp_required) {
38 round_digit = precision - min_exp_required;38 round_digit = precision - min_exp_required;
39 }39 }
...@@ -107,16 +107,16 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {...@@ -107,16 +107,16 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {
107 // normalize the midpoint107 // normalize the midpoint
108108
109 const e = math.frexp(val).exponent;109 const e = math.frexp(val).exponent;
110 var exp = i16(math.floor(307 + f64(e) * 0.30103));110 var exp = @floatToInt(i16, math.floor(307 + @intToFloat(f64, e) * 0.30103));
111 if (exp < 20) {111 if (exp < 20) {
112 exp = 20;112 exp = 20;
113 } else if (usize(exp) >= lookup_table.len) {113 } else if (@intCast(usize, exp) >= lookup_table.len) {
114 exp = i16(lookup_table.len - 1);114 exp = @intCast(i16, lookup_table.len - 1);
115 }115 }
116116
117 var mid = lookup_table[usize(exp)];117 var mid = lookup_table[@intCast(usize, exp)];
118 mid = hpProd(mid, val);118 mid = hpProd(mid, val);
119 const lten = lookup_table[usize(exp)].val;119 const lten = lookup_table[@intCast(usize, exp)].val;
120120
121 exp -= 307;121 exp -= 307;
122122
...@@ -168,25 +168,25 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {...@@ -168,25 +168,25 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {
168 // the 0-index for this extra digit.168 // the 0-index for this extra digit.
169 var buf_index: usize = 1;169 var buf_index: usize = 1;
170 while (true) {170 while (true) {
171 var hdig = u8(math.floor(high.val));171 var hdig = @floatToInt(u8, math.floor(high.val));
172 if ((high.val == f64(hdig)) and (high.off < 0)) hdig -= 1;172 if ((high.val == @intToFloat(f64, hdig)) and (high.off < 0)) hdig -= 1;
173173
174 var ldig = u8(math.floor(low.val));174 var ldig = @floatToInt(u8, math.floor(low.val));
175 if ((low.val == f64(ldig)) and (low.off < 0)) ldig -= 1;175 if ((low.val == @intToFloat(f64, ldig)) and (low.off < 0)) ldig -= 1;
176176
177 if (ldig != hdig) break;177 if (ldig != hdig) break;
178178
179 buffer[buf_index] = hdig + '0';179 buffer[buf_index] = hdig + '0';
180 buf_index += 1;180 buf_index += 1;
181 high.val -= f64(hdig);181 high.val -= @intToFloat(f64, hdig);
182 low.val -= f64(ldig);182 low.val -= @intToFloat(f64, ldig);
183 hpMul10(&high);183 hpMul10(&high);
184 hpMul10(&low);184 hpMul10(&low);
185 }185 }
186186
187 const tmp = (high.val + low.val) / 2.0;187 const tmp = (high.val + low.val) / 2.0;
188 var mdig = u8(math.floor(tmp + 0.5));188 var mdig = @floatToInt(u8, math.floor(tmp + 0.5));
189 if ((f64(mdig) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;189 if ((@intToFloat(f64, mdig) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
190190
191 buffer[buf_index] = mdig + '0';191 buffer[buf_index] = mdig + '0';
192 buf_index += 1;192 buf_index += 1;
...@@ -304,7 +304,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -304,7 +304,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
304304
305 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));305 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
306306
307 var mid = u128(val);307 var mid = @floatToInt(u128, val);
308 var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0);308 var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0);
309 var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0);309 var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0);
310310
...@@ -314,11 +314,11 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -314,11 +314,11 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
314 low -= 1;314 low -= 1;
315 }315 }
316316
317 var l64 = u64(low % pow19);317 var l64 = @intCast(u64, low % pow19);
318 const lf = u64((low / pow19) % pow19);318 const lf = @intCast(u64, (low / pow19) % pow19);
319319
320 var h64 = u64(high % pow19);320 var h64 = @intCast(u64, high % pow19);
321 const hf = u64((high / pow19) % pow19);321 const hf = @intCast(u64, (high / pow19) % pow19);
322322
323 if (lf != hf) {323 if (lf != hf) {
324 l64 = lf;324 l64 = lf;
...@@ -348,7 +348,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -348,7 +348,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
348348
349 return FloatDecimal{349 return FloatDecimal{
350 .digits = buffer[0..buf_index],350 .digits = buffer[0..buf_index],
351 .exp = i32(buf_index) + mi,351 .exp = @intCast(i32, buf_index) + mi,
352 };352 };
353}353}
354354
...@@ -359,33 +359,33 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {...@@ -359,33 +359,33 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
359fn errolFixed(val: f64, buffer: []u8) FloatDecimal {359fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
360 assert((val >= 16.0) and (val < 9.007199254740992e15));360 assert((val >= 16.0) and (val < 9.007199254740992e15));
361361
362 const u = u64(val);362 const u = @floatToInt(u64, val);
363 const n = f64(u);363 const n = @intToFloat(f64, u);
364364
365 var mid = val - n;365 var mid = val - n;
366 var lo = ((fpprev(val) - n) + mid) / 2.0;366 var lo = ((fpprev(val) - n) + mid) / 2.0;
367 var hi = ((fpnext(val) - n) + mid) / 2.0;367 var hi = ((fpnext(val) - n) + mid) / 2.0;
368368
369 var buf_index = u64toa(u, buffer);369 var buf_index = u64toa(u, buffer);
370 var exp = i32(buf_index);370 var exp = @intCast(i32, buf_index);
371 var j = buf_index;371 var j = buf_index;
372 buffer[j] = 0;372 buffer[j] = 0;
373373
374 if (mid != 0.0) {374 if (mid != 0.0) {
375 while (mid != 0.0) {375 while (mid != 0.0) {
376 lo *= 10.0;376 lo *= 10.0;
377 const ldig = i32(lo);377 const ldig = @floatToInt(i32, lo);
378 lo -= f64(ldig);378 lo -= @intToFloat(f64, ldig);
379379
380 mid *= 10.0;380 mid *= 10.0;
381 const mdig = i32(mid);381 const mdig = @floatToInt(i32, mid);
382 mid -= f64(mdig);382 mid -= @intToFloat(f64, mdig);
383383
384 hi *= 10.0;384 hi *= 10.0;
385 const hdig = i32(hi);385 const hdig = @floatToInt(i32, hi);
386 hi -= f64(hdig);386 hi -= @intToFloat(f64, hdig);
387387
388 buffer[j] = u8(mdig + '0');388 buffer[j] = @intCast(u8, mdig + '0');
389 j += 1;389 j += 1;
390390
391 if (hdig != ldig or j > 50) break;391 if (hdig != ldig or j > 50) break;
...@@ -452,7 +452,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -452,7 +452,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
452 var buf_index: usize = 0;452 var buf_index: usize = 0;
453453
454 if (value < kTen8) {454 if (value < kTen8) {
455 const v = u32(value);455 const v = @intCast(u32, value);
456 if (v < 10000) {456 if (v < 10000) {
457 const d1: u32 = (v / 100) << 1;457 const d1: u32 = (v / 100) << 1;
458 const d2: u32 = (v % 100) << 1;458 const d2: u32 = (v % 100) << 1;
...@@ -507,8 +507,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -507,8 +507,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
507 buf_index += 1;507 buf_index += 1;
508 }508 }
509 } else if (value < kTen16) {509 } else if (value < kTen16) {
510 const v0: u32 = u32(value / kTen8);510 const v0: u32 = @intCast(u32, value / kTen8);
511 const v1: u32 = u32(value % kTen8);511 const v1: u32 = @intCast(u32, value % kTen8);
512512
513 const b0: u32 = v0 / 10000;513 const b0: u32 = v0 / 10000;
514 const c0: u32 = v0 % 10000;514 const c0: u32 = v0 % 10000;
...@@ -578,11 +578,11 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -578,11 +578,11 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
578 buffer[buf_index] = c_digits_lut[d8 + 1];578 buffer[buf_index] = c_digits_lut[d8 + 1];
579 buf_index += 1;579 buf_index += 1;
580 } else {580 } else {
581 const a = u32(value / kTen16); // 1 to 1844581 const a = @intCast(u32, value / kTen16); // 1 to 1844
582 value %= kTen16;582 value %= kTen16;
583583
584 if (a < 10) {584 if (a < 10) {
585 buffer[buf_index] = '0' + u8(a);585 buffer[buf_index] = '0' + @intCast(u8, a);
586 buf_index += 1;586 buf_index += 1;
587 } else if (a < 100) {587 } else if (a < 100) {
588 const i: u32 = a << 1;588 const i: u32 = a << 1;
...@@ -591,7 +591,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -591,7 +591,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
591 buffer[buf_index] = c_digits_lut[i + 1];591 buffer[buf_index] = c_digits_lut[i + 1];
592 buf_index += 1;592 buf_index += 1;
593 } else if (a < 1000) {593 } else if (a < 1000) {
594 buffer[buf_index] = '0' + u8(a / 100);594 buffer[buf_index] = '0' + @intCast(u8, a / 100);
595 buf_index += 1;595 buf_index += 1;
596596
597 const i: u32 = (a % 100) << 1;597 const i: u32 = (a % 100) << 1;
...@@ -612,8 +612,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {...@@ -612,8 +612,8 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
612 buf_index += 1;612 buf_index += 1;
613 }613 }
614614
615 const v0 = u32(value / kTen8);615 const v0 = @intCast(u32, value / kTen8);
616 const v1 = u32(value % kTen8);616 const v1 = @intCast(u32, value % kTen8);
617617
618 const b0: u32 = v0 / 10000;618 const b0: u32 = v0 / 10000;
619 const c0: u32 = v0 % 10000;619 const c0: u32 = v0 % 10000;
std/fmt/index.zig+10-9
...@@ -5,6 +5,7 @@ const assert = debug.assert;...@@ -5,6 +5,7 @@ const assert = debug.assert;
5const mem = std.mem;5const mem = std.mem;
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const errol = @import("errol/index.zig");7const errol = @import("errol/index.zig");
8const lossyCast = std.math.lossyCast;
89
9const max_int_digits = 65;10const max_int_digits = 65;
1011
...@@ -463,7 +464,7 @@ pub fn formatFloatDecimal(...@@ -463,7 +464,7 @@ pub fn formatFloatDecimal(
463 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);464 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);
464465
465 // exp < 0 means the leading is always 0 as errol result is normalized.466 // exp < 0 means the leading is always 0 as errol result is normalized.
466 var num_digits_whole = if (float_decimal.exp > 0) usize(float_decimal.exp) else 0;467 var num_digits_whole = if (float_decimal.exp > 0) @intCast(usize, float_decimal.exp) else 0;
467468
468 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.469 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
469 var num_digits_whole_no_pad = math.min(num_digits_whole, float_decimal.digits.len);470 var num_digits_whole_no_pad = math.min(num_digits_whole, float_decimal.digits.len);
...@@ -492,7 +493,7 @@ pub fn formatFloatDecimal(...@@ -492,7 +493,7 @@ pub fn formatFloatDecimal(
492493
493 // Zero-fill until we reach significant digits or run out of precision.494 // Zero-fill until we reach significant digits or run out of precision.
494 if (float_decimal.exp <= 0) {495 if (float_decimal.exp <= 0) {
495 const zero_digit_count = usize(-float_decimal.exp);496 const zero_digit_count = @intCast(usize, -float_decimal.exp);
496 const zeros_to_print = math.min(zero_digit_count, precision);497 const zeros_to_print = math.min(zero_digit_count, precision);
497498
498 var i: usize = 0;499 var i: usize = 0;
...@@ -521,7 +522,7 @@ pub fn formatFloatDecimal(...@@ -521,7 +522,7 @@ pub fn formatFloatDecimal(
521 }522 }
522 } else {523 } else {
523 // exp < 0 means the leading is always 0 as errol result is normalized.524 // exp < 0 means the leading is always 0 as errol result is normalized.
524 var num_digits_whole = if (float_decimal.exp > 0) usize(float_decimal.exp) else 0;525 var num_digits_whole = if (float_decimal.exp > 0) @intCast(usize, float_decimal.exp) else 0;
525526
526 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.527 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
527 var num_digits_whole_no_pad = math.min(num_digits_whole, float_decimal.digits.len);528 var num_digits_whole_no_pad = math.min(num_digits_whole, float_decimal.digits.len);
...@@ -547,7 +548,7 @@ pub fn formatFloatDecimal(...@@ -547,7 +548,7 @@ pub fn formatFloatDecimal(
547548
548 // Zero-fill until we reach significant digits or run out of precision.549 // Zero-fill until we reach significant digits or run out of precision.
549 if (float_decimal.exp < 0) {550 if (float_decimal.exp < 0) {
550 const zero_digit_count = usize(-float_decimal.exp);551 const zero_digit_count = @intCast(usize, -float_decimal.exp);
551552
552 var i: usize = 0;553 var i: usize = 0;
553 while (i < zero_digit_count) : (i += 1) {554 while (i < zero_digit_count) : (i += 1) {
...@@ -578,7 +579,7 @@ pub fn formatBytes(...@@ -578,7 +579,7 @@ pub fn formatBytes(
578 1024 => math.min(math.log2(value) / 10, mags_iec.len - 1),579 1024 => math.min(math.log2(value) / 10, mags_iec.len - 1),
579 else => unreachable,580 else => unreachable,
580 };581 };
581 const new_value = f64(value) / math.pow(f64, f64(radix), f64(magnitude));582 const new_value = lossyCast(f64, value) / math.pow(f64, lossyCast(f64, radix), lossyCast(f64, magnitude));
582 const suffix = switch (radix) {583 const suffix = switch (radix) {
583 1000 => mags_si[magnitude],584 1000 => mags_si[magnitude],
584 1024 => mags_iec[magnitude],585 1024 => mags_iec[magnitude],
...@@ -628,15 +629,15 @@ fn formatIntSigned(...@@ -628,15 +629,15 @@ fn formatIntSigned(
628 if (value < 0) {629 if (value < 0) {
629 const minus_sign: u8 = '-';630 const minus_sign: u8 = '-';
630 try output(context, (*[1]u8)(&minus_sign)[0..]);631 try output(context, (*[1]u8)(&minus_sign)[0..]);
631 const new_value = uint(-(value + 1)) + 1;632 const new_value = @intCast(uint, -(value + 1)) + 1;
632 const new_width = if (width == 0) 0 else (width - 1);633 const new_width = if (width == 0) 0 else (width - 1);
633 return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output);634 return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output);
634 } else if (width == 0) {635 } else if (width == 0) {
635 return formatIntUnsigned(uint(value), base, uppercase, width, context, Errors, output);636 return formatIntUnsigned(@intCast(uint, value), base, uppercase, width, context, Errors, output);
636 } else {637 } else {
637 const plus_sign: u8 = '+';638 const plus_sign: u8 = '+';
638 try output(context, (*[1]u8)(&plus_sign)[0..]);639 try output(context, (*[1]u8)(&plus_sign)[0..]);
639 const new_value = uint(value);640 const new_value = @intCast(uint, value);
640 const new_width = if (width == 0) 0 else (width - 1);641 const new_width = if (width == 0) 0 else (width - 1);
641 return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output);642 return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output);
642 }643 }
...@@ -660,7 +661,7 @@ fn formatIntUnsigned(...@@ -660,7 +661,7 @@ fn formatIntUnsigned(
660 while (true) {661 while (true) {
661 const digit = a % base;662 const digit = a % base;
662 index -= 1;663 index -= 1;
663 buf[index] = digitToChar(u8(digit), uppercase);664 buf[index] = digitToChar(@intCast(u8, digit), uppercase);
664 a /= base;665 a /= base;
665 if (a == 0) break;666 if (a == 0) break;
666 }667 }
std/hash/crc.zig+2-2
...@@ -26,7 +26,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {...@@ -26,7 +26,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
26 var tables: [8][256]u32 = undefined;26 var tables: [8][256]u32 = undefined;
2727
28 for (tables[0]) |*e, i| {28 for (tables[0]) |*e, i| {
29 var crc = u32(i);29 var crc = @intCast(u32, i);
30 var j: usize = 0;30 var j: usize = 0;
31 while (j < 8) : (j += 1) {31 while (j < 8) : (j += 1) {
32 if (crc & 1 == 1) {32 if (crc & 1 == 1) {
...@@ -122,7 +122,7 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {...@@ -122,7 +122,7 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {
122 var table: [16]u32 = undefined;122 var table: [16]u32 = undefined;
123123
124 for (table) |*e, i| {124 for (table) |*e, i| {
125 var crc = u32(i * 16);125 var crc = @intCast(u32, i * 16);
126 var j: usize = 0;126 var j: usize = 0;
127 while (j < 8) : (j += 1) {127 while (j < 8) : (j += 1) {
128 if (crc & 1 == 1) {128 if (crc & 1 == 1) {
std/hash/siphash.zig+3-3
...@@ -81,7 +81,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -81,7 +81,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
8181
82 // Remainder for next pass.82 // Remainder for next pass.
83 mem.copy(u8, d.buf[d.buf_len..], b[off..]);83 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
84 d.buf_len += u8(b[off..].len);84 d.buf_len += @intCast(u8, b[off..].len);
85 d.msg_len +%= @truncate(u8, b.len);85 d.msg_len +%= @truncate(u8, b.len);
86 }86 }
8787
...@@ -233,7 +233,7 @@ test "siphash64-2-4 sanity" {...@@ -233,7 +233,7 @@ test "siphash64-2-4 sanity" {
233233
234 var buffer: [64]u8 = undefined;234 var buffer: [64]u8 = undefined;
235 for (vectors) |vector, i| {235 for (vectors) |vector, i| {
236 buffer[i] = u8(i);236 buffer[i] = @intCast(u8, i);
237237
238 const expected = mem.readInt(vector, u64, Endian.Little);238 const expected = mem.readInt(vector, u64, Endian.Little);
239 debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);239 debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);
...@@ -312,7 +312,7 @@ test "siphash128-2-4 sanity" {...@@ -312,7 +312,7 @@ test "siphash128-2-4 sanity" {
312312
313 var buffer: [64]u8 = undefined;313 var buffer: [64]u8 = undefined;
314 for (vectors) |vector, i| {314 for (vectors) |vector, i| {
315 buffer[i] = u8(i);315 buffer[i] = @intCast(u8, i);
316316
317 const expected = mem.readInt(vector, u128, Endian.Little);317 const expected = mem.readInt(vector, u128, Endian.Little);
318 debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);318 debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);
std/heap.zig+1-1
...@@ -408,7 +408,7 @@ fn testAllocator(allocator: *mem.Allocator) !void {...@@ -408,7 +408,7 @@ fn testAllocator(allocator: *mem.Allocator) !void {
408408
409 for (slice) |*item, i| {409 for (slice) |*item, i| {
410 item.* = try allocator.create(i32);410 item.* = try allocator.create(i32);
411 item.*.* = i32(i);411 item.*.* = @intCast(i32, i);
412 }412 }
413413
414 for (slice) |item, i| {414 for (slice) |item, i| {
std/json.zig+1-1
...@@ -180,7 +180,7 @@ pub const StreamingParser = struct {...@@ -180,7 +180,7 @@ pub const StreamingParser = struct {
180 pub fn fromInt(x: var) State {180 pub fn fromInt(x: var) State {
181 debug.assert(x == 0 or x == 1);181 debug.assert(x == 0 or x == 1);
182 const T = @TagType(State);182 const T = @TagType(State);
183 return State(T(x));183 return State(@intCast(T, x));
184 }184 }
185 };185 };
186186
std/math/acos.zig+2-2
...@@ -95,12 +95,12 @@ fn acos64(x: f64) f64 {...@@ -95,12 +95,12 @@ fn acos64(x: f64) f64 {
95 const pio2_lo: f64 = 6.12323399573676603587e-17;95 const pio2_lo: f64 = 6.12323399573676603587e-17;
9696
97 const ux = @bitCast(u64, x);97 const ux = @bitCast(u64, x);
98 const hx = u32(ux >> 32);98 const hx = @intCast(u32, ux >> 32);
99 const ix = hx & 0x7FFFFFFF;99 const ix = hx & 0x7FFFFFFF;
100100
101 // |x| >= 1 or nan101 // |x| >= 1 or nan
102 if (ix >= 0x3FF00000) {102 if (ix >= 0x3FF00000) {
103 const lx = u32(ux & 0xFFFFFFFF);103 const lx = @intCast(u32, ux & 0xFFFFFFFF);
104104
105 // acos(1) = 0, acos(-1) = pi105 // acos(1) = 0, acos(-1) = pi
106 if ((ix - 0x3FF00000) | lx == 0) {106 if ((ix - 0x3FF00000) | lx == 0) {
std/math/asin.zig+2-2
...@@ -87,12 +87,12 @@ fn asin64(x: f64) f64 {...@@ -87,12 +87,12 @@ fn asin64(x: f64) f64 {
87 const pio2_lo: f64 = 6.12323399573676603587e-17;87 const pio2_lo: f64 = 6.12323399573676603587e-17;
8888
89 const ux = @bitCast(u64, x);89 const ux = @bitCast(u64, x);
90 const hx = u32(ux >> 32);90 const hx = @intCast(u32, ux >> 32);
91 const ix = hx & 0x7FFFFFFF;91 const ix = hx & 0x7FFFFFFF;
9292
93 // |x| >= 1 or nan93 // |x| >= 1 or nan
94 if (ix >= 0x3FF00000) {94 if (ix >= 0x3FF00000) {
95 const lx = u32(ux & 0xFFFFFFFF);95 const lx = @intCast(u32, ux & 0xFFFFFFFF);
9696
97 // asin(1) = +-pi/2 with inexact97 // asin(1) = +-pi/2 with inexact
98 if ((ix - 0x3FF00000) | lx == 0) {98 if ((ix - 0x3FF00000) | lx == 0) {
std/math/atan.zig+2-2
...@@ -138,7 +138,7 @@ fn atan64(x_: f64) f64 {...@@ -138,7 +138,7 @@ fn atan64(x_: f64) f64 {
138138
139 var x = x_;139 var x = x_;
140 var ux = @bitCast(u64, x);140 var ux = @bitCast(u64, x);
141 var ix = u32(ux >> 32);141 var ix = @intCast(u32, ux >> 32);
142 const sign = ix >> 31;142 const sign = ix >> 31;
143 ix &= 0x7FFFFFFF;143 ix &= 0x7FFFFFFF;
144144
...@@ -159,7 +159,7 @@ fn atan64(x_: f64) f64 {...@@ -159,7 +159,7 @@ fn atan64(x_: f64) f64 {
159 // |x| < 2^(-27)159 // |x| < 2^(-27)
160 if (ix < 0x3E400000) {160 if (ix < 0x3E400000) {
161 if (ix < 0x00100000) {161 if (ix < 0x00100000) {
162 math.forceEval(f32(x));162 math.forceEval(@floatCast(f32, x));
163 }163 }
164 return x;164 return x;
165 }165 }
std/math/atan2.zig+4-4
...@@ -124,12 +124,12 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -124,12 +124,12 @@ fn atan2_64(y: f64, x: f64) f64 {
124 }124 }
125125
126 var ux = @bitCast(u64, x);126 var ux = @bitCast(u64, x);
127 var ix = u32(ux >> 32);127 var ix = @intCast(u32, ux >> 32);
128 var lx = u32(ux & 0xFFFFFFFF);128 var lx = @intCast(u32, ux & 0xFFFFFFFF);
129129
130 var uy = @bitCast(u64, y);130 var uy = @bitCast(u64, y);
131 var iy = u32(uy >> 32);131 var iy = @intCast(u32, uy >> 32);
132 var ly = u32(uy & 0xFFFFFFFF);132 var ly = @intCast(u32, uy & 0xFFFFFFFF);
133133
134 // x = 1.0134 // x = 1.0
135 if ((ix -% 0x3FF00000) | lx == 0) {135 if ((ix -% 0x3FF00000) | lx == 0) {
std/math/atanh.zig+1-1
...@@ -62,7 +62,7 @@ fn atanh_64(x: f64) f64 {...@@ -62,7 +62,7 @@ fn atanh_64(x: f64) f64 {
62 if (e < 0x3FF - 32) {62 if (e < 0x3FF - 32) {
63 // underflow63 // underflow
64 if (e == 0) {64 if (e == 0) {
65 math.forceEval(f32(y));65 math.forceEval(@floatCast(f32, y));
66 }66 }
67 }67 }
68 // |x| < 0.568 // |x| < 0.5
std/math/big/int.zig+11-11
...@@ -135,7 +135,7 @@ pub const Int = struct {...@@ -135,7 +135,7 @@ pub const Int = struct {
135 self.positive = value >= 0;135 self.positive = value >= 0;
136 self.len = 0;136 self.len = 0;
137137
138 var w_value: UT = if (value < 0) UT(-value) else UT(value);138 var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value);
139139
140 if (info.bits <= Limb.bit_count) {140 if (info.bits <= Limb.bit_count) {
141 self.limbs[0] = Limb(w_value);141 self.limbs[0] = Limb(w_value);
...@@ -198,7 +198,7 @@ pub const Int = struct {...@@ -198,7 +198,7 @@ pub const Int = struct {
198 var r: UT = 0;198 var r: UT = 0;
199199
200 if (@sizeOf(UT) <= @sizeOf(Limb)) {200 if (@sizeOf(UT) <= @sizeOf(Limb)) {
201 r = UT(self.limbs[0]);201 r = @intCast(UT, self.limbs[0]);
202 } else {202 } else {
203 for (self.limbs[0..self.len]) |_, ri| {203 for (self.limbs[0..self.len]) |_, ri| {
204 const limb = self.limbs[self.len - ri - 1];204 const limb = self.limbs[self.len - ri - 1];
...@@ -210,7 +210,7 @@ pub const Int = struct {...@@ -210,7 +210,7 @@ pub const Int = struct {
210 if (!T.is_signed) {210 if (!T.is_signed) {
211 return if (self.positive) r else error.NegativeIntoUnsigned;211 return if (self.positive) r else error.NegativeIntoUnsigned;
212 } else {212 } else {
213 return if (self.positive) T(r) else -T(r);213 return if (self.positive) @intCast(T, r) else -@intCast(T, r);
214 }214 }
215 },215 },
216 else => {216 else => {
...@@ -295,7 +295,7 @@ pub const Int = struct {...@@ -295,7 +295,7 @@ pub const Int = struct {
295 for (self.limbs[0..self.len]) |limb| {295 for (self.limbs[0..self.len]) |limb| {
296 var shift: usize = 0;296 var shift: usize = 0;
297 while (shift < Limb.bit_count) : (shift += base_shift) {297 while (shift < Limb.bit_count) : (shift += base_shift) {
298 const r = u8((limb >> Log2Limb(shift)) & Limb(base - 1));298 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & Limb(base - 1));
299 const ch = try digitToChar(r, base);299 const ch = try digitToChar(r, base);
300 try digits.append(ch);300 try digits.append(ch);
301 }301 }
...@@ -329,7 +329,7 @@ pub const Int = struct {...@@ -329,7 +329,7 @@ pub const Int = struct {
329 var r_word = r.limbs[0];329 var r_word = r.limbs[0];
330 var i: usize = 0;330 var i: usize = 0;
331 while (i < digits_per_limb) : (i += 1) {331 while (i < digits_per_limb) : (i += 1) {
332 const ch = try digitToChar(u8(r_word % base), base);332 const ch = try digitToChar(@intCast(u8, r_word % base), base);
333 r_word /= base;333 r_word /= base;
334 try digits.append(ch);334 try digits.append(ch);
335 }335 }
...@@ -340,7 +340,7 @@ pub const Int = struct {...@@ -340,7 +340,7 @@ pub const Int = struct {
340340
341 var r_word = q.limbs[0];341 var r_word = q.limbs[0];
342 while (r_word != 0) {342 while (r_word != 0) {
343 const ch = try digitToChar(u8(r_word % base), base);343 const ch = try digitToChar(@intCast(u8, r_word % base), base);
344 r_word /= base;344 r_word /= base;
345 try digits.append(ch);345 try digits.append(ch);
346 }346 }
...@@ -801,7 +801,7 @@ pub const Int = struct {...@@ -801,7 +801,7 @@ pub const Int = struct {
801 q.limbs[i - t - 1] = @maxValue(Limb);801 q.limbs[i - t - 1] = @maxValue(Limb);
802 } else {802 } else {
803 const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);803 const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);
804 const z = Limb(num / DoubleLimb(y.limbs[t]));804 const z = @intCast(Limb, num / DoubleLimb(y.limbs[t]));
805 q.limbs[i - t - 1] = if (z > @maxValue(Limb)) @maxValue(Limb) else Limb(z);805 q.limbs[i - t - 1] = if (z > @maxValue(Limb)) @maxValue(Limb) else Limb(z);
806 }806 }
807807
...@@ -860,7 +860,7 @@ pub const Int = struct {...@@ -860,7 +860,7 @@ pub const Int = struct {
860 debug.assert(r.len >= a.len + (shift / Limb.bit_count) + 1);860 debug.assert(r.len >= a.len + (shift / Limb.bit_count) + 1);
861861
862 const limb_shift = shift / Limb.bit_count + 1;862 const limb_shift = shift / Limb.bit_count + 1;
863 const interior_limb_shift = Log2Limb(shift % Limb.bit_count);863 const interior_limb_shift = @intCast(Log2Limb, shift % Limb.bit_count);
864864
865 var carry: Limb = 0;865 var carry: Limb = 0;
866 var i: usize = 0;866 var i: usize = 0;
...@@ -869,7 +869,7 @@ pub const Int = struct {...@@ -869,7 +869,7 @@ pub const Int = struct {
869 const dst_i = src_i + limb_shift;869 const dst_i = src_i + limb_shift;
870870
871 const src_digit = a[src_i];871 const src_digit = a[src_i];
872 r[dst_i] = carry | @inlineCall(math.shr, Limb, src_digit, Limb.bit_count - Limb(interior_limb_shift));872 r[dst_i] = carry | @inlineCall(math.shr, Limb, src_digit, Limb.bit_count - @intCast(Limb, interior_limb_shift));
873 carry = (src_digit << interior_limb_shift);873 carry = (src_digit << interior_limb_shift);
874 }874 }
875875
...@@ -898,7 +898,7 @@ pub const Int = struct {...@@ -898,7 +898,7 @@ pub const Int = struct {
898 debug.assert(r.len >= a.len - (shift / Limb.bit_count));898 debug.assert(r.len >= a.len - (shift / Limb.bit_count));
899899
900 const limb_shift = shift / Limb.bit_count;900 const limb_shift = shift / Limb.bit_count;
901 const interior_limb_shift = Log2Limb(shift % Limb.bit_count);901 const interior_limb_shift = @intCast(Log2Limb, shift % Limb.bit_count);
902902
903 var carry: Limb = 0;903 var carry: Limb = 0;
904 var i: usize = 0;904 var i: usize = 0;
...@@ -908,7 +908,7 @@ pub const Int = struct {...@@ -908,7 +908,7 @@ pub const Int = struct {
908908
909 const src_digit = a[src_i];909 const src_digit = a[src_i];
910 r[dst_i] = carry | (src_digit >> interior_limb_shift);910 r[dst_i] = carry | (src_digit >> interior_limb_shift);
911 carry = @inlineCall(math.shl, Limb, src_digit, Limb.bit_count - Limb(interior_limb_shift));911 carry = @inlineCall(math.shl, Limb, src_digit, Limb.bit_count - @intCast(Limb, interior_limb_shift));
912 }912 }
913 }913 }
914914
std/math/cbrt.zig+3-3
...@@ -54,7 +54,7 @@ fn cbrt32(x: f32) f32 {...@@ -54,7 +54,7 @@ fn cbrt32(x: f32) f32 {
54 r = t * t * t;54 r = t * t * t;
55 t = t * (f64(x) + x + r) / (x + r + r);55 t = t * (f64(x) + x + r) / (x + r + r);
5656
57 return f32(t);57 return @floatCast(f32, t);
58}58}
5959
60fn cbrt64(x: f64) f64 {60fn cbrt64(x: f64) f64 {
...@@ -69,7 +69,7 @@ fn cbrt64(x: f64) f64 {...@@ -69,7 +69,7 @@ fn cbrt64(x: f64) f64 {
69 const P4: f64 = 0.145996192886612446982;69 const P4: f64 = 0.145996192886612446982;
7070
71 var u = @bitCast(u64, x);71 var u = @bitCast(u64, x);
72 var hx = u32(u >> 32) & 0x7FFFFFFF;72 var hx = @intCast(u32, u >> 32) & 0x7FFFFFFF;
7373
74 // cbrt(nan, inf) = itself74 // cbrt(nan, inf) = itself
75 if (hx >= 0x7FF00000) {75 if (hx >= 0x7FF00000) {
...@@ -79,7 +79,7 @@ fn cbrt64(x: f64) f64 {...@@ -79,7 +79,7 @@ fn cbrt64(x: f64) f64 {
79 // cbrt to ~5bits79 // cbrt to ~5bits
80 if (hx < 0x00100000) {80 if (hx < 0x00100000) {
81 u = @bitCast(u64, x * 0x1.0p54);81 u = @bitCast(u64, x * 0x1.0p54);
82 hx = u32(u >> 32) & 0x7FFFFFFF;82 hx = @intCast(u32, u >> 32) & 0x7FFFFFFF;
8383
84 // cbrt(0) is itself84 // cbrt(0) is itself
85 if (hx == 0) {85 if (hx == 0) {
std/math/ceil.zig+2-2
...@@ -20,7 +20,7 @@ pub fn ceil(x: var) @typeOf(x) {...@@ -20,7 +20,7 @@ pub fn ceil(x: var) @typeOf(x) {
2020
21fn ceil32(x: f32) f32 {21fn ceil32(x: f32) f32 {
22 var u = @bitCast(u32, x);22 var u = @bitCast(u32, x);
23 var e = i32((u >> 23) & 0xFF) - 0x7F;23 var e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;
24 var m: u32 = undefined;24 var m: u32 = undefined;
2525
26 // TODO: Shouldn't need this explicit check.26 // TODO: Shouldn't need this explicit check.
...@@ -31,7 +31,7 @@ fn ceil32(x: f32) f32 {...@@ -31,7 +31,7 @@ fn ceil32(x: f32) f32 {
31 if (e >= 23) {31 if (e >= 23) {
32 return x;32 return x;
33 } else if (e >= 0) {33 } else if (e >= 0) {
34 m = u32(0x007FFFFF) >> u5(e);34 m = u32(0x007FFFFF) >> @intCast(u5, e);
35 if (u & m == 0) {35 if (u & m == 0) {
36 return x;36 return x;
37 }37 }
std/math/complex/atan.zig+5-5
...@@ -4,7 +4,7 @@ const math = std.math;...@@ -4,7 +4,7 @@ const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7pub fn atan(z: var) Complex(@typeOf(z.re)) {7pub fn atan(z: var) @typeOf(z) {
8 const T = @typeOf(z.re);8 const T = @typeOf(z.re);
9 return switch (T) {9 return switch (T) {
10 f32 => atan32(z),10 f32 => atan32(z),
...@@ -25,11 +25,11 @@ fn redupif32(x: f32) f32 {...@@ -25,11 +25,11 @@ fn redupif32(x: f32) f32 {
25 t -= 0.5;25 t -= 0.5;
26 }26 }
2727
28 const u = f32(i32(t));28 const u = @intToFloat(f32, @floatToInt(i32, t));
29 return ((x - u * DP1) - u * DP2) - t * DP3;29 return ((x - u * DP1) - u * DP2) - t * DP3;
30}30}
3131
32fn atan32(z: *const Complex(f32)) Complex(f32) {32fn atan32(z: Complex(f32)) Complex(f32) {
33 const maxnum = 1.0e38;33 const maxnum = 1.0e38;
3434
35 const x = z.re;35 const x = z.re;
...@@ -74,11 +74,11 @@ fn redupif64(x: f64) f64 {...@@ -74,11 +74,11 @@ fn redupif64(x: f64) f64 {
74 t -= 0.5;74 t -= 0.5;
75 }75 }
7676
77 const u = f64(i64(t));77 const u = @intToFloat(f64, @floatToInt(i64, t));
78 return ((x - u * DP1) - u * DP2) - t * DP3;78 return ((x - u * DP1) - u * DP2) - t * DP3;
79}79}
8080
81fn atan64(z: *const Complex(f64)) Complex(f64) {81fn atan64(z: Complex(f64)) Complex(f64) {
82 const maxnum = 1.0e308;82 const maxnum = 1.0e308;
8383
84 const x = z.re;84 const x = z.re;
std/math/complex/cosh.zig+2-2
...@@ -83,12 +83,12 @@ fn cosh64(z: *const Complex(f64)) Complex(f64) {...@@ -83,12 +83,12 @@ fn cosh64(z: *const Complex(f64)) Complex(f64) {
83 const y = z.im;83 const y = z.im;
8484
85 const fx = @bitCast(u64, x);85 const fx = @bitCast(u64, x);
86 const hx = u32(fx >> 32);86 const hx = @intCast(u32, fx >> 32);
87 const lx = @truncate(u32, fx);87 const lx = @truncate(u32, fx);
88 const ix = hx & 0x7fffffff;88 const ix = hx & 0x7fffffff;
8989
90 const fy = @bitCast(u64, y);90 const fy = @bitCast(u64, y);
91 const hy = u32(fy >> 32);91 const hy = @intCast(u32, fy >> 32);
92 const ly = @truncate(u32, fy);92 const ly = @truncate(u32, fy);
93 const iy = hy & 0x7fffffff;93 const iy = hy & 0x7fffffff;
9494
std/math/complex/exp.zig+3-3
...@@ -6,7 +6,7 @@ const Complex = cmath.Complex;...@@ -6,7 +6,7 @@ const Complex = cmath.Complex;
66
7const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;7const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
88
9pub fn exp(z: var) Complex(@typeOf(z.re)) {9pub fn exp(z: var) @typeOf(z) {
10 const T = @typeOf(z.re);10 const T = @typeOf(z.re);
1111
12 return switch (T) {12 return switch (T) {
...@@ -16,7 +16,7 @@ pub fn exp(z: var) Complex(@typeOf(z.re)) {...@@ -16,7 +16,7 @@ pub fn exp(z: var) Complex(@typeOf(z.re)) {
16 };16 };
17}17}
1818
19fn exp32(z: *const Complex(f32)) Complex(f32) {19fn exp32(z: Complex(f32)) Complex(f32) {
20 @setFloatMode(this, @import("builtin").FloatMode.Strict);20 @setFloatMode(this, @import("builtin").FloatMode.Strict);
2121
22 const exp_overflow = 0x42b17218; // max_exp * ln2 ~= 88.7228395522 const exp_overflow = 0x42b17218; // max_exp * ln2 ~= 88.72283955
...@@ -63,7 +63,7 @@ fn exp32(z: *const Complex(f32)) Complex(f32) {...@@ -63,7 +63,7 @@ fn exp32(z: *const Complex(f32)) Complex(f32) {
63 }63 }
64}64}
6565
66fn exp64(z: *const Complex(f64)) Complex(f64) {66fn exp64(z: Complex(f64)) Complex(f64) {
67 const exp_overflow = 0x40862e42; // high bits of max_exp * ln2 ~= 71067 const exp_overflow = 0x40862e42; // high bits of max_exp * ln2 ~= 710
68 const cexp_overflow = 0x4096b8e4; // (max_exp - min_denorm_exp) * ln268 const cexp_overflow = 0x4096b8e4; // (max_exp - min_denorm_exp) * ln2
6969
std/math/complex/ldexp.zig+7-6
...@@ -4,7 +4,7 @@ const math = std.math;...@@ -4,7 +4,7 @@ const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7pub fn ldexp_cexp(z: var, expt: i32) Complex(@typeOf(z.re)) {7pub fn ldexp_cexp(z: var, expt: i32) @typeOf(z) {
8 const T = @typeOf(z.re);8 const T = @typeOf(z.re);
99
10 return switch (T) {10 return switch (T) {
...@@ -20,11 +20,12 @@ fn frexp_exp32(x: f32, expt: *i32) f32 {...@@ -20,11 +20,12 @@ fn frexp_exp32(x: f32, expt: *i32) f32 {
2020
21 const exp_x = math.exp(x - kln2);21 const exp_x = math.exp(x - kln2);
22 const hx = @bitCast(u32, exp_x);22 const hx = @bitCast(u32, exp_x);
23 expt.* = i32(hx >> 23) - (0x7f + 127) + k;23 // TODO zig should allow this cast implicitly because it should know the value is in range
24 expt.* = @intCast(i32, hx >> 23) - (0x7f + 127) + k;
24 return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));25 return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));
25}26}
2627
27fn ldexp_cexp32(z: *const Complex(f32), expt: i32) Complex(f32) {28fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
28 var ex_expt: i32 = undefined;29 var ex_expt: i32 = undefined;
29 const exp_x = frexp_exp32(z.re, &ex_expt);30 const exp_x = frexp_exp32(z.re, &ex_expt);
30 const exptf = expt + ex_expt;31 const exptf = expt + ex_expt;
...@@ -45,16 +46,16 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {...@@ -45,16 +46,16 @@ fn frexp_exp64(x: f64, expt: *i32) f64 {
45 const exp_x = math.exp(x - kln2);46 const exp_x = math.exp(x - kln2);
4647
47 const fx = @bitCast(u64, x);48 const fx = @bitCast(u64, x);
48 const hx = u32(fx >> 32);49 const hx = @intCast(u32, fx >> 32);
49 const lx = @truncate(u32, fx);50 const lx = @truncate(u32, fx);
5051
51 expt.* = i32(hx >> 20) - (0x3ff + 1023) + k;52 expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k;
5253
53 const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);54 const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20);
54 return @bitCast(f64, (u64(high_word) << 32) | lx);55 return @bitCast(f64, (u64(high_word) << 32) | lx);
55}56}
5657
57fn ldexp_cexp64(z: *const Complex(f64), expt: i32) Complex(f64) {58fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) {
58 var ex_expt: i32 = undefined;59 var ex_expt: i32 = undefined;
59 const exp_x = frexp_exp64(z.re, &ex_expt);60 const exp_x = frexp_exp64(z.re, &ex_expt);
60 const exptf = i64(expt + ex_expt);61 const exptf = i64(expt + ex_expt);
std/math/complex/sinh.zig+5-5
...@@ -6,7 +6,7 @@ const Complex = cmath.Complex;...@@ -6,7 +6,7 @@ const Complex = cmath.Complex;
66
7const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;7const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
88
9pub fn sinh(z: var) Complex(@typeOf(z.re)) {9pub fn sinh(z: var) @typeOf(z) {
10 const T = @typeOf(z.re);10 const T = @typeOf(z.re);
11 return switch (T) {11 return switch (T) {
12 f32 => sinh32(z),12 f32 => sinh32(z),
...@@ -15,7 +15,7 @@ pub fn sinh(z: var) Complex(@typeOf(z.re)) {...@@ -15,7 +15,7 @@ pub fn sinh(z: var) Complex(@typeOf(z.re)) {
15 };15 };
16}16}
1717
18fn sinh32(z: *const Complex(f32)) Complex(f32) {18fn sinh32(z: Complex(f32)) Complex(f32) {
19 const x = z.re;19 const x = z.re;
20 const y = z.im;20 const y = z.im;
2121
...@@ -78,17 +78,17 @@ fn sinh32(z: *const Complex(f32)) Complex(f32) {...@@ -78,17 +78,17 @@ fn sinh32(z: *const Complex(f32)) Complex(f32) {
78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));
79}79}
8080
81fn sinh64(z: *const Complex(f64)) Complex(f64) {81fn sinh64(z: Complex(f64)) Complex(f64) {
82 const x = z.re;82 const x = z.re;
83 const y = z.im;83 const y = z.im;
8484
85 const fx = @bitCast(u64, x);85 const fx = @bitCast(u64, x);
86 const hx = u32(fx >> 32);86 const hx = @intCast(u32, fx >> 32);
87 const lx = @truncate(u32, fx);87 const lx = @truncate(u32, fx);
88 const ix = hx & 0x7fffffff;88 const ix = hx & 0x7fffffff;
8989
90 const fy = @bitCast(u64, y);90 const fy = @bitCast(u64, y);
91 const hy = u32(fy >> 32);91 const hy = @intCast(u32, fy >> 32);
92 const ly = @truncate(u32, fy);92 const ly = @truncate(u32, fy);
93 const iy = hy & 0x7fffffff;93 const iy = hy & 0x7fffffff;
9494
std/math/complex/sqrt.zig+8-2
...@@ -49,10 +49,16 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {...@@ -49,10 +49,16 @@ fn sqrt32(z: Complex(f32)) Complex(f32) {
4949
50 if (dx >= 0) {50 if (dx >= 0) {
51 const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);51 const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5);
52 return Complex(f32).new(f32(t), f32(dy / (2.0 * t)));52 return Complex(f32).new(
53 @floatCast(f32, t),
54 @floatCast(f32, dy / (2.0 * t)),
55 );
53 } else {56 } else {
54 const t = math.sqrt((-dx + math.hypot(f64, dx, dy)) * 0.5);57 const t = math.sqrt((-dx + math.hypot(f64, dx, dy)) * 0.5);
55 return Complex(f32).new(f32(math.fabs(y) / (2.0 * t)), f32(math.copysign(f64, t, y)));58 return Complex(f32).new(
59 @floatCast(f32, math.fabs(y) / (2.0 * t)),
60 @floatCast(f32, math.copysign(f64, t, y)),
61 );
56 }62 }
57}63}
5864
std/math/complex/tanh.zig+6-4
...@@ -4,7 +4,7 @@ const math = std.math;...@@ -4,7 +4,7 @@ const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7pub fn tanh(z: var) Complex(@typeOf(z.re)) {7pub fn tanh(z: var) @typeOf(z) {
8 const T = @typeOf(z.re);8 const T = @typeOf(z.re);
9 return switch (T) {9 return switch (T) {
10 f32 => tanh32(z),10 f32 => tanh32(z),
...@@ -13,7 +13,7 @@ pub fn tanh(z: var) Complex(@typeOf(z.re)) {...@@ -13,7 +13,7 @@ pub fn tanh(z: var) Complex(@typeOf(z.re)) {
13 };13 };
14}14}
1515
16fn tanh32(z: *const Complex(f32)) Complex(f32) {16fn tanh32(z: Complex(f32)) Complex(f32) {
17 const x = z.re;17 const x = z.re;
18 const y = z.im;18 const y = z.im;
1919
...@@ -51,12 +51,14 @@ fn tanh32(z: *const Complex(f32)) Complex(f32) {...@@ -51,12 +51,14 @@ fn tanh32(z: *const Complex(f32)) Complex(f32) {
51 return Complex(f32).new((beta * rho * s) / den, t / den);51 return Complex(f32).new((beta * rho * s) / den, t / den);
52}52}
5353
54fn tanh64(z: *const Complex(f64)) Complex(f64) {54fn tanh64(z: Complex(f64)) Complex(f64) {
55 const x = z.re;55 const x = z.re;
56 const y = z.im;56 const y = z.im;
5757
58 const fx = @bitCast(u64, x);58 const fx = @bitCast(u64, x);
59 const hx = u32(fx >> 32);59 // TODO: zig should allow this conversion implicitly because it can notice that the value necessarily
60 // fits in range.
61 const hx = @intCast(u32, fx >> 32);
60 const lx = @truncate(u32, fx);62 const lx = @truncate(u32, fx);
61 const ix = hx & 0x7fffffff;63 const ix = hx & 0x7fffffff;
6264
std/math/cos.zig+2-2
...@@ -55,7 +55,7 @@ fn cos32(x_: f32) f32 {...@@ -55,7 +55,7 @@ fn cos32(x_: f32) f32 {
55 }55 }
5656
57 var y = math.floor(x * m4pi);57 var y = math.floor(x * m4pi);
58 var j = i64(y);58 var j = @floatToInt(i64, y);
5959
60 if (j & 1 == 1) {60 if (j & 1 == 1) {
61 j += 1;61 j += 1;
...@@ -106,7 +106,7 @@ fn cos64(x_: f64) f64 {...@@ -106,7 +106,7 @@ fn cos64(x_: f64) f64 {
106 }106 }
107107
108 var y = math.floor(x * m4pi);108 var y = math.floor(x * m4pi);
109 var j = i64(y);109 var j = @floatToInt(i64, y);
110110
111 if (j & 1 == 1) {111 if (j & 1 == 1) {
112 j += 1;112 j += 1;
std/math/cosh.zig+1-1
...@@ -49,7 +49,7 @@ fn cosh32(x: f32) f32 {...@@ -49,7 +49,7 @@ fn cosh32(x: f32) f32 {
4949
50fn cosh64(x: f64) f64 {50fn cosh64(x: f64) f64 {
51 const u = @bitCast(u64, x);51 const u = @bitCast(u64, x);
52 const w = u32(u >> 32);52 const w = @intCast(u32, u >> 32);
53 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));53 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
5454
55 // TODO: Shouldn't need this explicit check.55 // TODO: Shouldn't need this explicit check.
std/math/exp.zig+6-6
...@@ -29,7 +29,7 @@ fn exp32(x_: f32) f32 {...@@ -29,7 +29,7 @@ fn exp32(x_: f32) f32 {
2929
30 var x = x_;30 var x = x_;
31 var hx = @bitCast(u32, x);31 var hx = @bitCast(u32, x);
32 const sign = i32(hx >> 31);32 const sign = @intCast(i32, hx >> 31);
33 hx &= 0x7FFFFFFF;33 hx &= 0x7FFFFFFF;
3434
35 if (math.isNan(x)) {35 if (math.isNan(x)) {
...@@ -63,12 +63,12 @@ fn exp32(x_: f32) f32 {...@@ -63,12 +63,12 @@ fn exp32(x_: f32) f32 {
63 if (hx > 0x3EB17218) {63 if (hx > 0x3EB17218) {
64 // |x| > 1.5 * ln264 // |x| > 1.5 * ln2
65 if (hx > 0x3F851592) {65 if (hx > 0x3F851592) {
66 k = i32(invln2 * x + half[usize(sign)]);66 k = @floatToInt(i32, invln2 * x + half[@intCast(usize, sign)]);
67 } else {67 } else {
68 k = 1 - sign - sign;68 k = 1 - sign - sign;
69 }69 }
7070
71 const fk = f32(k);71 const fk = @intToFloat(f32, k);
72 hi = x - fk * ln2hi;72 hi = x - fk * ln2hi;
73 lo = fk * ln2lo;73 lo = fk * ln2lo;
74 x = hi - lo;74 x = hi - lo;
...@@ -110,7 +110,7 @@ fn exp64(x_: f64) f64 {...@@ -110,7 +110,7 @@ fn exp64(x_: f64) f64 {
110 var x = x_;110 var x = x_;
111 var ux = @bitCast(u64, x);111 var ux = @bitCast(u64, x);
112 var hx = ux >> 32;112 var hx = ux >> 32;
113 const sign = i32(hx >> 31);113 const sign = @intCast(i32, hx >> 31);
114 hx &= 0x7FFFFFFF;114 hx &= 0x7FFFFFFF;
115115
116 if (math.isNan(x)) {116 if (math.isNan(x)) {
...@@ -148,12 +148,12 @@ fn exp64(x_: f64) f64 {...@@ -148,12 +148,12 @@ fn exp64(x_: f64) f64 {
148 if (hx > 0x3EB17218) {148 if (hx > 0x3EB17218) {
149 // |x| >= 1.5 * ln2149 // |x| >= 1.5 * ln2
150 if (hx > 0x3FF0A2B2) {150 if (hx > 0x3FF0A2B2) {
151 k = i32(invln2 * x + half[usize(sign)]);151 k = @floatToInt(i32, invln2 * x + half[@intCast(usize, sign)]);
152 } else {152 } else {
153 k = 1 - sign - sign;153 k = 1 - sign - sign;
154 }154 }
155155
156 const dk = f64(k);156 const dk = @intToFloat(f64, k);
157 hi = x - dk * ln2hi;157 hi = x - dk * ln2hi;
158 lo = dk * ln2lo;158 lo = dk * ln2lo;
159 x = hi - lo;159 x = hi - lo;
std/math/exp2.zig+7-7
...@@ -38,8 +38,8 @@ const exp2ft = []const f64{...@@ -38,8 +38,8 @@ const exp2ft = []const f64{
38fn exp2_32(x: f32) f32 {38fn exp2_32(x: f32) f32 {
39 @setFloatMode(this, @import("builtin").FloatMode.Strict);39 @setFloatMode(this, @import("builtin").FloatMode.Strict);
4040
41 const tblsiz = u32(exp2ft.len);41 const tblsiz = @intCast(u32, exp2ft.len);
42 const redux: f32 = 0x1.8p23 / f32(tblsiz);42 const redux: f32 = 0x1.8p23 / @intToFloat(f32, tblsiz);
43 const P1: f32 = 0x1.62e430p-1;43 const P1: f32 = 0x1.62e430p-1;
44 const P2: f32 = 0x1.ebfbe0p-3;44 const P2: f32 = 0x1.ebfbe0p-3;
45 const P3: f32 = 0x1.c6b348p-5;45 const P3: f32 = 0x1.c6b348p-5;
...@@ -89,7 +89,7 @@ fn exp2_32(x: f32) f32 {...@@ -89,7 +89,7 @@ fn exp2_32(x: f32) f32 {
89 var r: f64 = exp2ft[i0];89 var r: f64 = exp2ft[i0];
90 const t: f64 = r * z;90 const t: f64 = r * z;
91 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);91 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
92 return f32(r * uk);92 return @floatCast(f32, r * uk);
93}93}
9494
95const exp2dt = []f64{95const exp2dt = []f64{
...@@ -355,8 +355,8 @@ const exp2dt = []f64{...@@ -355,8 +355,8 @@ const exp2dt = []f64{
355fn exp2_64(x: f64) f64 {355fn exp2_64(x: f64) f64 {
356 @setFloatMode(this, @import("builtin").FloatMode.Strict);356 @setFloatMode(this, @import("builtin").FloatMode.Strict);
357357
358 const tblsiz = u32(exp2dt.len / 2);358 const tblsiz = @intCast(u32, exp2dt.len / 2);
359 const redux: f64 = 0x1.8p52 / f64(tblsiz);359 const redux: f64 = 0x1.8p52 / @intToFloat(f64, tblsiz);
360 const P1: f64 = 0x1.62e42fefa39efp-1;360 const P1: f64 = 0x1.62e42fefa39efp-1;
361 const P2: f64 = 0x1.ebfbdff82c575p-3;361 const P2: f64 = 0x1.ebfbdff82c575p-3;
362 const P3: f64 = 0x1.c6b08d704a0a6p-5;362 const P3: f64 = 0x1.c6b08d704a0a6p-5;
...@@ -364,7 +364,7 @@ fn exp2_64(x: f64) f64 {...@@ -364,7 +364,7 @@ fn exp2_64(x: f64) f64 {
364 const P5: f64 = 0x1.5d88003875c74p-10;364 const P5: f64 = 0x1.5d88003875c74p-10;
365365
366 const ux = @bitCast(u64, x);366 const ux = @bitCast(u64, x);
367 const ix = u32(ux >> 32) & 0x7FFFFFFF;367 const ix = @intCast(u32, ux >> 32) & 0x7FFFFFFF;
368368
369 // TODO: This should be handled beneath.369 // TODO: This should be handled beneath.
370 if (math.isNan(x)) {370 if (math.isNan(x)) {
...@@ -386,7 +386,7 @@ fn exp2_64(x: f64) f64 {...@@ -386,7 +386,7 @@ fn exp2_64(x: f64) f64 {
386 if (ux >> 63 != 0) {386 if (ux >> 63 != 0) {
387 // underflow387 // underflow
388 if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) {388 if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) {
389 math.forceEval(f32(-0x1.0p-149 / x));389 math.forceEval(@floatCast(f32, -0x1.0p-149 / x));
390 }390 }
391 if (x <= -1075) {391 if (x <= -1075) {
392 return 0;392 return 0;
std/math/expm1.zig+10-10
...@@ -78,8 +78,8 @@ fn expm1_32(x_: f32) f32 {...@@ -78,8 +78,8 @@ fn expm1_32(x_: f32) f32 {
78 kf += 0.5;78 kf += 0.5;
79 }79 }
8080
81 k = i32(kf);81 k = @floatToInt(i32, kf);
82 const t = f32(k);82 const t = @intToFloat(f32, k);
83 hi = x - t * ln2_hi;83 hi = x - t * ln2_hi;
84 lo = t * ln2_lo;84 lo = t * ln2_lo;
85 }85 }
...@@ -123,7 +123,7 @@ fn expm1_32(x_: f32) f32 {...@@ -123,7 +123,7 @@ fn expm1_32(x_: f32) f32 {
123 }123 }
124 }124 }
125125
126 const twopk = @bitCast(f32, u32((0x7F +% k) << 23));126 const twopk = @bitCast(f32, @intCast(u32, (0x7F +% k) << 23));
127127
128 if (k < 0 or k > 56) {128 if (k < 0 or k > 56) {
129 var y = x - e + 1.0;129 var y = x - e + 1.0;
...@@ -136,7 +136,7 @@ fn expm1_32(x_: f32) f32 {...@@ -136,7 +136,7 @@ fn expm1_32(x_: f32) f32 {
136 return y - 1.0;136 return y - 1.0;
137 }137 }
138138
139 const uf = @bitCast(f32, u32(0x7F -% k) << 23);139 const uf = @bitCast(f32, @intCast(u32, 0x7F -% k) << 23);
140 if (k < 23) {140 if (k < 23) {
141 return (x - e + (1 - uf)) * twopk;141 return (x - e + (1 - uf)) * twopk;
142 } else {142 } else {
...@@ -158,7 +158,7 @@ fn expm1_64(x_: f64) f64 {...@@ -158,7 +158,7 @@ fn expm1_64(x_: f64) f64 {
158158
159 var x = x_;159 var x = x_;
160 const ux = @bitCast(u64, x);160 const ux = @bitCast(u64, x);
161 const hx = u32(ux >> 32) & 0x7FFFFFFF;161 const hx = @intCast(u32, ux >> 32) & 0x7FFFFFFF;
162 const sign = ux >> 63;162 const sign = ux >> 63;
163163
164 if (math.isNegativeInf(x)) {164 if (math.isNegativeInf(x)) {
...@@ -207,8 +207,8 @@ fn expm1_64(x_: f64) f64 {...@@ -207,8 +207,8 @@ fn expm1_64(x_: f64) f64 {
207 kf += 0.5;207 kf += 0.5;
208 }208 }
209209
210 k = i32(kf);210 k = @floatToInt(i32, kf);
211 const t = f64(k);211 const t = @intToFloat(f64, k);
212 hi = x - t * ln2_hi;212 hi = x - t * ln2_hi;
213 lo = t * ln2_lo;213 lo = t * ln2_lo;
214 }214 }
...@@ -219,7 +219,7 @@ fn expm1_64(x_: f64) f64 {...@@ -219,7 +219,7 @@ fn expm1_64(x_: f64) f64 {
219 // |x| < 2^(-54)219 // |x| < 2^(-54)
220 else if (hx < 0x3C900000) {220 else if (hx < 0x3C900000) {
221 if (hx < 0x00100000) {221 if (hx < 0x00100000) {
222 math.forceEval(f32(x));222 math.forceEval(@floatCast(f32, x));
223 }223 }
224 return x;224 return x;
225 } else {225 } else {
...@@ -252,7 +252,7 @@ fn expm1_64(x_: f64) f64 {...@@ -252,7 +252,7 @@ fn expm1_64(x_: f64) f64 {
252 }252 }
253 }253 }
254254
255 const twopk = @bitCast(f64, u64(0x3FF +% k) << 52);255 const twopk = @bitCast(f64, @intCast(u64, 0x3FF +% k) << 52);
256256
257 if (k < 0 or k > 56) {257 if (k < 0 or k > 56) {
258 var y = x - e + 1.0;258 var y = x - e + 1.0;
...@@ -265,7 +265,7 @@ fn expm1_64(x_: f64) f64 {...@@ -265,7 +265,7 @@ fn expm1_64(x_: f64) f64 {
265 return y - 1.0;265 return y - 1.0;
266 }266 }
267267
268 const uf = @bitCast(f64, u64(0x3FF -% k) << 52);268 const uf = @bitCast(f64, @intCast(u64, 0x3FF -% k) << 52);
269 if (k < 20) {269 if (k < 20) {
270 return (x - e + (1 - uf)) * twopk;270 return (x - e + (1 - uf)) * twopk;
271 } else {271 } else {
std/math/floor.zig+2-2
...@@ -20,7 +20,7 @@ pub fn floor(x: var) @typeOf(x) {...@@ -20,7 +20,7 @@ pub fn floor(x: var) @typeOf(x) {
2020
21fn floor32(x: f32) f32 {21fn floor32(x: f32) f32 {
22 var u = @bitCast(u32, x);22 var u = @bitCast(u32, x);
23 const e = i32((u >> 23) & 0xFF) - 0x7F;23 const e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;
24 var m: u32 = undefined;24 var m: u32 = undefined;
2525
26 // TODO: Shouldn't need this explicit check.26 // TODO: Shouldn't need this explicit check.
...@@ -33,7 +33,7 @@ fn floor32(x: f32) f32 {...@@ -33,7 +33,7 @@ fn floor32(x: f32) f32 {
33 }33 }
3434
35 if (e >= 0) {35 if (e >= 0) {
36 m = u32(0x007FFFFF) >> u5(e);36 m = u32(0x007FFFFF) >> @intCast(u5, e);
37 if (u & m == 0) {37 if (u & m == 0) {
38 return x;38 return x;
39 }39 }
std/math/fma.zig+3-3
...@@ -17,10 +17,10 @@ fn fma32(x: f32, y: f32, z: f32) f32 {...@@ -17,10 +17,10 @@ fn fma32(x: f32, y: f32, z: f32) f32 {
17 const e = (u >> 52) & 0x7FF;17 const e = (u >> 52) & 0x7FF;
1818
19 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or xy_z - xy == z) {19 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or xy_z - xy == z) {
20 return f32(xy_z);20 return @floatCast(f32, xy_z);
21 } else {21 } else {
22 // TODO: Handle inexact case with double-rounding22 // TODO: Handle inexact case with double-rounding
23 return f32(xy_z);23 return @floatCast(f32, xy_z);
24 }24 }
25}25}
2626
...@@ -124,7 +124,7 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {...@@ -124,7 +124,7 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
124 var sum = dd_add(a, b);124 var sum = dd_add(a, b);
125 if (sum.lo != 0) {125 if (sum.lo != 0) {
126 var uhii = @bitCast(u64, sum.hi);126 var uhii = @bitCast(u64, sum.hi);
127 const bits_lost = -i32((uhii >> 52) & 0x7FF) - scale + 1;127 const bits_lost = -@intCast(i32, (uhii >> 52) & 0x7FF) - scale + 1;
128 if ((bits_lost != 1) == (uhii & 1 != 0)) {128 if ((bits_lost != 1) == (uhii & 1 != 0)) {
129 const uloi = @bitCast(u64, sum.lo);129 const uloi = @bitCast(u64, sum.lo);
130 uhii += 1 - (((uhii ^ uloi) >> 62) & 2);130 uhii += 1 - (((uhii ^ uloi) >> 62) & 2);
std/math/frexp.zig+2-2
...@@ -30,7 +30,7 @@ fn frexp32(x: f32) frexp32_result {...@@ -30,7 +30,7 @@ fn frexp32(x: f32) frexp32_result {
30 var result: frexp32_result = undefined;30 var result: frexp32_result = undefined;
3131
32 var y = @bitCast(u32, x);32 var y = @bitCast(u32, x);
33 const e = i32(y >> 23) & 0xFF;33 const e = @intCast(i32, y >> 23) & 0xFF;
3434
35 if (e == 0) {35 if (e == 0) {
36 if (x != 0) {36 if (x != 0) {
...@@ -67,7 +67,7 @@ fn frexp64(x: f64) frexp64_result {...@@ -67,7 +67,7 @@ fn frexp64(x: f64) frexp64_result {
67 var result: frexp64_result = undefined;67 var result: frexp64_result = undefined;
6868
69 var y = @bitCast(u64, x);69 var y = @bitCast(u64, x);
70 const e = i32(y >> 52) & 0x7FF;70 const e = @intCast(i32, y >> 52) & 0x7FF;
7171
72 if (e == 0) {72 if (e == 0) {
73 if (x != 0) {73 if (x != 0) {
std/math/hypot.zig+1-1
...@@ -49,7 +49,7 @@ fn hypot32(x: f32, y: f32) f32 {...@@ -49,7 +49,7 @@ fn hypot32(x: f32, y: f32) f32 {
49 yy *= 0x1.0p-90;49 yy *= 0x1.0p-90;
50 }50 }
5151
52 return z * math.sqrt(f32(f64(x) * x + f64(y) * y));52 return z * math.sqrt(@floatCast(f32, f64(x) * x + f64(y) * y));
53}53}
5454
55fn sq(hi: *f64, lo: *f64, x: f64) void {55fn sq(hi: *f64, lo: *f64, x: f64) void {
std/math/ilogb.zig+2-2
...@@ -23,7 +23,7 @@ const fp_ilogb0 = fp_ilogbnan;...@@ -23,7 +23,7 @@ const fp_ilogb0 = fp_ilogbnan;
2323
24fn ilogb32(x: f32) i32 {24fn ilogb32(x: f32) i32 {
25 var u = @bitCast(u32, x);25 var u = @bitCast(u32, x);
26 var e = i32((u >> 23) & 0xFF);26 var e = @intCast(i32, (u >> 23) & 0xFF);
2727
28 // TODO: We should be able to merge this with the lower check.28 // TODO: We should be able to merge this with the lower check.
29 if (math.isNan(x)) {29 if (math.isNan(x)) {
...@@ -59,7 +59,7 @@ fn ilogb32(x: f32) i32 {...@@ -59,7 +59,7 @@ fn ilogb32(x: f32) i32 {
5959
60fn ilogb64(x: f64) i32 {60fn ilogb64(x: f64) i32 {
61 var u = @bitCast(u64, x);61 var u = @bitCast(u64, x);
62 var e = i32((u >> 52) & 0x7FF);62 var e = @intCast(i32, (u >> 52) & 0x7FF);
6363
64 if (math.isNan(x)) {64 if (math.isNan(x)) {
65 return @maxValue(i32);65 return @maxValue(i32);
std/math/index.zig+18-7
...@@ -227,7 +227,7 @@ pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {...@@ -227,7 +227,7 @@ pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {
227/// A negative shift amount results in a right shift.227/// A negative shift amount results in a right shift.
228pub fn shl(comptime T: type, a: T, shift_amt: var) T {228pub fn shl(comptime T: type, a: T, shift_amt: var) T {
229 const abs_shift_amt = absCast(shift_amt);229 const abs_shift_amt = absCast(shift_amt);
230 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt);230 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
231231
232 if (@typeOf(shift_amt).is_signed) {232 if (@typeOf(shift_amt).is_signed) {
233 if (shift_amt >= 0) {233 if (shift_amt >= 0) {
...@@ -251,7 +251,7 @@ test "math.shl" {...@@ -251,7 +251,7 @@ test "math.shl" {
251/// A negative shift amount results in a lefft shift.251/// A negative shift amount results in a lefft shift.
252pub fn shr(comptime T: type, a: T, shift_amt: var) T {252pub fn shr(comptime T: type, a: T, shift_amt: var) T {
253 const abs_shift_amt = absCast(shift_amt);253 const abs_shift_amt = absCast(shift_amt);
254 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt);254 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
255255
256 if (@typeOf(shift_amt).is_signed) {256 if (@typeOf(shift_amt).is_signed) {
257 if (shift_amt >= 0) {257 if (shift_amt >= 0) {
...@@ -473,9 +473,9 @@ fn testRem() void {...@@ -473,9 +473,9 @@ fn testRem() void {
473/// Result is an unsigned integer.473/// Result is an unsigned integer.
474pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) {474pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) {
475 const uint = @IntType(false, @typeOf(x).bit_count);475 const uint = @IntType(false, @typeOf(x).bit_count);
476 if (x >= 0) return uint(x);476 if (x >= 0) return @intCast(uint, x);
477477
478 return uint(-(x + 1)) + 1;478 return @intCast(uint, -(x + 1)) + 1;
479}479}
480480
481test "math.absCast" {481test "math.absCast" {
...@@ -499,7 +499,7 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {...@@ -499,7 +499,7 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
499499
500 if (x == -@minValue(int)) return @minValue(int);500 if (x == -@minValue(int)) return @minValue(int);
501501
502 return -int(x);502 return -@intCast(int, x);
503}503}
504504
505test "math.negateCast" {505test "math.negateCast" {
...@@ -522,7 +522,7 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {...@@ -522,7 +522,7 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
522 } else if (@minValue(@typeOf(x)) < @minValue(T) and x < @minValue(T)) {522 } else if (@minValue(@typeOf(x)) < @minValue(T) and x < @minValue(T)) {
523 return error.Overflow;523 return error.Overflow;
524 } else {524 } else {
525 return T(x);525 return @intCast(T, x);
526 }526 }
527}527}
528528
...@@ -565,7 +565,7 @@ test "math.floorPowerOfTwo" {...@@ -565,7 +565,7 @@ test "math.floorPowerOfTwo" {
565565
566pub fn log2_int(comptime T: type, x: T) Log2Int(T) {566pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
567 assert(x != 0);567 assert(x != 0);
568 return Log2Int(T)(T.bit_count - 1 - @clz(x));568 return @intCast(Log2Int(T), T.bit_count - 1 - @clz(x));
569}569}
570570
571pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {571pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
...@@ -597,3 +597,14 @@ fn testFloorPowerOfTwo() void {...@@ -597,3 +597,14 @@ fn testFloorPowerOfTwo() void {
597 assert(floorPowerOfTwo(u4, 8) == 8);597 assert(floorPowerOfTwo(u4, 8) == 8);
598 assert(floorPowerOfTwo(u4, 9) == 8);598 assert(floorPowerOfTwo(u4, 9) == 8);
599}599}
600
601pub fn lossyCast(comptime T: type, value: var) T {
602 switch (@typeInfo(@typeOf(value))) {
603 builtin.TypeId.Int => return @intToFloat(T, value),
604 builtin.TypeId.Float => return @floatCast(T, value),
605 builtin.TypeId.ComptimeInt => return T(value),
606 builtin.TypeId.ComptimeFloat => return T(value),
607 else => @compileError("bad type"),
608 }
609}
610
std/math/ln.zig+6-6
...@@ -71,7 +71,7 @@ pub fn ln_32(x_: f32) f32 {...@@ -71,7 +71,7 @@ pub fn ln_32(x_: f32) f32 {
7171
72 // x into [sqrt(2) / 2, sqrt(2)]72 // x into [sqrt(2) / 2, sqrt(2)]
73 ix += 0x3F800000 - 0x3F3504F3;73 ix += 0x3F800000 - 0x3F3504F3;
74 k += i32(ix >> 23) - 0x7F;74 k += @intCast(i32, ix >> 23) - 0x7F;
75 ix = (ix & 0x007FFFFF) + 0x3F3504F3;75 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
76 x = @bitCast(f32, ix);76 x = @bitCast(f32, ix);
7777
...@@ -83,7 +83,7 @@ pub fn ln_32(x_: f32) f32 {...@@ -83,7 +83,7 @@ pub fn ln_32(x_: f32) f32 {
83 const t2 = z * (Lg1 + w * Lg3);83 const t2 = z * (Lg1 + w * Lg3);
84 const R = t2 + t1;84 const R = t2 + t1;
85 const hfsq = 0.5 * f * f;85 const hfsq = 0.5 * f * f;
86 const dk = f32(k);86 const dk = @intToFloat(f32, k);
8787
88 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;88 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
89}89}
...@@ -103,7 +103,7 @@ pub fn ln_64(x_: f64) f64 {...@@ -103,7 +103,7 @@ pub fn ln_64(x_: f64) f64 {
103103
104 var x = x_;104 var x = x_;
105 var ix = @bitCast(u64, x);105 var ix = @bitCast(u64, x);
106 var hx = u32(ix >> 32);106 var hx = @intCast(u32, ix >> 32);
107 var k: i32 = 0;107 var k: i32 = 0;
108108
109 if (hx < 0x00100000 or hx >> 31 != 0) {109 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -119,7 +119,7 @@ pub fn ln_64(x_: f64) f64 {...@@ -119,7 +119,7 @@ pub fn ln_64(x_: f64) f64 {
119 // subnormal, scale x119 // subnormal, scale x
120 k -= 54;120 k -= 54;
121 x *= 0x1.0p54;121 x *= 0x1.0p54;
122 hx = u32(@bitCast(u64, ix) >> 32);122 hx = @intCast(u32, @bitCast(u64, ix) >> 32);
123 } else if (hx >= 0x7FF00000) {123 } else if (hx >= 0x7FF00000) {
124 return x;124 return x;
125 } else if (hx == 0x3FF00000 and ix << 32 == 0) {125 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -128,7 +128,7 @@ pub fn ln_64(x_: f64) f64 {...@@ -128,7 +128,7 @@ pub fn ln_64(x_: f64) f64 {
128128
129 // x into [sqrt(2) / 2, sqrt(2)]129 // x into [sqrt(2) / 2, sqrt(2)]
130 hx += 0x3FF00000 - 0x3FE6A09E;130 hx += 0x3FF00000 - 0x3FE6A09E;
131 k += i32(hx >> 20) - 0x3FF;131 k += @intCast(i32, hx >> 20) - 0x3FF;
132 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;132 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
133 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);133 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
134 x = @bitCast(f64, ix);134 x = @bitCast(f64, ix);
...@@ -141,7 +141,7 @@ pub fn ln_64(x_: f64) f64 {...@@ -141,7 +141,7 @@ pub fn ln_64(x_: f64) f64 {
141 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));141 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
142 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));142 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
143 const R = t2 + t1;143 const R = t2 + t1;
144 const dk = f64(k);144 const dk = @intToFloat(f64, k);
145145
146 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;146 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
147}147}
std/math/log.zig+6-5
...@@ -13,22 +13,23 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -13,22 +13,23 @@ pub fn log(comptime T: type, base: T, x: T) T {
13 return math.ln(x);13 return math.ln(x);
14 }14 }
1515
16 const float_base = math.lossyCast(f64, base);
16 switch (@typeId(T)) {17 switch (@typeId(T)) {
17 TypeId.ComptimeFloat => {18 TypeId.ComptimeFloat => {
18 return @typeOf(1.0)(math.ln(f64(x)) / math.ln(f64(base)));19 return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base));
19 },20 },
20 TypeId.ComptimeInt => {21 TypeId.ComptimeInt => {
21 return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(f64(base))));22 return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base)));
22 },23 },
23 builtin.TypeId.Int => {24 builtin.TypeId.Int => {
24 // TODO implement integer log without using float math25 // TODO implement integer log without using float math
25 return T(math.floor(math.ln(f64(x)) / math.ln(f64(base))));26 return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base)));
26 },27 },
2728
28 builtin.TypeId.Float => {29 builtin.TypeId.Float => {
29 switch (T) {30 switch (T) {
30 f32 => return f32(math.ln(f64(x)) / math.ln(f64(base))),31 f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)),
31 f64 => return math.ln(x) / math.ln(f64(base)),32 f64 => return math.ln(x) / math.ln(float_base),
32 else => @compileError("log not implemented for " ++ @typeName(T)),33 else => @compileError("log not implemented for " ++ @typeName(T)),
33 }34 }
34 },35 },
std/math/log10.zig+7-7
...@@ -28,7 +28,7 @@ pub fn log10(x: var) @typeOf(x) {...@@ -28,7 +28,7 @@ pub fn log10(x: var) @typeOf(x) {
28 return @typeOf(1)(math.floor(log10_64(f64(x))));28 return @typeOf(1)(math.floor(log10_64(f64(x))));
29 },29 },
30 TypeId.Int => {30 TypeId.Int => {
31 return T(math.floor(log10_64(f64(x))));31 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
32 },32 },
33 else => @compileError("log10 not implemented for " ++ @typeName(T)),33 else => @compileError("log10 not implemented for " ++ @typeName(T)),
34 }34 }
...@@ -71,7 +71,7 @@ pub fn log10_32(x_: f32) f32 {...@@ -71,7 +71,7 @@ pub fn log10_32(x_: f32) f32 {
7171
72 // x into [sqrt(2) / 2, sqrt(2)]72 // x into [sqrt(2) / 2, sqrt(2)]
73 ix += 0x3F800000 - 0x3F3504F3;73 ix += 0x3F800000 - 0x3F3504F3;
74 k += i32(ix >> 23) - 0x7F;74 k += @intCast(i32, ix >> 23) - 0x7F;
75 ix = (ix & 0x007FFFFF) + 0x3F3504F3;75 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
76 x = @bitCast(f32, ix);76 x = @bitCast(f32, ix);
7777
...@@ -89,7 +89,7 @@ pub fn log10_32(x_: f32) f32 {...@@ -89,7 +89,7 @@ pub fn log10_32(x_: f32) f32 {
89 u &= 0xFFFFF000;89 u &= 0xFFFFF000;
90 hi = @bitCast(f32, u);90 hi = @bitCast(f32, u);
91 const lo = f - hi - hfsq + s * (hfsq + R);91 const lo = f - hi - hfsq + s * (hfsq + R);
92 const dk = f32(k);92 const dk = @intToFloat(f32, k);
9393
94 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;94 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
95}95}
...@@ -109,7 +109,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -109,7 +109,7 @@ pub fn log10_64(x_: f64) f64 {
109109
110 var x = x_;110 var x = x_;
111 var ix = @bitCast(u64, x);111 var ix = @bitCast(u64, x);
112 var hx = u32(ix >> 32);112 var hx = @intCast(u32, ix >> 32);
113 var k: i32 = 0;113 var k: i32 = 0;
114114
115 if (hx < 0x00100000 or hx >> 31 != 0) {115 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -125,7 +125,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -125,7 +125,7 @@ pub fn log10_64(x_: f64) f64 {
125 // subnormal, scale x125 // subnormal, scale x
126 k -= 54;126 k -= 54;
127 x *= 0x1.0p54;127 x *= 0x1.0p54;
128 hx = u32(@bitCast(u64, x) >> 32);128 hx = @intCast(u32, @bitCast(u64, x) >> 32);
129 } else if (hx >= 0x7FF00000) {129 } else if (hx >= 0x7FF00000) {
130 return x;130 return x;
131 } else if (hx == 0x3FF00000 and ix << 32 == 0) {131 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -134,7 +134,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -134,7 +134,7 @@ pub fn log10_64(x_: f64) f64 {
134134
135 // x into [sqrt(2) / 2, sqrt(2)]135 // x into [sqrt(2) / 2, sqrt(2)]
136 hx += 0x3FF00000 - 0x3FE6A09E;136 hx += 0x3FF00000 - 0x3FE6A09E;
137 k += i32(hx >> 20) - 0x3FF;137 k += @intCast(i32, hx >> 20) - 0x3FF;
138 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;138 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
139 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);139 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
140 x = @bitCast(f64, ix);140 x = @bitCast(f64, ix);
...@@ -157,7 +157,7 @@ pub fn log10_64(x_: f64) f64 {...@@ -157,7 +157,7 @@ pub fn log10_64(x_: f64) f64 {
157157
158 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)158 // val_hi + val_lo ~ log10(1 + f) + k * log10(2)
159 var val_hi = hi * ivln10hi;159 var val_hi = hi * ivln10hi;
160 const dk = f64(k);160 const dk = @intToFloat(f64, k);
161 const y = dk * log10_2hi;161 const y = dk * log10_2hi;
162 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;162 var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;
163163
std/math/log1p.zig+6-6
...@@ -68,7 +68,7 @@ fn log1p_32(x: f32) f32 {...@@ -68,7 +68,7 @@ fn log1p_32(x: f32) f32 {
68 const uf = 1 + x;68 const uf = 1 + x;
69 var iu = @bitCast(u32, uf);69 var iu = @bitCast(u32, uf);
70 iu += 0x3F800000 - 0x3F3504F3;70 iu += 0x3F800000 - 0x3F3504F3;
71 k = i32(iu >> 23) - 0x7F;71 k = @intCast(i32, iu >> 23) - 0x7F;
7272
73 // correction to avoid underflow in c / u73 // correction to avoid underflow in c / u
74 if (k < 25) {74 if (k < 25) {
...@@ -90,7 +90,7 @@ fn log1p_32(x: f32) f32 {...@@ -90,7 +90,7 @@ fn log1p_32(x: f32) f32 {
90 const t2 = z * (Lg1 + w * Lg3);90 const t2 = z * (Lg1 + w * Lg3);
91 const R = t2 + t1;91 const R = t2 + t1;
92 const hfsq = 0.5 * f * f;92 const hfsq = 0.5 * f * f;
93 const dk = f32(k);93 const dk = @intToFloat(f32, k);
9494
95 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;95 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
96}96}
...@@ -107,7 +107,7 @@ fn log1p_64(x: f64) f64 {...@@ -107,7 +107,7 @@ fn log1p_64(x: f64) f64 {
107 const Lg7: f64 = 1.479819860511658591e-01;107 const Lg7: f64 = 1.479819860511658591e-01;
108108
109 var ix = @bitCast(u64, x);109 var ix = @bitCast(u64, x);
110 var hx = u32(ix >> 32);110 var hx = @intCast(u32, ix >> 32);
111 var k: i32 = 1;111 var k: i32 = 1;
112 var c: f64 = undefined;112 var c: f64 = undefined;
113 var f: f64 = undefined;113 var f: f64 = undefined;
...@@ -145,9 +145,9 @@ fn log1p_64(x: f64) f64 {...@@ -145,9 +145,9 @@ fn log1p_64(x: f64) f64 {
145 if (k != 0) {145 if (k != 0) {
146 const uf = 1 + x;146 const uf = 1 + x;
147 const hu = @bitCast(u64, uf);147 const hu = @bitCast(u64, uf);
148 var iu = u32(hu >> 32);148 var iu = @intCast(u32, hu >> 32);
149 iu += 0x3FF00000 - 0x3FE6A09E;149 iu += 0x3FF00000 - 0x3FE6A09E;
150 k = i32(iu >> 20) - 0x3FF;150 k = @intCast(i32, iu >> 20) - 0x3FF;
151151
152 // correction to avoid underflow in c / u152 // correction to avoid underflow in c / u
153 if (k < 54) {153 if (k < 54) {
...@@ -170,7 +170,7 @@ fn log1p_64(x: f64) f64 {...@@ -170,7 +170,7 @@ fn log1p_64(x: f64) f64 {
170 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));170 const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
171 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));171 const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
172 const R = t2 + t1;172 const R = t2 + t1;
173 const dk = f64(k);173 const dk = @intToFloat(f64, k);
174174
175 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;175 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
176}176}
std/math/log2.zig+6-6
...@@ -75,7 +75,7 @@ pub fn log2_32(x_: f32) f32 {...@@ -75,7 +75,7 @@ pub fn log2_32(x_: f32) f32 {
7575
76 // x into [sqrt(2) / 2, sqrt(2)]76 // x into [sqrt(2) / 2, sqrt(2)]
77 ix += 0x3F800000 - 0x3F3504F3;77 ix += 0x3F800000 - 0x3F3504F3;
78 k += i32(ix >> 23) - 0x7F;78 k += @intCast(i32, ix >> 23) - 0x7F;
79 ix = (ix & 0x007FFFFF) + 0x3F3504F3;79 ix = (ix & 0x007FFFFF) + 0x3F3504F3;
80 x = @bitCast(f32, ix);80 x = @bitCast(f32, ix);
8181
...@@ -93,7 +93,7 @@ pub fn log2_32(x_: f32) f32 {...@@ -93,7 +93,7 @@ pub fn log2_32(x_: f32) f32 {
93 u &= 0xFFFFF000;93 u &= 0xFFFFF000;
94 hi = @bitCast(f32, u);94 hi = @bitCast(f32, u);
95 const lo = f - hi - hfsq + s * (hfsq + R);95 const lo = f - hi - hfsq + s * (hfsq + R);
96 return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + f32(k);96 return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + @intToFloat(f32, k);
97}97}
9898
99pub fn log2_64(x_: f64) f64 {99pub fn log2_64(x_: f64) f64 {
...@@ -109,7 +109,7 @@ pub fn log2_64(x_: f64) f64 {...@@ -109,7 +109,7 @@ pub fn log2_64(x_: f64) f64 {
109109
110 var x = x_;110 var x = x_;
111 var ix = @bitCast(u64, x);111 var ix = @bitCast(u64, x);
112 var hx = u32(ix >> 32);112 var hx = @intCast(u32, ix >> 32);
113 var k: i32 = 0;113 var k: i32 = 0;
114114
115 if (hx < 0x00100000 or hx >> 31 != 0) {115 if (hx < 0x00100000 or hx >> 31 != 0) {
...@@ -125,7 +125,7 @@ pub fn log2_64(x_: f64) f64 {...@@ -125,7 +125,7 @@ pub fn log2_64(x_: f64) f64 {
125 // subnormal, scale x125 // subnormal, scale x
126 k -= 54;126 k -= 54;
127 x *= 0x1.0p54;127 x *= 0x1.0p54;
128 hx = u32(@bitCast(u64, x) >> 32);128 hx = @intCast(u32, @bitCast(u64, x) >> 32);
129 } else if (hx >= 0x7FF00000) {129 } else if (hx >= 0x7FF00000) {
130 return x;130 return x;
131 } else if (hx == 0x3FF00000 and ix << 32 == 0) {131 } else if (hx == 0x3FF00000 and ix << 32 == 0) {
...@@ -134,7 +134,7 @@ pub fn log2_64(x_: f64) f64 {...@@ -134,7 +134,7 @@ pub fn log2_64(x_: f64) f64 {
134134
135 // x into [sqrt(2) / 2, sqrt(2)]135 // x into [sqrt(2) / 2, sqrt(2)]
136 hx += 0x3FF00000 - 0x3FE6A09E;136 hx += 0x3FF00000 - 0x3FE6A09E;
137 k += i32(hx >> 20) - 0x3FF;137 k += @intCast(i32, hx >> 20) - 0x3FF;
138 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;138 hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
139 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);139 ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF);
140 x = @bitCast(f64, ix);140 x = @bitCast(f64, ix);
...@@ -159,7 +159,7 @@ pub fn log2_64(x_: f64) f64 {...@@ -159,7 +159,7 @@ pub fn log2_64(x_: f64) f64 {
159 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;159 var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;
160160
161 // spadd(val_hi, val_lo, y)161 // spadd(val_hi, val_lo, y)
162 const y = f64(k);162 const y = @intToFloat(f64, k);
163 const ww = y + val_hi;163 const ww = y + val_hi;
164 val_lo += (y - ww) + val_hi;164 val_lo += (y - ww) + val_hi;
165 val_hi = ww;165 val_hi = ww;
std/math/modf.zig+4-4
...@@ -29,7 +29,7 @@ fn modf32(x: f32) modf32_result {...@@ -29,7 +29,7 @@ fn modf32(x: f32) modf32_result {
29 var result: modf32_result = undefined;29 var result: modf32_result = undefined;
3030
31 const u = @bitCast(u32, x);31 const u = @bitCast(u32, x);
32 const e = i32((u >> 23) & 0xFF) - 0x7F;32 const e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;
33 const us = u & 0x80000000;33 const us = u & 0x80000000;
3434
35 // TODO: Shouldn't need this.35 // TODO: Shouldn't need this.
...@@ -57,7 +57,7 @@ fn modf32(x: f32) modf32_result {...@@ -57,7 +57,7 @@ fn modf32(x: f32) modf32_result {
57 return result;57 return result;
58 }58 }
5959
60 const mask = u32(0x007FFFFF) >> u5(e);60 const mask = u32(0x007FFFFF) >> @intCast(u5, e);
61 if (u & mask == 0) {61 if (u & mask == 0) {
62 result.ipart = x;62 result.ipart = x;
63 result.fpart = @bitCast(f32, us);63 result.fpart = @bitCast(f32, us);
...@@ -74,7 +74,7 @@ fn modf64(x: f64) modf64_result {...@@ -74,7 +74,7 @@ fn modf64(x: f64) modf64_result {
74 var result: modf64_result = undefined;74 var result: modf64_result = undefined;
7575
76 const u = @bitCast(u64, x);76 const u = @bitCast(u64, x);
77 const e = i32((u >> 52) & 0x7FF) - 0x3FF;77 const e = @intCast(i32, (u >> 52) & 0x7FF) - 0x3FF;
78 const us = u & (1 << 63);78 const us = u & (1 << 63);
7979
80 if (math.isInf(x)) {80 if (math.isInf(x)) {
...@@ -101,7 +101,7 @@ fn modf64(x: f64) modf64_result {...@@ -101,7 +101,7 @@ fn modf64(x: f64) modf64_result {
101 return result;101 return result;
102 }102 }
103103
104 const mask = u64(@maxValue(u64) >> 12) >> u6(e);104 const mask = u64(@maxValue(u64) >> 12) >> @intCast(u6, e);
105 if (u & mask == 0) {105 if (u & mask == 0) {
106 result.ipart = x;106 result.ipart = x;
107 result.fpart = @bitCast(f64, us);107 result.fpart = @bitCast(f64, us);
std/math/pow.zig+2-2
...@@ -146,7 +146,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {...@@ -146,7 +146,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
146 var xe = r2.exponent;146 var xe = r2.exponent;
147 var x1 = r2.significand;147 var x1 = r2.significand;
148148
149 var i = i32(yi);149 var i = @floatToInt(i32, yi);
150 while (i != 0) : (i >>= 1) {150 while (i != 0) : (i >>= 1) {
151 if (i & 1 == 1) {151 if (i & 1 == 1) {
152 a1 *= x1;152 a1 *= x1;
...@@ -171,7 +171,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {...@@ -171,7 +171,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
171171
172fn isOddInteger(x: f64) bool {172fn isOddInteger(x: f64) bool {
173 const r = math.modf(x);173 const r = math.modf(x);
174 return r.fpart == 0.0 and i64(r.ipart) & 1 == 1;174 return r.fpart == 0.0 and @floatToInt(i64, r.ipart) & 1 == 1;
175}175}
176176
177test "math.pow" {177test "math.pow" {
std/math/scalbn.zig+2-2
...@@ -37,7 +37,7 @@ fn scalbn32(x: f32, n_: i32) f32 {...@@ -37,7 +37,7 @@ fn scalbn32(x: f32, n_: i32) f32 {
37 }37 }
38 }38 }
3939
40 const u = u32(n +% 0x7F) << 23;40 const u = @intCast(u32, n +% 0x7F) << 23;
41 return y * @bitCast(f32, u);41 return y * @bitCast(f32, u);
42}42}
4343
...@@ -67,7 +67,7 @@ fn scalbn64(x: f64, n_: i32) f64 {...@@ -67,7 +67,7 @@ fn scalbn64(x: f64, n_: i32) f64 {
67 }67 }
68 }68 }
6969
70 const u = u64(n +% 0x3FF) << 52;70 const u = @intCast(u64, n +% 0x3FF) << 52;
71 return y * @bitCast(f64, u);71 return y * @bitCast(f64, u);
72}72}
7373
std/math/sin.zig+2-2
...@@ -60,7 +60,7 @@ fn sin32(x_: f32) f32 {...@@ -60,7 +60,7 @@ fn sin32(x_: f32) f32 {
60 }60 }
6161
62 var y = math.floor(x * m4pi);62 var y = math.floor(x * m4pi);
63 var j = i64(y);63 var j = @floatToInt(i64, y);
6464
65 if (j & 1 == 1) {65 if (j & 1 == 1) {
66 j += 1;66 j += 1;
...@@ -112,7 +112,7 @@ fn sin64(x_: f64) f64 {...@@ -112,7 +112,7 @@ fn sin64(x_: f64) f64 {
112 }112 }
113113
114 var y = math.floor(x * m4pi);114 var y = math.floor(x * m4pi);
115 var j = i64(y);115 var j = @floatToInt(i64, y);
116116
117 if (j & 1 == 1) {117 if (j & 1 == 1) {
118 j += 1;118 j += 1;
std/math/sinh.zig+1-1
...@@ -57,7 +57,7 @@ fn sinh64(x: f64) f64 {...@@ -57,7 +57,7 @@ fn sinh64(x: f64) f64 {
57 @setFloatMode(this, @import("builtin").FloatMode.Strict);57 @setFloatMode(this, @import("builtin").FloatMode.Strict);
5858
59 const u = @bitCast(u64, x);59 const u = @bitCast(u64, x);
60 const w = u32(u >> 32);60 const w = @intCast(u32, u >> 32);
61 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));61 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
6262
63 if (x == 0.0 or math.isNan(x)) {63 if (x == 0.0 or math.isNan(x)) {
std/math/sqrt.zig+1-1
...@@ -99,7 +99,7 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {...@@ -99,7 +99,7 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
99 }99 }
100100
101 const ResultType = @IntType(false, T.bit_count / 2);101 const ResultType = @IntType(false, T.bit_count / 2);
102 return ResultType(res);102 return @intCast(ResultType, res);
103}103}
104104
105test "math.sqrt_int" {105test "math.sqrt_int" {
std/math/tan.zig+2-2
...@@ -53,7 +53,7 @@ fn tan32(x_: f32) f32 {...@@ -53,7 +53,7 @@ fn tan32(x_: f32) f32 {
53 }53 }
5454
55 var y = math.floor(x * m4pi);55 var y = math.floor(x * m4pi);
56 var j = i64(y);56 var j = @floatToInt(i64, y);
5757
58 if (j & 1 == 1) {58 if (j & 1 == 1) {
59 j += 1;59 j += 1;
...@@ -102,7 +102,7 @@ fn tan64(x_: f64) f64 {...@@ -102,7 +102,7 @@ fn tan64(x_: f64) f64 {
102 }102 }
103103
104 var y = math.floor(x * m4pi);104 var y = math.floor(x * m4pi);
105 var j = i64(y);105 var j = @floatToInt(i64, y);
106106
107 if (j & 1 == 1) {107 if (j & 1 == 1) {
108 j += 1;108 j += 1;
std/math/tanh.zig+2-2
...@@ -68,7 +68,7 @@ fn tanh32(x: f32) f32 {...@@ -68,7 +68,7 @@ fn tanh32(x: f32) f32 {
6868
69fn tanh64(x: f64) f64 {69fn tanh64(x: f64) f64 {
70 const u = @bitCast(u64, x);70 const u = @bitCast(u64, x);
71 const w = u32(u >> 32);71 const w = @intCast(u32, u >> 32);
72 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));72 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
7373
74 var t: f64 = undefined;74 var t: f64 = undefined;
...@@ -100,7 +100,7 @@ fn tanh64(x: f64) f64 {...@@ -100,7 +100,7 @@ fn tanh64(x: f64) f64 {
100 }100 }
101 // |x| is subnormal101 // |x| is subnormal
102 else {102 else {
103 math.forceEval(f32(x));103 math.forceEval(@floatCast(f32, x));
104 t = x;104 t = x;
105 }105 }
106106
std/math/trunc.zig+4-4
...@@ -19,7 +19,7 @@ pub fn trunc(x: var) @typeOf(x) {...@@ -19,7 +19,7 @@ pub fn trunc(x: var) @typeOf(x) {
1919
20fn trunc32(x: f32) f32 {20fn trunc32(x: f32) f32 {
21 const u = @bitCast(u32, x);21 const u = @bitCast(u32, x);
22 var e = i32(((u >> 23) & 0xFF)) - 0x7F + 9;22 var e = @intCast(i32, ((u >> 23) & 0xFF)) - 0x7F + 9;
23 var m: u32 = undefined;23 var m: u32 = undefined;
2424
25 if (e >= 23 + 9) {25 if (e >= 23 + 9) {
...@@ -29,7 +29,7 @@ fn trunc32(x: f32) f32 {...@@ -29,7 +29,7 @@ fn trunc32(x: f32) f32 {
29 e = 1;29 e = 1;
30 }30 }
3131
32 m = u32(@maxValue(u32)) >> u5(e);32 m = u32(@maxValue(u32)) >> @intCast(u5, e);
33 if (u & m == 0) {33 if (u & m == 0) {
34 return x;34 return x;
35 } else {35 } else {
...@@ -40,7 +40,7 @@ fn trunc32(x: f32) f32 {...@@ -40,7 +40,7 @@ fn trunc32(x: f32) f32 {
4040
41fn trunc64(x: f64) f64 {41fn trunc64(x: f64) f64 {
42 const u = @bitCast(u64, x);42 const u = @bitCast(u64, x);
43 var e = i32(((u >> 52) & 0x7FF)) - 0x3FF + 12;43 var e = @intCast(i32, ((u >> 52) & 0x7FF)) - 0x3FF + 12;
44 var m: u64 = undefined;44 var m: u64 = undefined;
4545
46 if (e >= 52 + 12) {46 if (e >= 52 + 12) {
...@@ -50,7 +50,7 @@ fn trunc64(x: f64) f64 {...@@ -50,7 +50,7 @@ fn trunc64(x: f64) f64 {
50 e = 1;50 e = 1;
51 }51 }
5252
53 m = u64(@maxValue(u64)) >> u6(e);53 m = u64(@maxValue(u64)) >> @intCast(u6, e);
54 if (u & m == 0) {54 if (u & m == 0) {
55 return x;55 return x;
56 } else {56 } else {
std/mem.zig+1-1
...@@ -334,7 +334,7 @@ pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) T {...@@ -334,7 +334,7 @@ pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) T {
334 builtin.Endian.Little => {334 builtin.Endian.Little => {
335 const ShiftType = math.Log2Int(T);335 const ShiftType = math.Log2Int(T);
336 for (bytes) |b, index| {336 for (bytes) |b, index| {
337 result = result | (T(b) << ShiftType(index * 8));337 result = result | (T(b) << @intCast(ShiftType, index * 8));
338 }338 }
339 },339 },
340 }340 }
std/os/child_process.zig+1-1
...@@ -413,7 +413,7 @@ pub const ChildProcess = struct {...@@ -413,7 +413,7 @@ pub const ChildProcess = struct {
413 }413 }
414414
415 // we are the parent415 // we are the parent
416 const pid = i32(pid_result);416 const pid = @intCast(i32, pid_result);
417 if (self.stdin_behavior == StdIo.Pipe) {417 if (self.stdin_behavior == StdIo.Pipe) {
418 self.stdin = os.File.openHandle(stdin_pipe[1]);418 self.stdin = os.File.openHandle(stdin_pipe[1]);
419 } else {419 } else {
std/os/darwin.zig+9-2
...@@ -290,7 +290,7 @@ pub fn WIFSIGNALED(x: i32) bool {...@@ -290,7 +290,7 @@ pub fn WIFSIGNALED(x: i32) bool {
290/// Get the errno from a syscall return value, or 0 for no error.290/// Get the errno from a syscall return value, or 0 for no error.
291pub fn getErrno(r: usize) usize {291pub fn getErrno(r: usize) usize {
292 const signed_r = @bitCast(isize, r);292 const signed_r = @bitCast(isize, r);
293 return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;293 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
294}294}
295295
296pub fn close(fd: i32) usize {296pub fn close(fd: i32) usize {
...@@ -339,7 +339,14 @@ pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {...@@ -339,7 +339,14 @@ pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
339}339}
340340
341pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {341pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
342 const ptr_result = c.mmap(@ptrCast(*c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);342 const ptr_result = c.mmap(
343 @ptrCast(*c_void, address),
344 length,
345 @bitCast(c_int, @intCast(c_uint, prot)),
346 @bitCast(c_int, c_uint(flags)),
347 fd,
348 offset,
349 );
343 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));350 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
344 return errnoWrap(isize_result);351 return errnoWrap(isize_result);
345}352}
std/os/file.zig+3-3
...@@ -266,7 +266,7 @@ pub const File = struct {...@@ -266,7 +266,7 @@ pub const File = struct {
266 pub fn getEndPos(self: *File) !usize {266 pub fn getEndPos(self: *File) !usize {
267 if (is_posix) {267 if (is_posix) {
268 const stat = try os.posixFStat(self.handle);268 const stat = try os.posixFStat(self.handle);
269 return usize(stat.size);269 return @intCast(usize, stat.size);
270 } else if (is_windows) {270 } else if (is_windows) {
271 var file_size: windows.LARGE_INTEGER = undefined;271 var file_size: windows.LARGE_INTEGER = undefined;
272 if (windows.GetFileSizeEx(self.handle, &file_size) == 0) {272 if (windows.GetFileSizeEx(self.handle, &file_size) == 0) {
...@@ -277,7 +277,7 @@ pub const File = struct {...@@ -277,7 +277,7 @@ pub const File = struct {
277 }277 }
278 if (file_size < 0)278 if (file_size < 0)
279 return error.Overflow;279 return error.Overflow;
280 return math.cast(usize, u64(file_size));280 return math.cast(usize, @intCast(u64, file_size));
281 } else {281 } else {
282 @compileError("TODO support getEndPos on this OS");282 @compileError("TODO support getEndPos on this OS");
283 }283 }
...@@ -343,7 +343,7 @@ pub const File = struct {...@@ -343,7 +343,7 @@ pub const File = struct {
343 } else if (is_windows) {343 } else if (is_windows) {
344 var index: usize = 0;344 var index: usize = 0;
345 while (index < buffer.len) {345 while (index < buffer.len) {
346 const want_read_count = windows.DWORD(math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index));346 const want_read_count = @intCast(windows.DWORD, math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index));
347 var amt_read: windows.DWORD = undefined;347 var amt_read: windows.DWORD = undefined;
348 if (windows.ReadFile(self.handle, @ptrCast(*c_void, buffer.ptr + index), want_read_count, &amt_read, null) == 0) {348 if (windows.ReadFile(self.handle, @ptrCast(*c_void, buffer.ptr + index), want_read_count, &amt_read, null) == 0) {
349 const err = windows.GetLastError();349 const err = windows.GetLastError();
std/os/index.zig+8-8
...@@ -126,7 +126,7 @@ pub fn getRandomBytes(buf: []u8) !void {...@@ -126,7 +126,7 @@ pub fn getRandomBytes(buf: []u8) !void {
126 }126 }
127 defer _ = windows.CryptReleaseContext(hCryptProv, 0);127 defer _ = windows.CryptReleaseContext(hCryptProv, 0);
128128
129 if (windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr) == 0) {129 if (windows.CryptGenRandom(hCryptProv, @intCast(windows.DWORD, buf.len), buf.ptr) == 0) {
130 const err = windows.GetLastError();130 const err = windows.GetLastError();
131 return switch (err) {131 return switch (err) {
132 else => unexpectedErrorWindows(err),132 else => unexpectedErrorWindows(err),
...@@ -343,7 +343,7 @@ pub fn posixOpenC(file_path: [*]const u8, flags: u32, perm: usize) !i32 {...@@ -343,7 +343,7 @@ pub fn posixOpenC(file_path: [*]const u8, flags: u32, perm: usize) !i32 {
343 else => return unexpectedErrorPosix(err),343 else => return unexpectedErrorPosix(err),
344 }344 }
345 }345 }
346 return i32(result);346 return @intCast(i32, result);
347 }347 }
348}348}
349349
...@@ -586,7 +586,7 @@ pub fn getCwd(allocator: *Allocator) ![]u8 {...@@ -586,7 +586,7 @@ pub fn getCwd(allocator: *Allocator) ![]u8 {
586 errdefer allocator.free(buf);586 errdefer allocator.free(buf);
587587
588 while (true) {588 while (true) {
589 const result = windows.GetCurrentDirectoryA(windows.WORD(buf.len), buf.ptr);589 const result = windows.GetCurrentDirectoryA(@intCast(windows.WORD, buf.len), buf.ptr);
590590
591 if (result == 0) {591 if (result == 0) {
592 const err = windows.GetLastError();592 const err = windows.GetLastError();
...@@ -2019,7 +2019,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {...@@ -2019,7 +2019,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {
2019 const rc = posix.socket(domain, socket_type, protocol);2019 const rc = posix.socket(domain, socket_type, protocol);
2020 const err = posix.getErrno(rc);2020 const err = posix.getErrno(rc);
2021 switch (err) {2021 switch (err) {
2022 0 => return i32(rc),2022 0 => return @intCast(i32, rc),
2023 posix.EACCES => return PosixSocketError.PermissionDenied,2023 posix.EACCES => return PosixSocketError.PermissionDenied,
2024 posix.EAFNOSUPPORT => return PosixSocketError.AddressFamilyNotSupported,2024 posix.EAFNOSUPPORT => return PosixSocketError.AddressFamilyNotSupported,
2025 posix.EINVAL => return PosixSocketError.ProtocolFamilyNotAvailable,2025 posix.EINVAL => return PosixSocketError.ProtocolFamilyNotAvailable,
...@@ -2183,7 +2183,7 @@ pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError!...@@ -2183,7 +2183,7 @@ pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError!
2183 const rc = posix.accept4(fd, addr, &sockaddr_size, flags);2183 const rc = posix.accept4(fd, addr, &sockaddr_size, flags);
2184 const err = posix.getErrno(rc);2184 const err = posix.getErrno(rc);
2185 switch (err) {2185 switch (err) {
2186 0 => return i32(rc),2186 0 => return @intCast(i32, rc),
2187 posix.EINTR => continue,2187 posix.EINTR => continue,
2188 else => return unexpectedErrorPosix(err),2188 else => return unexpectedErrorPosix(err),
21892189
...@@ -2226,7 +2226,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 {...@@ -2226,7 +2226,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 {
2226 const rc = posix.epoll_create1(flags);2226 const rc = posix.epoll_create1(flags);
2227 const err = posix.getErrno(rc);2227 const err = posix.getErrno(rc);
2228 switch (err) {2228 switch (err) {
2229 0 => return i32(rc),2229 0 => return @intCast(i32, rc),
2230 else => return unexpectedErrorPosix(err),2230 else => return unexpectedErrorPosix(err),
22312231
2232 posix.EINVAL => return LinuxEpollCreateError.InvalidSyscall,2232 posix.EINVAL => return LinuxEpollCreateError.InvalidSyscall,
...@@ -2296,7 +2296,7 @@ pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: *linux.epoll_event) Lin...@@ -2296,7 +2296,7 @@ pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: *linux.epoll_event) Lin
22962296
2297pub fn linuxEpollWait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize {2297pub fn linuxEpollWait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize {
2298 while (true) {2298 while (true) {
2299 const rc = posix.epoll_wait(epfd, events.ptr, u32(events.len), timeout);2299 const rc = posix.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);
2300 const err = posix.getErrno(rc);2300 const err = posix.getErrno(rc);
2301 switch (err) {2301 switch (err) {
2302 0 => return rc,2302 0 => return rc,
...@@ -2661,7 +2661,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread...@@ -2661,7 +2661,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
2661 posix.EAGAIN => return SpawnThreadError.SystemResources,2661 posix.EAGAIN => return SpawnThreadError.SystemResources,
2662 posix.EPERM => unreachable,2662 posix.EPERM => unreachable,
2663 posix.EINVAL => unreachable,2663 posix.EINVAL => unreachable,
2664 else => return unexpectedErrorPosix(usize(err)),2664 else => return unexpectedErrorPosix(@intCast(usize, err)),
2665 }2665 }
2666 } else if (builtin.os == builtin.Os.linux) {2666 } else if (builtin.os == builtin.Os.linux) {
2667 // use linux API directly. TODO use posix.CLONE_SETTLS and initialize thread local storage correctly2667 // use linux API directly. TODO use posix.CLONE_SETTLS and initialize thread local storage correctly
std/os/linux/index.zig+40-40
...@@ -642,7 +642,7 @@ pub fn WIFEXITED(s: i32) bool {...@@ -642,7 +642,7 @@ pub fn WIFEXITED(s: i32) bool {
642 return WTERMSIG(s) == 0;642 return WTERMSIG(s) == 0;
643}643}
644pub fn WIFSTOPPED(s: i32) bool {644pub fn WIFSTOPPED(s: i32) bool {
645 return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;645 return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
646}646}
647pub fn WIFSIGNALED(s: i32) bool {647pub fn WIFSIGNALED(s: i32) bool {
648 return (unsigned(s) & 0xffff) -% 1 < 0xff;648 return (unsigned(s) & 0xffff) -% 1 < 0xff;
...@@ -658,11 +658,11 @@ pub const winsize = extern struct {...@@ -658,11 +658,11 @@ pub const winsize = extern struct {
658/// Get the errno from a syscall return value, or 0 for no error.658/// Get the errno from a syscall return value, or 0 for no error.
659pub fn getErrno(r: usize) usize {659pub fn getErrno(r: usize) usize {
660 const signed_r = @bitCast(isize, r);660 const signed_r = @bitCast(isize, r);
661 return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;661 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
662}662}
663663
664pub fn dup2(old: i32, new: i32) usize {664pub fn dup2(old: i32, new: i32) usize {
665 return syscall2(SYS_dup2, usize(old), usize(new));665 return syscall2(SYS_dup2, @intCast(usize, old), @intCast(usize, new));
666}666}
667667
668// TODO https://github.com/ziglang/zig/issues/265668// TODO https://github.com/ziglang/zig/issues/265
...@@ -693,12 +693,12 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {...@@ -693,12 +693,12 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
693}693}
694694
695pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {695pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
696 return syscall3(SYS_getdents, usize(fd), @ptrToInt(dirp), count);696 return syscall3(SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count);
697}697}
698698
699pub fn isatty(fd: i32) bool {699pub fn isatty(fd: i32) bool {
700 var wsz: winsize = undefined;700 var wsz: winsize = undefined;
701 return syscall3(SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;701 return syscall3(SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
702}702}
703703
704// TODO https://github.com/ziglang/zig/issues/265704// TODO https://github.com/ziglang/zig/issues/265
...@@ -727,7 +727,7 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {...@@ -727,7 +727,7 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
727}727}
728728
729pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {729pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
730 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));730 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset));
731}731}
732732
733pub fn munmap(address: usize, length: usize) usize {733pub fn munmap(address: usize, length: usize) usize {
...@@ -735,7 +735,7 @@ pub fn munmap(address: usize, length: usize) usize {...@@ -735,7 +735,7 @@ pub fn munmap(address: usize, length: usize) usize {
735}735}
736736
737pub fn read(fd: i32, buf: [*]u8, count: usize) usize {737pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
738 return syscall3(SYS_read, usize(fd), @ptrToInt(buf), count);738 return syscall3(SYS_read, @intCast(usize, fd), @ptrToInt(buf), count);
739}739}
740740
741// TODO https://github.com/ziglang/zig/issues/265741// TODO https://github.com/ziglang/zig/issues/265
...@@ -749,7 +749,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {...@@ -749,7 +749,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
749}749}
750750
751pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {751pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
752 return syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset);752 return syscall4(SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset);
753}753}
754754
755// TODO https://github.com/ziglang/zig/issues/265755// TODO https://github.com/ziglang/zig/issues/265
...@@ -766,11 +766,11 @@ pub fn pipe2(fd: *[2]i32, flags: usize) usize {...@@ -766,11 +766,11 @@ pub fn pipe2(fd: *[2]i32, flags: usize) usize {
766}766}
767767
768pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {768pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
769 return syscall3(SYS_write, usize(fd), @ptrToInt(buf), count);769 return syscall3(SYS_write, @intCast(usize, fd), @ptrToInt(buf), count);
770}770}
771771
772pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {772pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
773 return syscall4(SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);773 return syscall4(SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset);
774}774}
775775
776// TODO https://github.com/ziglang/zig/issues/265776// TODO https://github.com/ziglang/zig/issues/265
...@@ -790,7 +790,7 @@ pub fn create(path: [*]const u8, perm: usize) usize {...@@ -790,7 +790,7 @@ pub fn create(path: [*]const u8, perm: usize) usize {
790790
791// TODO https://github.com/ziglang/zig/issues/265791// TODO https://github.com/ziglang/zig/issues/265
792pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {792pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
793 return syscall4(SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);793 return syscall4(SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode);
794}794}
795795
796/// See also `clone` (from the arch-specific include)796/// See also `clone` (from the arch-specific include)
...@@ -804,11 +804,11 @@ pub fn clone2(flags: usize, child_stack_ptr: usize) usize {...@@ -804,11 +804,11 @@ pub fn clone2(flags: usize, child_stack_ptr: usize) usize {
804}804}
805805
806pub fn close(fd: i32) usize {806pub fn close(fd: i32) usize {
807 return syscall1(SYS_close, usize(fd));807 return syscall1(SYS_close, @intCast(usize, fd));
808}808}
809809
810pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {810pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
811 return syscall3(SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos);811 return syscall3(SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos);
812}812}
813813
814pub fn exit(status: i32) noreturn {814pub fn exit(status: i32) noreturn {
...@@ -817,11 +817,11 @@ pub fn exit(status: i32) noreturn {...@@ -817,11 +817,11 @@ pub fn exit(status: i32) noreturn {
817}817}
818818
819pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {819pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
820 return syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));820 return syscall3(SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags));
821}821}
822822
823pub fn kill(pid: i32, sig: i32) usize {823pub fn kill(pid: i32, sig: i32) usize {
824 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), usize(sig));824 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @intCast(usize, sig));
825}825}
826826
827// TODO https://github.com/ziglang/zig/issues/265827// TODO https://github.com/ziglang/zig/issues/265
...@@ -999,8 +999,8 @@ pub const empty_sigset = []usize{0} ** sigset_t.len;...@@ -999,8 +999,8 @@ pub const empty_sigset = []usize{0} ** sigset_t.len;
999pub fn raise(sig: i32) usize {999pub fn raise(sig: i32) usize {
1000 var set: sigset_t = undefined;1000 var set: sigset_t = undefined;
1001 blockAppSignals(&set);1001 blockAppSignals(&set);
1002 const tid = i32(syscall0(SYS_gettid));1002 const tid = @intCast(i32, syscall0(SYS_gettid));
1003 const ret = syscall2(SYS_tkill, usize(tid), usize(sig));1003 const ret = syscall2(SYS_tkill, @intCast(usize, tid), @intCast(usize, sig));
1004 restoreSignals(&set);1004 restoreSignals(&set);
1005 return ret;1005 return ret;
1006}1006}
...@@ -1019,12 +1019,12 @@ fn restoreSignals(set: *sigset_t) void {...@@ -1019,12 +1019,12 @@ fn restoreSignals(set: *sigset_t) void {
10191019
1020pub fn sigaddset(set: *sigset_t, sig: u6) void {1020pub fn sigaddset(set: *sigset_t, sig: u6) void {
1021 const s = sig - 1;1021 const s = sig - 1;
1022 (set.*)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));1022 (set.*)[@intCast(usize, s) / usize.bit_count] |= @intCast(usize, 1) << (s & (usize.bit_count - 1));
1023}1023}
10241024
1025pub fn sigismember(set: *const sigset_t, sig: u6) bool {1025pub fn sigismember(set: *const sigset_t, sig: u6) bool {
1026 const s = sig - 1;1026 const s = sig - 1;
1027 return ((set.*)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;1027 return ((set.*)[@intCast(usize, s) / usize.bit_count] & (@intCast(usize, 1) << (s & (usize.bit_count - 1)))) != 0;
1028}1028}
10291029
1030pub const in_port_t = u16;1030pub const in_port_t = u16;
...@@ -1057,11 +1057,11 @@ pub const iovec = extern struct {...@@ -1057,11 +1057,11 @@ pub const iovec = extern struct {
1057};1057};
10581058
1059pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {1059pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1060 return syscall3(SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));1060 return syscall3(SYS_getsockname, @intCast(usize, fd), @ptrToInt(addr), @ptrToInt(len));
1061}1061}
10621062
1063pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {1063pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1064 return syscall3(SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));1064 return syscall3(SYS_getpeername, @intCast(usize, fd), @ptrToInt(addr), @ptrToInt(len));
1065}1065}
10661066
1067pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {1067pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
...@@ -1069,47 +1069,47 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {...@@ -1069,47 +1069,47 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
1069}1069}
10701070
1071pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {1071pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
1072 return syscall5(SYS_setsockopt, usize(fd), level, optname, usize(optval), @ptrToInt(optlen));1072 return syscall5(SYS_setsockopt, @intCast(usize, fd), level, optname, @intCast(usize, optval), @ptrToInt(optlen));
1073}1073}
10741074
1075pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {1075pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
1076 return syscall5(SYS_getsockopt, usize(fd), level, optname, @ptrToInt(optval), @ptrToInt(optlen));1076 return syscall5(SYS_getsockopt, @intCast(usize, fd), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
1077}1077}
10781078
1079pub fn sendmsg(fd: i32, msg: *const msghdr, flags: u32) usize {1079pub fn sendmsg(fd: i32, msg: *const msghdr, flags: u32) usize {
1080 return syscall3(SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);1080 return syscall3(SYS_sendmsg, @intCast(usize, fd), @ptrToInt(msg), flags);
1081}1081}
10821082
1083pub fn connect(fd: i32, addr: *const sockaddr, len: socklen_t) usize {1083pub fn connect(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
1084 return syscall3(SYS_connect, usize(fd), @ptrToInt(addr), usize(len));1084 return syscall3(SYS_connect, @intCast(usize, fd), @ptrToInt(addr), @intCast(usize, len));
1085}1085}
10861086
1087pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {1087pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
1088 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);1088 return syscall3(SYS_recvmsg, @intCast(usize, fd), @ptrToInt(msg), flags);
1089}1089}
10901090
1091pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {1091pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
1092 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));1092 return syscall6(SYS_recvfrom, @intCast(usize, fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
1093}1093}
10941094
1095pub fn shutdown(fd: i32, how: i32) usize {1095pub fn shutdown(fd: i32, how: i32) usize {
1096 return syscall2(SYS_shutdown, usize(fd), usize(how));1096 return syscall2(SYS_shutdown, @intCast(usize, fd), @intCast(usize, how));
1097}1097}
10981098
1099pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {1099pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
1100 return syscall3(SYS_bind, usize(fd), @ptrToInt(addr), usize(len));1100 return syscall3(SYS_bind, @intCast(usize, fd), @ptrToInt(addr), @intCast(usize, len));
1101}1101}
11021102
1103pub fn listen(fd: i32, backlog: u32) usize {1103pub fn listen(fd: i32, backlog: u32) usize {
1104 return syscall2(SYS_listen, usize(fd), backlog);1104 return syscall2(SYS_listen, @intCast(usize, fd), backlog);
1105}1105}
11061106
1107pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {1107pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
1108 return syscall6(SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));1108 return syscall6(SYS_sendto, @intCast(usize, fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
1109}1109}
11101110
1111pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {1111pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
1112 return syscall4(SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(*fd[0]));1112 return syscall4(SYS_socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(*fd[0]));
1113}1113}
11141114
1115pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {1115pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
...@@ -1117,11 +1117,11 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {...@@ -1117,11 +1117,11 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1117}1117}
11181118
1119pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {1119pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {
1120 return syscall4(SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);1120 return syscall4(SYS_accept4, @intCast(usize, fd), @ptrToInt(addr), @ptrToInt(len), flags);
1121}1121}
11221122
1123pub fn fstat(fd: i32, stat_buf: *Stat) usize {1123pub fn fstat(fd: i32, stat_buf: *Stat) usize {
1124 return syscall2(SYS_fstat, usize(fd), @ptrToInt(stat_buf));1124 return syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
1125}1125}
11261126
1127// TODO https://github.com/ziglang/zig/issues/2651127// TODO https://github.com/ziglang/zig/issues/265
...@@ -1214,15 +1214,15 @@ pub fn epoll_create1(flags: usize) usize {...@@ -1214,15 +1214,15 @@ pub fn epoll_create1(flags: usize) usize {
1214}1214}
12151215
1216pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize {1216pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize {
1217 return syscall4(SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));1217 return syscall4(SYS_epoll_ctl, @intCast(usize, epoll_fd), @intCast(usize, op), @intCast(usize, fd), @ptrToInt(ev));
1218}1218}
12191219
1220pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {1220pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
1221 return syscall4(SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));1221 return syscall4(SYS_epoll_wait, @intCast(usize, epoll_fd), @ptrToInt(events), @intCast(usize, maxevents), @intCast(usize, timeout));
1222}1222}
12231223
1224pub fn timerfd_create(clockid: i32, flags: u32) usize {1224pub fn timerfd_create(clockid: i32, flags: u32) usize {
1225 return syscall2(SYS_timerfd_create, usize(clockid), usize(flags));1225 return syscall2(SYS_timerfd_create, @intCast(usize, clockid), @intCast(usize, flags));
1226}1226}
12271227
1228pub const itimerspec = extern struct {1228pub const itimerspec = extern struct {
...@@ -1231,11 +1231,11 @@ pub const itimerspec = extern struct {...@@ -1231,11 +1231,11 @@ pub const itimerspec = extern struct {
1231};1231};
12321232
1233pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {1233pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
1234 return syscall2(SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));1234 return syscall2(SYS_timerfd_gettime, @intCast(usize, fd), @ptrToInt(curr_value));
1235}1235}
12361236
1237pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {1237pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1238 return syscall4(SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));1238 return syscall4(SYS_timerfd_settime, @intCast(usize, fd), @intCast(usize, flags), @ptrToInt(new_value), @ptrToInt(old_value));
1239}1239}
12401240
1241pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;1241pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
...@@ -1345,7 +1345,7 @@ pub const cap_user_data_t = extern struct {...@@ -1345,7 +1345,7 @@ pub const cap_user_data_t = extern struct {
1345};1345};
13461346
1347pub fn unshare(flags: usize) usize {1347pub fn unshare(flags: usize) usize {
1348 return syscall1(SYS_unshare, usize(flags));1348 return syscall1(SYS_unshare, @intCast(usize, flags));
1349}1349}
13501350
1351pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize {1351pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize {
std/os/linux/test.zig+3-3
...@@ -21,7 +21,7 @@ test "timer" {...@@ -21,7 +21,7 @@ test "timer" {
21 .it_value = time_interval,21 .it_value = time_interval,
22 };22 };
2323
24 err = linux.timerfd_settime(i32(timer_fd), 0, &new_time, null);24 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
25 assert(err == 0);25 assert(err == 0);
2626
27 var event = linux.epoll_event{27 var event = linux.epoll_event{
...@@ -29,12 +29,12 @@ test "timer" {...@@ -29,12 +29,12 @@ test "timer" {
29 .data = linux.epoll_data{ .ptr = 0 },29 .data = linux.epoll_data{ .ptr = 0 },
30 };30 };
3131
32 err = linux.epoll_ctl(i32(epoll_fd), linux.EPOLL_CTL_ADD, i32(timer_fd), &event);32 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
33 assert(err == 0);33 assert(err == 0);
3434
35 const events_one: linux.epoll_event = undefined;35 const events_one: linux.epoll_event = undefined;
36 var events = []linux.epoll_event{events_one} ** 8;36 var events = []linux.epoll_event{events_one} ** 8;
3737
38 // TODO implicit cast from *[N]T to [*]T38 // TODO implicit cast from *[N]T to [*]T
39 err = linux.epoll_wait(i32(epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);39 err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
40}40}
std/os/linux/vdso.zig+2-2
...@@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6262
63 var i: usize = 0;63 var i: usize = 0;
64 while (i < hashtab[1]) : (i += 1) {64 while (i < hashtab[1]) : (i += 1) {
65 if (0 == (u32(1) << u5(syms[i].st_info & 0xf) & OK_TYPES)) continue;65 if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
66 if (0 == (u32(1) << u5(syms[i].st_info >> 4) & OK_BINDS)) continue;66 if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
67 if (0 == syms[i].st_shndx) continue;67 if (0 == syms[i].st_shndx) continue;
68 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;68 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;
69 if (maybe_versym) |versym| {69 if (maybe_versym) |versym| {
std/os/time.zig+12-12
...@@ -14,12 +14,12 @@ pub const epoch = @import("epoch.zig");...@@ -14,12 +14,12 @@ pub const epoch = @import("epoch.zig");
14pub fn sleep(seconds: usize, nanoseconds: usize) void {14pub fn sleep(seconds: usize, nanoseconds: usize) void {
15 switch (builtin.os) {15 switch (builtin.os) {
16 Os.linux, Os.macosx, Os.ios => {16 Os.linux, Os.macosx, Os.ios => {
17 posixSleep(u63(seconds), u63(nanoseconds));17 posixSleep(@intCast(u63, seconds), @intCast(u63, nanoseconds));
18 },18 },
19 Os.windows => {19 Os.windows => {
20 const ns_per_ms = ns_per_s / ms_per_s;20 const ns_per_ms = ns_per_s / ms_per_s;
21 const milliseconds = seconds * ms_per_s + nanoseconds / ns_per_ms;21 const milliseconds = seconds * ms_per_s + nanoseconds / ns_per_ms;
22 windows.Sleep(windows.DWORD(milliseconds));22 windows.Sleep(@intCast(windows.DWORD, milliseconds));
23 },23 },
24 else => @compileError("Unsupported OS"),24 else => @compileError("Unsupported OS"),
25 }25 }
...@@ -83,8 +83,8 @@ fn milliTimestampDarwin() u64 {...@@ -83,8 +83,8 @@ fn milliTimestampDarwin() u64 {
83 var tv: darwin.timeval = undefined;83 var tv: darwin.timeval = undefined;
84 var err = darwin.gettimeofday(&tv, null);84 var err = darwin.gettimeofday(&tv, null);
85 debug.assert(err == 0);85 debug.assert(err == 0);
86 const sec_ms = u64(tv.tv_sec) * ms_per_s;86 const sec_ms = @intCast(u64, tv.tv_sec) * ms_per_s;
87 const usec_ms = @divFloor(u64(tv.tv_usec), us_per_s / ms_per_s);87 const usec_ms = @divFloor(@intCast(u64, tv.tv_usec), us_per_s / ms_per_s);
88 return u64(sec_ms) + u64(usec_ms);88 return u64(sec_ms) + u64(usec_ms);
89}89}
9090
...@@ -95,8 +95,8 @@ fn milliTimestampPosix() u64 {...@@ -95,8 +95,8 @@ fn milliTimestampPosix() u64 {
95 var ts: posix.timespec = undefined;95 var ts: posix.timespec = undefined;
96 const err = posix.clock_gettime(posix.CLOCK_REALTIME, &ts);96 const err = posix.clock_gettime(posix.CLOCK_REALTIME, &ts);
97 debug.assert(err == 0);97 debug.assert(err == 0);
98 const sec_ms = u64(ts.tv_sec) * ms_per_s;98 const sec_ms = @intCast(u64, ts.tv_sec) * ms_per_s;
99 const nsec_ms = @divFloor(u64(ts.tv_nsec), ns_per_s / ms_per_s);99 const nsec_ms = @divFloor(@intCast(u64, ts.tv_nsec), ns_per_s / ms_per_s);
100 return sec_ms + nsec_ms;100 return sec_ms + nsec_ms;
101}101}
102102
...@@ -162,13 +162,13 @@ pub const Timer = struct {...@@ -162,13 +162,13 @@ pub const Timer = struct {
162 var freq: i64 = undefined;162 var freq: i64 = undefined;
163 var err = windows.QueryPerformanceFrequency(&freq);163 var err = windows.QueryPerformanceFrequency(&freq);
164 if (err == windows.FALSE) return error.TimerUnsupported;164 if (err == windows.FALSE) return error.TimerUnsupported;
165 self.frequency = u64(freq);165 self.frequency = @intCast(u64, freq);
166 self.resolution = @divFloor(ns_per_s, self.frequency);166 self.resolution = @divFloor(ns_per_s, self.frequency);
167167
168 var start_time: i64 = undefined;168 var start_time: i64 = undefined;
169 err = windows.QueryPerformanceCounter(&start_time);169 err = windows.QueryPerformanceCounter(&start_time);
170 debug.assert(err != windows.FALSE);170 debug.assert(err != windows.FALSE);
171 self.start_time = u64(start_time);171 self.start_time = @intCast(u64, start_time);
172 },172 },
173 Os.linux => {173 Os.linux => {
174 //On Linux, seccomp can do arbitrary things to our ability to call174 //On Linux, seccomp can do arbitrary things to our ability to call
...@@ -184,12 +184,12 @@ pub const Timer = struct {...@@ -184,12 +184,12 @@ pub const Timer = struct {
184 posix.EINVAL => return error.TimerUnsupported,184 posix.EINVAL => return error.TimerUnsupported,
185 else => return std.os.unexpectedErrorPosix(errno),185 else => return std.os.unexpectedErrorPosix(errno),
186 }186 }
187 self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);187 self.resolution = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);
188188
189 result = posix.clock_gettime(monotonic_clock_id, &ts);189 result = posix.clock_gettime(monotonic_clock_id, &ts);
190 errno = posix.getErrno(result);190 errno = posix.getErrno(result);
191 if (errno != 0) return std.os.unexpectedErrorPosix(errno);191 if (errno != 0) return std.os.unexpectedErrorPosix(errno);
192 self.start_time = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);192 self.start_time = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);
193 },193 },
194 Os.macosx, Os.ios => {194 Os.macosx, Os.ios => {
195 darwin.mach_timebase_info(&self.frequency);195 darwin.mach_timebase_info(&self.frequency);
...@@ -236,7 +236,7 @@ pub const Timer = struct {...@@ -236,7 +236,7 @@ pub const Timer = struct {
236 var result: i64 = undefined;236 var result: i64 = undefined;
237 var err = windows.QueryPerformanceCounter(&result);237 var err = windows.QueryPerformanceCounter(&result);
238 debug.assert(err != windows.FALSE);238 debug.assert(err != windows.FALSE);
239 return u64(result);239 return @intCast(u64, result);
240 }240 }
241241
242 fn clockDarwin() u64 {242 fn clockDarwin() u64 {
...@@ -247,7 +247,7 @@ pub const Timer = struct {...@@ -247,7 +247,7 @@ pub const Timer = struct {
247 var ts: posix.timespec = undefined;247 var ts: posix.timespec = undefined;
248 var result = posix.clock_gettime(monotonic_clock_id, &ts);248 var result = posix.clock_gettime(monotonic_clock_id, &ts);
249 debug.assert(posix.getErrno(result) == 0);249 debug.assert(posix.getErrno(result) == 0);
250 return u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);250 return @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec);
251 }251 }
252};252};
253253
std/os/windows/util.zig+7-2
...@@ -42,7 +42,7 @@ pub const WriteError = error{...@@ -42,7 +42,7 @@ pub const WriteError = error{
42};42};
4343
44pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) WriteError!void {44pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) WriteError!void {
45 if (windows.WriteFile(handle, @ptrCast(*const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {45 if (windows.WriteFile(handle, @ptrCast(*const c_void, bytes.ptr), @intCast(u32, bytes.len), null, null) == 0) {
46 const err = windows.GetLastError();46 const err = windows.GetLastError();
47 return switch (err) {47 return switch (err) {
48 windows.ERROR.INVALID_USER_BUFFER => WriteError.SystemResources,48 windows.ERROR.INVALID_USER_BUFFER => WriteError.SystemResources,
...@@ -68,7 +68,12 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {...@@ -68,7 +68,12 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {
68 const size = @sizeOf(windows.FILE_NAME_INFO);68 const size = @sizeOf(windows.FILE_NAME_INFO);
69 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);69 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
7070
71 if (windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo, @ptrCast(*c_void, &name_info_bytes[0]), u32(name_info_bytes.len)) == 0) {71 if (windows.GetFileInformationByHandleEx(
72 handle,
73 windows.FileNameInfo,
74 @ptrCast(*c_void, &name_info_bytes[0]),
75 @intCast(u32, name_info_bytes.len),
76 ) == 0) {
72 return true;77 return true;
73 }78 }
7479
std/rand/index.zig+8-8
...@@ -55,16 +55,16 @@ pub const Random = struct {...@@ -55,16 +55,16 @@ pub const Random = struct {
55 if (T.is_signed) {55 if (T.is_signed) {
56 const uint = @IntType(false, T.bit_count);56 const uint = @IntType(false, T.bit_count);
57 if (start >= 0 and end >= 0) {57 if (start >= 0 and end >= 0) {
58 return T(r.range(uint, uint(start), uint(end)));58 return @intCast(T, r.range(uint, @intCast(uint, start), @intCast(uint, end)));
59 } else if (start < 0 and end < 0) {59 } else if (start < 0 and end < 0) {
60 // Can't overflow because the range is over signed ints60 // Can't overflow because the range is over signed ints
61 return math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1) catch unreachable;61 return math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1) catch unreachable;
62 } else if (start < 0 and end >= 0) {62 } else if (start < 0 and end >= 0) {
63 const end_uint = uint(end);63 const end_uint = @intCast(uint, end);
64 const total_range = math.absCast(start) + end_uint;64 const total_range = math.absCast(start) + end_uint;
65 const value = r.range(uint, 0, total_range);65 const value = r.range(uint, 0, total_range);
66 const result = if (value < end_uint) x: {66 const result = if (value < end_uint) x: {
67 break :x T(value);67 break :x @intCast(T, value);
68 } else if (value == end_uint) x: {68 } else if (value == end_uint) x: {
69 break :x start;69 break :x start;
70 } else x: {70 } else x: {
...@@ -213,9 +213,9 @@ pub const Pcg = struct {...@@ -213,9 +213,9 @@ pub const Pcg = struct {
213 self.s = l *% default_multiplier +% (self.i | 1);213 self.s = l *% default_multiplier +% (self.i | 1);
214214
215 const xor_s = @truncate(u32, ((l >> 18) ^ l) >> 27);215 const xor_s = @truncate(u32, ((l >> 18) ^ l) >> 27);
216 const rot = u32(l >> 59);216 const rot = @intCast(u32, l >> 59);
217217
218 return (xor_s >> u5(rot)) | (xor_s << u5((0 -% rot) & 31));218 return (xor_s >> @intCast(u5, rot)) | (xor_s << @intCast(u5, (0 -% rot) & 31));
219 }219 }
220220
221 fn seed(self: *Pcg, init_s: u64) void {221 fn seed(self: *Pcg, init_s: u64) void {
...@@ -322,7 +322,7 @@ pub const Xoroshiro128 = struct {...@@ -322,7 +322,7 @@ pub const Xoroshiro128 = struct {
322 inline for (table) |entry| {322 inline for (table) |entry| {
323 var b: usize = 0;323 var b: usize = 0;
324 while (b < 64) : (b += 1) {324 while (b < 64) : (b += 1) {
325 if ((entry & (u64(1) << u6(b))) != 0) {325 if ((entry & (u64(1) << @intCast(u6, b))) != 0) {
326 s0 ^= self.s[0];326 s0 ^= self.s[0];
327 s1 ^= self.s[1];327 s1 ^= self.s[1];
328 }328 }
...@@ -667,13 +667,13 @@ test "Random range" {...@@ -667,13 +667,13 @@ test "Random range" {
667}667}
668668
669fn testRange(r: *Random, start: i32, end: i32) void {669fn testRange(r: *Random, start: i32, end: i32) void {
670 const count = usize(end - start);670 const count = @intCast(usize, end - start);
671 var values_buffer = []bool{false} ** 20;671 var values_buffer = []bool{false} ** 20;
672 const values = values_buffer[0..count];672 const values = values_buffer[0..count];
673 var i: usize = 0;673 var i: usize = 0;
674 while (i < count) {674 while (i < count) {
675 const value = r.range(i32, start, end);675 const value = r.range(i32, start, end);
676 const index = usize(value - start);676 const index = @intCast(usize, value - start);
677 if (!values[index]) {677 if (!values[index]) {
678 i += 1;678 i += 1;
679 values[index] = true;679 values[index] = true;
std/segmented_list.zig+6-6
...@@ -104,7 +104,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -104,7 +104,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
104 }104 }
105105
106 pub fn deinit(self: *Self) void {106 pub fn deinit(self: *Self) void {
107 self.freeShelves(ShelfIndex(self.dynamic_segments.len), 0);107 self.freeShelves(@intCast(ShelfIndex, self.dynamic_segments.len), 0);
108 self.allocator.free(self.dynamic_segments);108 self.allocator.free(self.dynamic_segments);
109 self.* = undefined;109 self.* = undefined;
110 }110 }
...@@ -158,7 +158,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -158,7 +158,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
158 /// Only grows capacity, or retains current capacity158 /// Only grows capacity, or retains current capacity
159 pub fn growCapacity(self: *Self, new_capacity: usize) !void {159 pub fn growCapacity(self: *Self, new_capacity: usize) !void {
160 const new_cap_shelf_count = shelfCount(new_capacity);160 const new_cap_shelf_count = shelfCount(new_capacity);
161 const old_shelf_count = ShelfIndex(self.dynamic_segments.len);161 const old_shelf_count = @intCast(ShelfIndex, self.dynamic_segments.len);
162 if (new_cap_shelf_count > old_shelf_count) {162 if (new_cap_shelf_count > old_shelf_count) {
163 self.dynamic_segments = try self.allocator.realloc([*]T, self.dynamic_segments, new_cap_shelf_count);163 self.dynamic_segments = try self.allocator.realloc([*]T, self.dynamic_segments, new_cap_shelf_count);
164 var i = old_shelf_count;164 var i = old_shelf_count;
...@@ -175,7 +175,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -175,7 +175,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
175 /// Only shrinks capacity or retains current capacity175 /// Only shrinks capacity or retains current capacity
176 pub fn shrinkCapacity(self: *Self, new_capacity: usize) void {176 pub fn shrinkCapacity(self: *Self, new_capacity: usize) void {
177 if (new_capacity <= prealloc_item_count) {177 if (new_capacity <= prealloc_item_count) {
178 const len = ShelfIndex(self.dynamic_segments.len);178 const len = @intCast(ShelfIndex, self.dynamic_segments.len);
179 self.freeShelves(len, 0);179 self.freeShelves(len, 0);
180 self.allocator.free(self.dynamic_segments);180 self.allocator.free(self.dynamic_segments);
181 self.dynamic_segments = [][*]T{};181 self.dynamic_segments = [][*]T{};
...@@ -183,7 +183,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -183,7 +183,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
183 }183 }
184184
185 const new_cap_shelf_count = shelfCount(new_capacity);185 const new_cap_shelf_count = shelfCount(new_capacity);
186 const old_shelf_count = ShelfIndex(self.dynamic_segments.len);186 const old_shelf_count = @intCast(ShelfIndex, self.dynamic_segments.len);
187 assert(new_cap_shelf_count <= old_shelf_count);187 assert(new_cap_shelf_count <= old_shelf_count);
188 if (new_cap_shelf_count == old_shelf_count) {188 if (new_cap_shelf_count == old_shelf_count) {
189 return;189 return;
...@@ -338,7 +338,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {...@@ -338,7 +338,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
338 {338 {
339 var i: usize = 0;339 var i: usize = 0;
340 while (i < 100) : (i += 1) {340 while (i < 100) : (i += 1) {
341 try list.push(i32(i + 1));341 try list.push(@intCast(i32, i + 1));
342 assert(list.len == i + 1);342 assert(list.len == i + 1);
343 }343 }
344 }344 }
...@@ -346,7 +346,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {...@@ -346,7 +346,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
346 {346 {
347 var i: usize = 0;347 var i: usize = 0;
348 while (i < 100) : (i += 1) {348 while (i < 100) : (i += 1) {
349 assert(list.at(i).* == i32(i + 1));349 assert(list.at(i).* == @intCast(i32, i + 1));
350 }350 }
351 }351 }
352352
std/special/bootstrap.zig+1-1
...@@ -80,7 +80,7 @@ extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 {...@@ -80,7 +80,7 @@ extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 {
80 var env_count: usize = 0;80 var env_count: usize = 0;
81 while (c_envp[env_count] != null) : (env_count += 1) {}81 while (c_envp[env_count] != null) : (env_count += 1) {}
82 const envp = @ptrCast([*][*]u8, c_envp)[0..env_count];82 const envp = @ptrCast([*][*]u8, c_envp)[0..env_count];
83 return callMainWithArgs(usize(c_argc), c_argv, envp);83 return callMainWithArgs(@intCast(usize, c_argc), c_argv, envp);
84}84}
8585
86fn callMain() u8 {86fn callMain() u8 {
std/special/builtin.zig+15-15
...@@ -135,9 +135,9 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -135,9 +135,9 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
135 const mask = if (T == f32) 0xff else 0x7ff;135 const mask = if (T == f32) 0xff else 0x7ff;
136 var ux = @bitCast(uint, x);136 var ux = @bitCast(uint, x);
137 var uy = @bitCast(uint, y);137 var uy = @bitCast(uint, y);
138 var ex = i32((ux >> digits) & mask);138 var ex = @intCast(i32, (ux >> digits) & mask);
139 var ey = i32((uy >> digits) & mask);139 var ey = @intCast(i32, (uy >> digits) & mask);
140 const sx = if (T == f32) u32(ux & 0x80000000) else i32(ux >> bits_minus_1);140 const sx = if (T == f32) @intCast(u32, ux & 0x80000000) else @intCast(i32, ux >> bits_minus_1);
141 var i: uint = undefined;141 var i: uint = undefined;
142142
143 if (uy << 1 == 0 or isNan(uint, uy) or ex == mask)143 if (uy << 1 == 0 or isNan(uint, uy) or ex == mask)
...@@ -156,7 +156,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -156,7 +156,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
156 ex -= 1;156 ex -= 1;
157 i <<= 1;157 i <<= 1;
158 }) {}158 }) {}
159 ux <<= log2uint(@bitCast(u32, -ex + 1));159 ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1));
160 } else {160 } else {
161 ux &= @maxValue(uint) >> exp_bits;161 ux &= @maxValue(uint) >> exp_bits;
162 ux |= 1 << digits;162 ux |= 1 << digits;
...@@ -167,7 +167,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -167,7 +167,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
167 ey -= 1;167 ey -= 1;
168 i <<= 1;168 i <<= 1;
169 }) {}169 }) {}
170 uy <<= log2uint(@bitCast(u32, -ey + 1));170 uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1));
171 } else {171 } else {
172 uy &= @maxValue(uint) >> exp_bits;172 uy &= @maxValue(uint) >> exp_bits;
173 uy |= 1 << digits;173 uy |= 1 << digits;
...@@ -199,12 +199,12 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {...@@ -199,12 +199,12 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
199 ux -%= 1 << digits;199 ux -%= 1 << digits;
200 ux |= uint(@bitCast(u32, ex)) << digits;200 ux |= uint(@bitCast(u32, ex)) << digits;
201 } else {201 } else {
202 ux >>= log2uint(@bitCast(u32, -ex + 1));202 ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));
203 }203 }
204 if (T == f32) {204 if (T == f32) {
205 ux |= sx;205 ux |= sx;
206 } else {206 } else {
207 ux |= uint(sx) << bits_minus_1;207 ux |= @intCast(uint, sx) << bits_minus_1;
208 }208 }
209 return @bitCast(T, ux);209 return @bitCast(T, ux);
210}210}
...@@ -227,8 +227,8 @@ export fn sqrt(x: f64) f64 {...@@ -227,8 +227,8 @@ export fn sqrt(x: f64) f64 {
227 const sign: u32 = 0x80000000;227 const sign: u32 = 0x80000000;
228 const u = @bitCast(u64, x);228 const u = @bitCast(u64, x);
229229
230 var ix0 = u32(u >> 32);230 var ix0 = @intCast(u32, u >> 32);
231 var ix1 = u32(u & 0xFFFFFFFF);231 var ix1 = @intCast(u32, u & 0xFFFFFFFF);
232232
233 // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan233 // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = nan
234 if (ix0 & 0x7FF00000 == 0x7FF00000) {234 if (ix0 & 0x7FF00000 == 0x7FF00000) {
...@@ -245,7 +245,7 @@ export fn sqrt(x: f64) f64 {...@@ -245,7 +245,7 @@ export fn sqrt(x: f64) f64 {
245 }245 }
246246
247 // normalize x247 // normalize x
248 var m = i32(ix0 >> 20);248 var m = @intCast(i32, ix0 >> 20);
249 if (m == 0) {249 if (m == 0) {
250 // subnormal250 // subnormal
251 while (ix0 == 0) {251 while (ix0 == 0) {
...@@ -259,9 +259,9 @@ export fn sqrt(x: f64) f64 {...@@ -259,9 +259,9 @@ export fn sqrt(x: f64) f64 {
259 while (ix0 & 0x00100000 == 0) : (i += 1) {259 while (ix0 & 0x00100000 == 0) : (i += 1) {
260 ix0 <<= 1;260 ix0 <<= 1;
261 }261 }
262 m -= i32(i) - 1;262 m -= @intCast(i32, i) - 1;
263 ix0 |= ix1 >> u5(32 - i);263 ix0 |= ix1 >> @intCast(u5, 32 - i);
264 ix1 <<= u5(i);264 ix1 <<= @intCast(u5, i);
265 }265 }
266266
267 // unbias exponent267 // unbias exponent
...@@ -345,10 +345,10 @@ export fn sqrt(x: f64) f64 {...@@ -345,10 +345,10 @@ export fn sqrt(x: f64) f64 {
345345
346 // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same346 // NOTE: musl here appears to rely on signed twos-complement wraparound. +% has the same
347 // behaviour at least.347 // behaviour at least.
348 var iix0 = i32(ix0);348 var iix0 = @intCast(i32, ix0);
349 iix0 = iix0 +% (m << 20);349 iix0 = iix0 +% (m << 20);
350350
351 const uz = (u64(iix0) << 32) | ix1;351 const uz = (@intCast(u64, iix0) << 32) | ix1;
352 return @bitCast(f64, uz);352 return @bitCast(f64, uz);
353}353}
354354
std/special/compiler_rt/divti3.zig+1-1
...@@ -13,7 +13,7 @@ pub extern fn __divti3(a: i128, b: i128) i128 {...@@ -13,7 +13,7 @@ pub extern fn __divti3(a: i128, b: i128) i128 {
1313
14 const r = udivmod(u128, @bitCast(u128, an), @bitCast(u128, bn), null);14 const r = udivmod(u128, @bitCast(u128, an), @bitCast(u128, bn), null);
15 const s = s_a ^ s_b;15 const s = s_a ^ s_b;
16 return (i128(r) ^ s) -% s;16 return (@bitCast(i128, r) ^ s) -% s;
17}17}
1818
19pub extern fn __divti3_windows_x86_64(a: *const i128, b: *const i128) void {19pub extern fn __divti3_windows_x86_64(a: *const i128, b: *const i128) void {
std/special/compiler_rt/fixuint.zig+4-4
...@@ -32,14 +32,14 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t...@@ -32,14 +32,14 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
32 const aAbs: rep_t = aRep & absMask;32 const aAbs: rep_t = aRep & absMask;
3333
34 const sign = if ((aRep & signBit) != 0) i32(-1) else i32(1);34 const sign = if ((aRep & signBit) != 0) i32(-1) else i32(1);
35 const exponent = i32(aAbs >> significandBits) - exponentBias;35 const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias;
36 const significand: rep_t = (aAbs & significandMask) | implicitBit;36 const significand: rep_t = (aAbs & significandMask) | implicitBit;
3737
38 // If either the value or the exponent is negative, the result is zero.38 // If either the value or the exponent is negative, the result is zero.
39 if (sign == -1 or exponent < 0) return 0;39 if (sign == -1 or exponent < 0) return 0;
4040
41 // If the value is too large for the integer type, saturate.41 // If the value is too large for the integer type, saturate.
42 if (c_uint(exponent) >= fixuint_t.bit_count) return ~fixuint_t(0);42 if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~fixuint_t(0);
4343
44 // If 0 <= exponent < significandBits, right shift to get the result.44 // If 0 <= exponent < significandBits, right shift to get the result.
45 // Otherwise, shift left.45 // Otherwise, shift left.
...@@ -47,11 +47,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t...@@ -47,11 +47,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
47 // TODO this is a workaround for the mysterious "integer cast truncated bits"47 // TODO this is a workaround for the mysterious "integer cast truncated bits"
48 // happening on the next line48 // happening on the next line
49 @setRuntimeSafety(false);49 @setRuntimeSafety(false);
50 return fixuint_t(significand >> Log2Int(rep_t)(significandBits - exponent));50 return @intCast(fixuint_t, significand >> @intCast(Log2Int(rep_t), significandBits - exponent));
51 } else {51 } else {
52 // TODO this is a workaround for the mysterious "integer cast truncated bits"52 // TODO this is a workaround for the mysterious "integer cast truncated bits"
53 // happening on the next line53 // happening on the next line
54 @setRuntimeSafety(false);54 @setRuntimeSafety(false);
55 return fixuint_t(significand) << Log2Int(fixuint_t)(exponent - significandBits);55 return @intCast(fixuint_t, significand) << @intCast(Log2Int(fixuint_t), exponent - significandBits);
56 }56 }
57}57}
std/special/compiler_rt/index.zig+6-6
...@@ -292,7 +292,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: *u32) u32 {...@@ -292,7 +292,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: *u32) u32 {
292 @setRuntimeSafety(is_test);292 @setRuntimeSafety(is_test);
293293
294 const d = __udivsi3(a, b);294 const d = __udivsi3(a, b);
295 rem.* = u32(i32(a) -% (i32(d) * i32(b)));295 rem.* = @bitCast(u32, @bitCast(i32, a) -% (@bitCast(i32, d) * @bitCast(i32, b)));
296 return d;296 return d;
297}297}
298298
...@@ -316,12 +316,12 @@ extern fn __udivsi3(n: u32, d: u32) u32 {...@@ -316,12 +316,12 @@ extern fn __udivsi3(n: u32, d: u32) u32 {
316 sr += 1;316 sr += 1;
317 // 1 <= sr <= n_uword_bits - 1317 // 1 <= sr <= n_uword_bits - 1
318 // Not a special case318 // Not a special case
319 var q: u32 = n << u5(n_uword_bits - sr);319 var q: u32 = n << @intCast(u5, n_uword_bits - sr);
320 var r: u32 = n >> u5(sr);320 var r: u32 = n >> @intCast(u5, sr);
321 var carry: u32 = 0;321 var carry: u32 = 0;
322 while (sr > 0) : (sr -= 1) {322 while (sr > 0) : (sr -= 1) {
323 // r:q = ((r:q) << 1) | carry323 // r:q = ((r:q) << 1) | carry
324 r = (r << 1) | (q >> u5(n_uword_bits - 1));324 r = (r << 1) | (q >> @intCast(u5, n_uword_bits - 1));
325 q = (q << 1) | carry;325 q = (q << 1) | carry;
326 // carry = 0;326 // carry = 0;
327 // if (r.all >= d.all)327 // if (r.all >= d.all)
...@@ -329,8 +329,8 @@ extern fn __udivsi3(n: u32, d: u32) u32 {...@@ -329,8 +329,8 @@ extern fn __udivsi3(n: u32, d: u32) u32 {
329 // r.all -= d.all;329 // r.all -= d.all;
330 // carry = 1;330 // carry = 1;
331 // }331 // }
332 const s = i32(d -% r -% 1) >> u5(n_uword_bits - 1);332 const s = @intCast(i32, d -% r -% 1) >> @intCast(u5, n_uword_bits - 1);
333 carry = u32(s & 1);333 carry = @intCast(u32, s & 1);
334 r -= d & @bitCast(u32, s);334 r -= d & @bitCast(u32, s);
335 }335 }
336 q = (q << 1) | carry;336 q = (q << 1) | carry;
std/special/compiler_rt/udivmod.zig+17-17
...@@ -71,7 +71,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -71,7 +71,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
71 r[high] = n[high] & (d[high] - 1);71 r[high] = n[high] & (d[high] - 1);
72 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #42172 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
73 }73 }
74 return n[high] >> Log2SingleInt(@ctz(d[high]));74 return n[high] >> @intCast(Log2SingleInt, @ctz(d[high]));
75 }75 }
76 // K K76 // K K
77 // ---77 // ---
...@@ -88,10 +88,10 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -88,10 +88,10 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
88 // 1 <= sr <= SingleInt.bit_count - 188 // 1 <= sr <= SingleInt.bit_count - 1
89 // q.all = a << (DoubleInt.bit_count - sr);89 // q.all = a << (DoubleInt.bit_count - sr);
90 q[low] = 0;90 q[low] = 0;
91 q[high] = n[low] << Log2SingleInt(SingleInt.bit_count - sr);91 q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
92 // r.all = a >> sr;92 // r.all = a >> sr;
93 r[high] = n[high] >> Log2SingleInt(sr);93 r[high] = n[high] >> @intCast(Log2SingleInt, sr);
94 r[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));94 r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
95 } else {95 } else {
96 // d[low] != 096 // d[low] != 0
97 if (d[high] == 0) {97 if (d[high] == 0) {
...@@ -107,8 +107,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -107,8 +107,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
107 return a;107 return a;
108 }108 }
109 sr = @ctz(d[low]);109 sr = @ctz(d[low]);
110 q[high] = n[high] >> Log2SingleInt(sr);110 q[high] = n[high] >> @intCast(Log2SingleInt, sr);
111 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));111 q[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
112 return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421112 return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
113 }113 }
114 // K X114 // K X
...@@ -126,15 +126,15 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -126,15 +126,15 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
126 } else if (sr < SingleInt.bit_count) {126 } else if (sr < SingleInt.bit_count) {
127 // 2 <= sr <= SingleInt.bit_count - 1127 // 2 <= sr <= SingleInt.bit_count - 1
128 q[low] = 0;128 q[low] = 0;
129 q[high] = n[low] << Log2SingleInt(SingleInt.bit_count - sr);129 q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
130 r[high] = n[high] >> Log2SingleInt(sr);130 r[high] = n[high] >> @intCast(Log2SingleInt, sr);
131 r[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));131 r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
132 } else {132 } else {
133 // SingleInt.bit_count + 1 <= sr <= DoubleInt.bit_count - 1133 // SingleInt.bit_count + 1 <= sr <= DoubleInt.bit_count - 1
134 q[low] = n[low] << Log2SingleInt(DoubleInt.bit_count - sr);134 q[low] = n[low] << @intCast(Log2SingleInt, DoubleInt.bit_count - sr);
135 q[high] = (n[high] << Log2SingleInt(DoubleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr - SingleInt.bit_count));135 q[high] = (n[high] << @intCast(Log2SingleInt, DoubleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr - SingleInt.bit_count));
136 r[high] = 0;136 r[high] = 0;
137 r[low] = n[high] >> Log2SingleInt(sr - SingleInt.bit_count);137 r[low] = n[high] >> @intCast(Log2SingleInt, sr - SingleInt.bit_count);
138 }138 }
139 } else {139 } else {
140 // K X140 // K X
...@@ -158,9 +158,9 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -158,9 +158,9 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
158 r[high] = 0;158 r[high] = 0;
159 r[low] = n[high];159 r[low] = n[high];
160 } else {160 } else {
161 r[high] = n[high] >> Log2SingleInt(sr);161 r[high] = n[high] >> @intCast(Log2SingleInt, sr);
162 r[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));162 r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
163 q[high] = n[low] << Log2SingleInt(SingleInt.bit_count - sr);163 q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
164 }164 }
165 }165 }
166 }166 }
...@@ -184,8 +184,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -184,8 +184,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
184 // carry = 1;184 // carry = 1;
185 // }185 // }
186 r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421186 r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
187 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);187 const s: SignedDoubleInt = @intCast(SignedDoubleInt, b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
188 carry = u32(s & 1);188 carry = @intCast(u32, s & 1);
189 r_all -= b & @bitCast(DoubleInt, s);189 r_all -= b & @bitCast(DoubleInt, s);
190 r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421190 r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421
191 }191 }
std/unicode.zig+10-10
...@@ -35,22 +35,22 @@ pub fn utf8Encode(c: u32, out: []u8) !u3 {...@@ -35,22 +35,22 @@ pub fn utf8Encode(c: u32, out: []u8) !u3 {
35 // - Increasing the initial shift by 6 each time35 // - Increasing the initial shift by 6 each time
36 // - Each time after the first shorten the shifted36 // - Each time after the first shorten the shifted
37 // value to a max of 0b111111 (63)37 // value to a max of 0b111111 (63)
38 1 => out[0] = u8(c), // Can just do 0 + codepoint for initial range38 1 => out[0] = @intCast(u8, c), // Can just do 0 + codepoint for initial range
39 2 => {39 2 => {
40 out[0] = u8(0b11000000 | (c >> 6));40 out[0] = @intCast(u8, 0b11000000 | (c >> 6));
41 out[1] = u8(0b10000000 | (c & 0b111111));41 out[1] = @intCast(u8, 0b10000000 | (c & 0b111111));
42 },42 },
43 3 => {43 3 => {
44 if (0xd800 <= c and c <= 0xdfff) return error.Utf8CannotEncodeSurrogateHalf;44 if (0xd800 <= c and c <= 0xdfff) return error.Utf8CannotEncodeSurrogateHalf;
45 out[0] = u8(0b11100000 | (c >> 12));45 out[0] = @intCast(u8, 0b11100000 | (c >> 12));
46 out[1] = u8(0b10000000 | ((c >> 6) & 0b111111));46 out[1] = @intCast(u8, 0b10000000 | ((c >> 6) & 0b111111));
47 out[2] = u8(0b10000000 | (c & 0b111111));47 out[2] = @intCast(u8, 0b10000000 | (c & 0b111111));
48 },48 },
49 4 => {49 4 => {
50 out[0] = u8(0b11110000 | (c >> 18));50 out[0] = @intCast(u8, 0b11110000 | (c >> 18));
51 out[1] = u8(0b10000000 | ((c >> 12) & 0b111111));51 out[1] = @intCast(u8, 0b10000000 | ((c >> 12) & 0b111111));
52 out[2] = u8(0b10000000 | ((c >> 6) & 0b111111));52 out[2] = @intCast(u8, 0b10000000 | ((c >> 6) & 0b111111));
53 out[3] = u8(0b10000000 | (c & 0b111111));53 out[3] = @intCast(u8, 0b10000000 | (c & 0b111111));
54 },54 },
55 else => unreachable,55 else => unreachable,
56 }56 }
std/zig/tokenizer.zig+1-1
...@@ -1128,7 +1128,7 @@ pub const Tokenizer = struct {...@@ -1128,7 +1128,7 @@ pub const Tokenizer = struct {
1128 // check utf8-encoded character.1128 // check utf8-encoded character.
1129 const length = std.unicode.utf8ByteSequenceLength(c0) catch return 1;1129 const length = std.unicode.utf8ByteSequenceLength(c0) catch return 1;
1130 if (self.index + length > self.buffer.len) {1130 if (self.index + length > self.buffer.len) {
1131 return u3(self.buffer.len - self.index);1131 return @intCast(u3, self.buffer.len - self.index);
1132 }1132 }
1133 const bytes = self.buffer[self.index .. self.index + length];1133 const bytes = self.buffer[self.index .. self.index + length];
1134 switch (length) {1134 switch (length) {
test/cases/cast.zig+17-1
...@@ -343,7 +343,7 @@ fn testPeerErrorAndArray2(x: u8) error![]const u8 {...@@ -343,7 +343,7 @@ fn testPeerErrorAndArray2(x: u8) error![]const u8 {
343test "explicit cast float number literal to integer if no fraction component" {343test "explicit cast float number literal to integer if no fraction component" {
344 const x = i32(1e4);344 const x = i32(1e4);
345 assert(x == 10000);345 assert(x == 10000);
346 const y = i32(f32(1e4));346 const y = @floatToInt(i32, f32(1e4));
347 assert(y == 10000);347 assert(y == 10000);
348}348}
349349
...@@ -398,3 +398,19 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {...@@ -398,3 +398,19 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
398 const x: [*]const ?[*]const u8 = &window_name;398 const x: [*]const ?[*]const u8 = &window_name;
399 assert(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name"));399 assert(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name"));
400}400}
401
402test "@intCast comptime_int" {
403 const result = @intCast(i32, 1234);
404 assert(@typeOf(result) == i32);
405 assert(result == 1234);
406}
407
408test "@floatCast comptime_int and comptime_float" {
409 const result = @floatCast(f32, 1234);
410 assert(@typeOf(result) == f32);
411 assert(result == 1234.0);
412
413 const result2 = @floatCast(f32, 1234.0);
414 assert(@typeOf(result) == f32);
415 assert(result == 1234.0);
416}
test/cases/enum.zig+1-1
...@@ -99,7 +99,7 @@ test "int to enum" {...@@ -99,7 +99,7 @@ test "int to enum" {
99 testIntToEnumEval(3);99 testIntToEnumEval(3);
100}100}
101fn testIntToEnumEval(x: i32) void {101fn testIntToEnumEval(x: i32) void {
102 assert(IntToEnumNumber(u3(x)) == IntToEnumNumber.Three);102 assert(IntToEnumNumber(@intCast(u3, x)) == IntToEnumNumber.Three);
103}103}
104const IntToEnumNumber = enum {104const IntToEnumNumber = enum {
105 Zero,105 Zero,
test/cases/eval.zig+4-4
...@@ -5,7 +5,7 @@ const builtin = @import("builtin");...@@ -5,7 +5,7 @@ const builtin = @import("builtin");
5test "compile time recursion" {5test "compile time recursion" {
6 assert(some_data.len == 21);6 assert(some_data.len == 21);
7}7}
8var some_data: [usize(fibonacci(7))]u8 = undefined;8var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;
9fn fibonacci(x: i32) i32 {9fn fibonacci(x: i32) i32 {
10 if (x <= 1) return 1;10 if (x <= 1) return 1;
11 return fibonacci(x - 1) + fibonacci(x - 2);11 return fibonacci(x - 1) + fibonacci(x - 2);
...@@ -356,7 +356,7 @@ const global_array = x: {...@@ -356,7 +356,7 @@ const global_array = x: {
356test "compile-time downcast when the bits fit" {356test "compile-time downcast when the bits fit" {
357 comptime {357 comptime {
358 const spartan_count: u16 = 255;358 const spartan_count: u16 = 255;
359 const byte = u8(spartan_count);359 const byte = @intCast(u8, spartan_count);
360 assert(byte == 255);360 assert(byte == 255);
361 }361 }
362}362}
...@@ -440,7 +440,7 @@ test "binary math operator in partially inlined function" {...@@ -440,7 +440,7 @@ test "binary math operator in partially inlined function" {
440 var b: [16]u8 = undefined;440 var b: [16]u8 = undefined;
441441
442 for (b) |*r, i|442 for (b) |*r, i|
443 r.* = u8(i + 1);443 r.* = @intCast(u8, i + 1);
444444
445 copyWithPartialInline(s[0..], b[0..]);445 copyWithPartialInline(s[0..], b[0..]);
446 assert(s[0] == 0x1020304);446 assert(s[0] == 0x1020304);
...@@ -480,7 +480,7 @@ fn generateTable(comptime T: type) [1010]T {...@@ -480,7 +480,7 @@ fn generateTable(comptime T: type) [1010]T {
480 var res: [1010]T = undefined;480 var res: [1010]T = undefined;
481 var i: usize = 0;481 var i: usize = 0;
482 while (i < 1010) : (i += 1) {482 while (i < 1010) : (i += 1) {
483 res[i] = T(i);483 res[i] = @intCast(T, i);
484 }484 }
485 return res;485 return res;
486}486}
test/cases/fn.zig+1-1
...@@ -80,7 +80,7 @@ test "function pointers" {...@@ -80,7 +80,7 @@ test "function pointers" {
80 fn4,80 fn4,
81 };81 };
82 for (fns) |f, i| {82 for (fns) |f, i| {
83 assert(f() == u32(i) + 5);83 assert(f() == @intCast(u32, i) + 5);
84 }84 }
85}85}
86fn fn1() u32 {86fn fn1() u32 {
test/cases/for.zig+2-2
...@@ -46,7 +46,7 @@ test "basic for loop" {...@@ -46,7 +46,7 @@ test "basic for loop" {
46 buf_index += 1;46 buf_index += 1;
47 }47 }
48 for (array) |item, index| {48 for (array) |item, index| {
49 buffer[buf_index] = u8(index);49 buffer[buf_index] = @intCast(u8, index);
50 buf_index += 1;50 buf_index += 1;
51 }51 }
52 const unknown_size: []const u8 = array;52 const unknown_size: []const u8 = array;
...@@ -55,7 +55,7 @@ test "basic for loop" {...@@ -55,7 +55,7 @@ test "basic for loop" {
55 buf_index += 1;55 buf_index += 1;
56 }56 }
57 for (unknown_size) |item, index| {57 for (unknown_size) |item, index| {
58 buffer[buf_index] = u8(index);58 buffer[buf_index] = @intCast(u8, index);
59 buf_index += 1;59 buf_index += 1;
60 }60 }
6161
test/cases/struct.zig+4-4
...@@ -365,14 +365,14 @@ test "runtime struct initialization of bitfield" {...@@ -365,14 +365,14 @@ test "runtime struct initialization of bitfield" {
365 .y = x1,365 .y = x1,
366 };366 };
367 const s2 = Nibbles{367 const s2 = Nibbles{
368 .x = u4(x2),368 .x = @intCast(u4, x2),
369 .y = u4(x2),369 .y = @intCast(u4, x2),
370 };370 };
371371
372 assert(s1.x == x1);372 assert(s1.x == x1);
373 assert(s1.y == x1);373 assert(s1.y == x1);
374 assert(s2.x == u4(x2));374 assert(s2.x == @intCast(u4, x2));
375 assert(s2.y == u4(x2));375 assert(s2.y == @intCast(u4, x2));
376}376}
377377
378var x1 = u4(1);378var x1 = u4(1);