| author | |
| committer | |
| log | 2b395d4ede2d8ef356c54e1c7c09da88c634be11 |
| tree | ddb9806afc26bc55554e20066b29d076bec71f79 |
| parent | 40b7652a6da135aed68a0067f2de60b8b276713c |
| signature | Commit is signed but in an unrecognized format. |
closes #1466
closes #147655 files changed, 310 insertions(+), 398 deletions(-)
doc/langref.html.in+18-30| ... | @@ -827,7 +827,7 @@ a +%= b{#endsyntax#}</pre></td> | ... | @@ -827,7 +827,7 @@ a +%= b{#endsyntax#}</pre></td> |
| 827 | </ul> | 827 | </ul> |
| 828 | </td> | 828 | </td> |
| 829 | <td> | 829 | <td> |
| 830 | <pre>{#syntax#}u32(@maxValue(u32)) +% 1 == 0{#endsyntax#}</pre> | 830 | <pre>{#syntax#}u32(std.math.maxInt(u32)) +% 1 == 0{#endsyntax#}</pre> |
| 831 | </td> | 831 | </td> |
| 832 | </tr> | 832 | </tr> |
| 833 | <tr> | 833 | <tr> |
| ... | @@ -866,7 +866,7 @@ a -%= b{#endsyntax#}</pre></td> | ... | @@ -866,7 +866,7 @@ a -%= b{#endsyntax#}</pre></td> |
| 866 | </ul> | 866 | </ul> |
| 867 | </td> | 867 | </td> |
| 868 | <td> | 868 | <td> |
| 869 | <pre>{#syntax#}u32(0) -% 1 == @maxValue(u32){#endsyntax#}</pre> | 869 | <pre>{#syntax#}u32(0) -% 1 == std.math.maxInt(u32){#endsyntax#}</pre> |
| 870 | </td> | 870 | </td> |
| 871 | </tr> | 871 | </tr> |
| 872 | <tr> | 872 | <tr> |
| ... | @@ -901,7 +901,7 @@ a -%= b{#endsyntax#}</pre></td> | ... | @@ -901,7 +901,7 @@ a -%= b{#endsyntax#}</pre></td> |
| 901 | </ul> | 901 | </ul> |
| 902 | </td> | 902 | </td> |
| 903 | <td> | 903 | <td> |
| 904 | <pre>{#syntax#}-%i32(@minValue(i32)) == @minValue(i32){#endsyntax#}</pre> | 904 | <pre>{#syntax#}-%i32(std.math.minInt(i32)) == std.math.minInt(i32){#endsyntax#}</pre> |
| 905 | </td> | 905 | </td> |
| 906 | </tr> | 906 | </tr> |
| 907 | <tr> | 907 | <tr> |
| ... | @@ -3298,6 +3298,9 @@ const err = (error.{FileNotFound}).FileNotFound; | ... | @@ -3298,6 +3298,9 @@ const err = (error.{FileNotFound}).FileNotFound; |
| 3298 | Here is a function to parse a string into a 64-bit integer: | 3298 | Here is a function to parse a string into a 64-bit integer: |
| 3299 | </p> | 3299 | </p> |
| 3300 | {#code_begin|test#} | 3300 | {#code_begin|test#} |
| 3301 | const std = @import("std"); | ||
| 3302 | const maxInt = std.math.maxInt; | ||
| 3303 | |||
| 3301 | pub fn parseU64(buf: []const u8, radix: u8) !u64 { | 3304 | pub fn parseU64(buf: []const u8, radix: u8) !u64 { |
| 3302 | var x: u64 = 0; | 3305 | var x: u64 = 0; |
| 3303 | 3306 | ||
| ... | @@ -3327,13 +3330,13 @@ fn charToDigit(c: u8) u8 { | ... | @@ -3327,13 +3330,13 @@ fn charToDigit(c: u8) u8 { |
| 3327 | '0' ... '9' => c - '0', | 3330 | '0' ... '9' => c - '0', |
| 3328 | 'A' ... 'Z' => c - 'A' + 10, | 3331 | 'A' ... 'Z' => c - 'A' + 10, |
| 3329 | 'a' ... 'z' => c - 'a' + 10, | 3332 | 'a' ... 'z' => c - 'a' + 10, |
| 3330 | else => @maxValue(u8), | 3333 | else => maxInt(u8), |
| 3331 | }; | 3334 | }; |
| 3332 | } | 3335 | } |
| 3333 | 3336 | ||
| 3334 | test "parse u64" { | 3337 | test "parse u64" { |
| 3335 | const result = try parseU64("1234", 10); | 3338 | const result = try parseU64("1234", 10); |
| 3336 | @import("std").debug.assert(result == 1234); | 3339 | std.debug.assert(result == 1234); |
| 3337 | } | 3340 | } |
| 3338 | {#code_end#} | 3341 | {#code_end#} |
| 3339 | <p> | 3342 | <p> |
| ... | @@ -5539,7 +5542,7 @@ test "main" { | ... | @@ -5539,7 +5542,7 @@ test "main" { |
| 5539 | <p> | 5542 | <p> |
| 5540 | Floored division. Rounds toward negative infinity. For unsigned integers it is | 5543 | Floored division. Rounds toward negative infinity. For unsigned integers it is |
| 5541 | the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and | 5544 | the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and |
| 5542 | {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1){#endsyntax#}. | 5545 | {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}. |
| 5543 | </p> | 5546 | </p> |
| 5544 | <ul> | 5547 | <ul> |
| 5545 | <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li> | 5548 | <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li> |
| ... | @@ -5553,7 +5556,7 @@ test "main" { | ... | @@ -5553,7 +5556,7 @@ test "main" { |
| 5553 | <p> | 5556 | <p> |
| 5554 | Truncated division. Rounds toward zero. For unsigned integers it is | 5557 | Truncated division. Rounds toward zero. For unsigned integers it is |
| 5555 | the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and | 5558 | the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and |
| 5556 | {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1){#endsyntax#}. | 5559 | {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}. |
| 5557 | </p> | 5560 | </p> |
| 5558 | <ul> | 5561 | <ul> |
| 5559 | <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li> | 5562 | <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li> |
| ... | @@ -5816,15 +5819,6 @@ fn add(a: i32, b: i32) i32 { return a + b; } | ... | @@ -5816,15 +5819,6 @@ fn add(a: i32, b: i32) i32 { return a + b; } |
| 5816 | This function returns an integer type with the given signness and bit count. | 5819 | This function returns an integer type with the given signness and bit count. |
| 5817 | </p> | 5820 | </p> |
| 5818 | {#header_close#} | 5821 | {#header_close#} |
| 5819 | {#header_open|@maxValue#} | ||
| 5820 | <pre>{#syntax#}@maxValue(comptime T: type) comptime_int{#endsyntax#}</pre> | ||
| 5821 | <p> | ||
| 5822 | This function returns the maximum value of the integer type {#syntax#}T{#endsyntax#}. | ||
| 5823 | </p> | ||
| 5824 | <p> | ||
| 5825 | The result is a compile time constant. | ||
| 5826 | </p> | ||
| 5827 | {#header_close#} | ||
| 5828 | {#header_open|@memberCount#} | 5822 | {#header_open|@memberCount#} |
| 5829 | <pre>{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}</pre> | 5823 | <pre>{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}</pre> |
| 5830 | <p> | 5824 | <p> |
| ... | @@ -5885,15 +5879,6 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);{#endsyntax#}</pre> | ... | @@ -5885,15 +5879,6 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);{#endsyntax#}</pre> |
| 5885 | <p>There is also a standard library function for this:</p> | 5879 | <p>There is also a standard library function for this:</p> |
| 5886 | <pre>{#syntax#}const mem = @import("std").mem; | 5880 | <pre>{#syntax#}const mem = @import("std").mem; |
| 5887 | mem.set(u8, dest, c);{#endsyntax#}</pre> | 5881 | mem.set(u8, dest, c);{#endsyntax#}</pre> |
| 5888 | {#header_close#} | ||
| 5889 | {#header_open|@minValue#} | ||
| 5890 | <pre>{#syntax#}@minValue(comptime T: type) comptime_int{#endsyntax#}</pre> | ||
| 5891 | <p> | ||
| 5892 | This function returns the minimum value of the integer type T. | ||
| 5893 | </p> | ||
| 5894 | <p> | ||
| 5895 | The result is a compile time constant. | ||
| 5896 | </p> | ||
| 5897 | {#header_close#} | 5882 | {#header_close#} |
| 5898 | {#header_open|@mod#} | 5883 | {#header_open|@mod#} |
| 5899 | <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre> | 5884 | <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre> |
| ... | @@ -6688,7 +6673,7 @@ pub fn main() void { | ... | @@ -6688,7 +6673,7 @@ pub fn main() void { |
| 6688 | } | 6673 | } |
| 6689 | {#code_end#} | 6674 | {#code_end#} |
| 6690 | <p> | 6675 | <p> |
| 6691 | To obtain the maximum value of an unsigned integer, use {#link|@maxValue#}. | 6676 | To obtain the maximum value of an unsigned integer, use {#syntax#}std.math.maxInt{#endsyntax#}. |
| 6692 | </p> | 6677 | </p> |
| 6693 | {#header_close#} | 6678 | {#header_close#} |
| 6694 | {#header_open|Cast Truncates Data#} | 6679 | {#header_open|Cast Truncates Data#} |
| ... | @@ -6810,14 +6795,17 @@ pub fn main() void { | ... | @@ -6810,14 +6795,17 @@ pub fn main() void { |
| 6810 | <li>{#syntax#}*%{#endsyntax#} (wraparound multiplication)</li> | 6795 | <li>{#syntax#}*%{#endsyntax#} (wraparound multiplication)</li> |
| 6811 | </ul> | 6796 | </ul> |
| 6812 | {#code_begin|test#} | 6797 | {#code_begin|test#} |
| 6813 | const assert = @import("std").debug.assert; | 6798 | const std = @import("std"); |
| 6799 | const assert = std.debug.assert; | ||
| 6800 | const minInt = std.math.minInt; | ||
| 6801 | const maxInt = std.math.maxInt; | ||
| 6814 | 6802 | ||
| 6815 | test "wraparound addition and subtraction" { | 6803 | test "wraparound addition and subtraction" { |
| 6816 | const x: i32 = @maxValue(i32); | 6804 | const x: i32 = maxInt(i32); |
| 6817 | const min_val = x +% 1; | 6805 | const min_val = x +% 1; |
| 6818 | assert(min_val == @minValue(i32)); | 6806 | assert(min_val == minInt(i32)); |
| 6819 | const max_val = min_val -% 1; | 6807 | const max_val = min_val -% 1; |
| 6820 | assert(max_val == @maxValue(i32)); | 6808 | assert(max_val == maxInt(i32)); |
| 6821 | } | 6809 | } |
| 6822 | {#code_end#} | 6810 | {#code_end#} |
| 6823 | {#header_close#} | 6811 | {#header_close#} |
src-self-hosted/codegen.zig+4-3| ... | @@ -10,6 +10,7 @@ const Scope = @import("scope.zig").Scope; | ... | @@ -10,6 +10,7 @@ const Scope = @import("scope.zig").Scope; |
| 10 | const event = std.event; | 10 | const event = std.event; |
| 11 | const assert = std.debug.assert; | 11 | const assert = std.debug.assert; |
| 12 | const DW = std.dwarf; | 12 | const DW = std.dwarf; |
| 13 | const maxInt = std.math.maxInt; | ||
| 13 | 14 | ||
| 14 | pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) !void { | 15 | pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) !void { |
| 15 | fn_val.base.ref(); | 16 | fn_val.base.ref(); |
| ... | @@ -362,15 +363,15 @@ fn addLLVMAttrInt( | ... | @@ -362,15 +363,15 @@ fn addLLVMAttrInt( |
| 362 | } | 363 | } |
| 363 | 364 | ||
| 364 | fn addLLVMFnAttr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8) !void { | 365 | fn addLLVMFnAttr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8) !void { |
| 365 | return addLLVMAttr(ofile, fn_val, @maxValue(llvm.AttributeIndex), attr_name); | 366 | return addLLVMAttr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name); |
| 366 | } | 367 | } |
| 367 | 368 | ||
| 368 | fn addLLVMFnAttrStr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: []const u8) !void { | 369 | fn addLLVMFnAttrStr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: []const u8) !void { |
| 369 | return addLLVMAttrStr(ofile, fn_val, @maxValue(llvm.AttributeIndex), attr_name, attr_val); | 370 | return addLLVMAttrStr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val); |
| 370 | } | 371 | } |
| 371 | 372 | ||
| 372 | fn addLLVMFnAttrInt(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: u64) !void { | 373 | fn addLLVMFnAttrInt(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: u64) !void { |
| 373 | return addLLVMAttrInt(ofile, fn_val, @maxValue(llvm.AttributeIndex), attr_name, attr_val); | 374 | return addLLVMAttrInt(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val); |
| 374 | } | 375 | } |
| 375 | 376 | ||
| 376 | fn renderLoadUntyped( | 377 | fn renderLoadUntyped( |
src/all_types.hpp-16| ... | @@ -1343,8 +1343,6 @@ enum BuiltinFnId { | ... | @@ -1343,8 +1343,6 @@ enum BuiltinFnId { |
| 1343 | BuiltinFnIdMemset, | 1343 | BuiltinFnIdMemset, |
| 1344 | BuiltinFnIdSizeof, | 1344 | BuiltinFnIdSizeof, |
| 1345 | BuiltinFnIdAlignOf, | 1345 | BuiltinFnIdAlignOf, |
| 1346 | BuiltinFnIdMaxValue, | ||
| 1347 | BuiltinFnIdMinValue, | ||
| 1348 | BuiltinFnIdMemberCount, | 1346 | BuiltinFnIdMemberCount, |
| 1349 | BuiltinFnIdMemberType, | 1347 | BuiltinFnIdMemberType, |
| 1350 | BuiltinFnIdMemberName, | 1348 | BuiltinFnIdMemberName, |
| ... | @@ -2081,8 +2079,6 @@ enum IrInstructionId { | ... | @@ -2081,8 +2079,6 @@ enum IrInstructionId { |
| 2081 | IrInstructionIdCUndef, | 2079 | IrInstructionIdCUndef, |
| 2082 | IrInstructionIdArrayLen, | 2080 | IrInstructionIdArrayLen, |
| 2083 | IrInstructionIdRef, | 2081 | IrInstructionIdRef, |
| 2084 | IrInstructionIdMinValue, | ||
| 2085 | IrInstructionIdMaxValue, | ||
| 2086 | IrInstructionIdCompileErr, | 2082 | IrInstructionIdCompileErr, |
| 2087 | IrInstructionIdCompileLog, | 2083 | IrInstructionIdCompileLog, |
| 2088 | IrInstructionIdErrName, | 2084 | IrInstructionIdErrName, |
| ... | @@ -2609,18 +2605,6 @@ struct IrInstructionRef { | ... | @@ -2609,18 +2605,6 @@ struct IrInstructionRef { |
| 2609 | bool is_volatile; | 2605 | bool is_volatile; |
| 2610 | }; | 2606 | }; |
| 2611 | 2607 | ||
| 2612 | struct IrInstructionMinValue { | ||
| 2613 | IrInstruction base; | ||
| 2614 | |||
| 2615 | IrInstruction *value; | ||
| 2616 | }; | ||
| 2617 | |||
| 2618 | struct IrInstructionMaxValue { | ||
| 2619 | IrInstruction base; | ||
| 2620 | |||
| 2621 | IrInstruction *value; | ||
| 2622 | }; | ||
| 2623 | |||
| 2624 | struct IrInstructionCompileErr { | 2608 | struct IrInstructionCompileErr { |
| 2625 | IrInstruction base; | 2609 | IrInstruction base; |
| 2626 | 2610 |
src/codegen.cpp-4| ... | @@ -5100,8 +5100,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, | ... | @@ -5100,8 +5100,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 5100 | case IrInstructionIdSizeOf: | 5100 | case IrInstructionIdSizeOf: |
| 5101 | case IrInstructionIdSwitchTarget: | 5101 | case IrInstructionIdSwitchTarget: |
| 5102 | case IrInstructionIdContainerInitFields: | 5102 | case IrInstructionIdContainerInitFields: |
| 5103 | case IrInstructionIdMinValue: | ||
| 5104 | case IrInstructionIdMaxValue: | ||
| 5105 | case IrInstructionIdCompileErr: | 5103 | case IrInstructionIdCompileErr: |
| 5106 | case IrInstructionIdCompileLog: | 5104 | case IrInstructionIdCompileLog: |
| 5107 | case IrInstructionIdArrayLen: | 5105 | case IrInstructionIdArrayLen: |
| ... | @@ -6651,8 +6649,6 @@ static void define_builtin_fns(CodeGen *g) { | ... | @@ -6651,8 +6649,6 @@ static void define_builtin_fns(CodeGen *g) { |
| 6651 | create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3); | 6649 | create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3); |
| 6652 | create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1); | 6650 | create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1); |
| 6653 | create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1); | 6651 | create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1); |
| 6654 | create_builtin_fn(g, BuiltinFnIdMaxValue, "maxValue", 1); | ||
| 6655 | create_builtin_fn(g, BuiltinFnIdMinValue, "minValue", 1); | ||
| 6656 | create_builtin_fn(g, BuiltinFnIdMemberCount, "memberCount", 1); | 6652 | create_builtin_fn(g, BuiltinFnIdMemberCount, "memberCount", 1); |
| 6657 | create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2); | 6653 | create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2); |
| 6658 | create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2); | 6654 | create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2); |
src/ir.cpp-120| ... | @@ -495,14 +495,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) { | ... | @@ -495,14 +495,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) { |
| 495 | return IrInstructionIdUnionInit; | 495 | return IrInstructionIdUnionInit; |
| 496 | } | 496 | } |
| 497 | 497 | ||
| 498 | static constexpr IrInstructionId ir_instruction_id(IrInstructionMinValue *) { | ||
| 499 | return IrInstructionIdMinValue; | ||
| 500 | } | ||
| 501 | |||
| 502 | static constexpr IrInstructionId ir_instruction_id(IrInstructionMaxValue *) { | ||
| 503 | return IrInstructionIdMaxValue; | ||
| 504 | } | ||
| 505 | |||
| 506 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { | 498 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { |
| 507 | return IrInstructionIdCompileErr; | 499 | return IrInstructionIdCompileErr; |
| 508 | } | 500 | } |
| ... | @@ -1693,24 +1685,6 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source | ... | @@ -1693,24 +1685,6 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source |
| 1693 | return &instruction->base; | 1685 | return &instruction->base; |
| 1694 | } | 1686 | } |
| 1695 | 1687 | ||
| 1696 | static IrInstruction *ir_build_min_value(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { | ||
| 1697 | IrInstructionMinValue *instruction = ir_build_instruction<IrInstructionMinValue>(irb, scope, source_node); | ||
| 1698 | instruction->value = value; | ||
| 1699 | |||
| 1700 | ir_ref_instruction(value, irb->current_basic_block); | ||
| 1701 | |||
| 1702 | return &instruction->base; | ||
| 1703 | } | ||
| 1704 | |||
| 1705 | static IrInstruction *ir_build_max_value(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { | ||
| 1706 | IrInstructionMaxValue *instruction = ir_build_instruction<IrInstructionMaxValue>(irb, scope, source_node); | ||
| 1707 | instruction->value = value; | ||
| 1708 | |||
| 1709 | ir_ref_instruction(value, irb->current_basic_block); | ||
| 1710 | |||
| 1711 | return &instruction->base; | ||
| 1712 | } | ||
| 1713 | |||
| 1714 | static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { | 1688 | static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { |
| 1715 | IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node); | 1689 | IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node); |
| 1716 | instruction->msg = msg; | 1690 | instruction->msg = msg; |
| ... | @@ -3813,26 +3787,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -3813,26 +3787,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 3813 | IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); | 3787 | IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); |
| 3814 | return ir_lval_wrap(irb, scope, c_undef, lval); | 3788 | return ir_lval_wrap(irb, scope, c_undef, lval); |
| 3815 | } | 3789 | } |
| 3816 | case BuiltinFnIdMaxValue: | ||
| 3817 | { | ||
| 3818 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | ||
| 3819 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); | ||
| 3820 | if (arg0_value == irb->codegen->invalid_instruction) | ||
| 3821 | return arg0_value; | ||
| 3822 | |||
| 3823 | IrInstruction *max_value = ir_build_max_value(irb, scope, node, arg0_value); | ||
| 3824 | return ir_lval_wrap(irb, scope, max_value, lval); | ||
| 3825 | } | ||
| 3826 | case BuiltinFnIdMinValue: | ||
| 3827 | { | ||
| 3828 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | ||
| 3829 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); | ||
| 3830 | if (arg0_value == irb->codegen->invalid_instruction) | ||
| 3831 | return arg0_value; | ||
| 3832 | |||
| 3833 | IrInstruction *min_value = ir_build_min_value(irb, scope, node, arg0_value); | ||
| 3834 | return ir_lval_wrap(irb, scope, min_value, lval); | ||
| 3835 | } | ||
| 3836 | case BuiltinFnIdCompileErr: | 3790 | case BuiltinFnIdCompileErr: |
| 3837 | { | 3791 | { |
| 3838 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 3792 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| ... | @@ -16407,74 +16361,6 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir | ... | @@ -16407,74 +16361,6 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir |
| 16407 | instruction->field_count, instruction->fields); | 16361 | instruction->field_count, instruction->fields); |
| 16408 | } | 16362 | } |
| 16409 | 16363 | ||
| 16410 | static IrInstruction *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction, | ||
| 16411 | IrInstruction *target_type_value, bool is_max) | ||
| 16412 | { | ||
| 16413 | ZigType *target_type = ir_resolve_type(ira, target_type_value); | ||
| 16414 | if (type_is_invalid(target_type)) | ||
| 16415 | return ira->codegen->invalid_instruction; | ||
| 16416 | switch (target_type->id) { | ||
| 16417 | case ZigTypeIdInvalid: | ||
| 16418 | zig_unreachable(); | ||
| 16419 | case ZigTypeIdInt: | ||
| 16420 | { | ||
| 16421 | IrInstruction *result = ir_const(ira, source_instruction, | ||
| 16422 | ira->codegen->builtin_types.entry_num_lit_int); | ||
| 16423 | eval_min_max_value(ira->codegen, target_type, &result->value, is_max); | ||
| 16424 | return result; | ||
| 16425 | } | ||
| 16426 | case ZigTypeIdBool: | ||
| 16427 | case ZigTypeIdVoid: | ||
| 16428 | { | ||
| 16429 | IrInstruction *result = ir_const(ira, source_instruction, target_type); | ||
| 16430 | eval_min_max_value(ira->codegen, target_type, &result->value, is_max); | ||
| 16431 | return result; | ||
| 16432 | } | ||
| 16433 | case ZigTypeIdEnum: | ||
| 16434 | case ZigTypeIdFloat: | ||
| 16435 | case ZigTypeIdMetaType: | ||
| 16436 | case ZigTypeIdUnreachable: | ||
| 16437 | case ZigTypeIdPointer: | ||
| 16438 | case ZigTypeIdPromise: | ||
| 16439 | case ZigTypeIdArray: | ||
| 16440 | case ZigTypeIdStruct: | ||
| 16441 | case ZigTypeIdComptimeFloat: | ||
| 16442 | case ZigTypeIdComptimeInt: | ||
| 16443 | case ZigTypeIdUndefined: | ||
| 16444 | case ZigTypeIdNull: | ||
| 16445 | case ZigTypeIdOptional: | ||
| 16446 | case ZigTypeIdErrorUnion: | ||
| 16447 | case ZigTypeIdErrorSet: | ||
| 16448 | case ZigTypeIdUnion: | ||
| 16449 | case ZigTypeIdFn: | ||
| 16450 | case ZigTypeIdNamespace: | ||
| 16451 | case ZigTypeIdBoundFn: | ||
| 16452 | case ZigTypeIdArgTuple: | ||
| 16453 | case ZigTypeIdOpaque: | ||
| 16454 | { | ||
| 16455 | const char *err_format = is_max ? | ||
| 16456 | "no max value available for type '%s'" : | ||
| 16457 | "no min value available for type '%s'"; | ||
| 16458 | ir_add_error(ira, source_instruction, | ||
| 16459 | buf_sprintf(err_format, buf_ptr(&target_type->name))); | ||
| 16460 | return ira->codegen->invalid_instruction; | ||
| 16461 | } | ||
| 16462 | } | ||
| 16463 | zig_unreachable(); | ||
| 16464 | } | ||
| 16465 | |||
| 16466 | static IrInstruction *ir_analyze_instruction_min_value(IrAnalyze *ira, | ||
| 16467 | IrInstructionMinValue *instruction) | ||
| 16468 | { | ||
| 16469 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->child, false); | ||
| 16470 | } | ||
| 16471 | |||
| 16472 | static IrInstruction *ir_analyze_instruction_max_value(IrAnalyze *ira, | ||
| 16473 | IrInstructionMaxValue *instruction) | ||
| 16474 | { | ||
| 16475 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->child, true); | ||
| 16476 | } | ||
| 16477 | |||
| 16478 | static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira, | 16364 | static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 16479 | IrInstructionCompileErr *instruction) | 16365 | IrInstructionCompileErr *instruction) |
| 16480 | { | 16366 | { |
| ... | @@ -21052,10 +20938,6 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio | ... | @@ -21052,10 +20938,6 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio |
| 21052 | return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction); | 20938 | return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction); |
| 21053 | case IrInstructionIdContainerInitFields: | 20939 | case IrInstructionIdContainerInitFields: |
| 21054 | return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction); | 20940 | return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction); |
| 21055 | case IrInstructionIdMinValue: | ||
| 21056 | return ir_analyze_instruction_min_value(ira, (IrInstructionMinValue *)instruction); | ||
| 21057 | case IrInstructionIdMaxValue: | ||
| 21058 | return ir_analyze_instruction_max_value(ira, (IrInstructionMaxValue *)instruction); | ||
| 21059 | case IrInstructionIdCompileErr: | 20941 | case IrInstructionIdCompileErr: |
| 21060 | return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction); | 20942 | return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction); |
| 21061 | case IrInstructionIdCompileLog: | 20943 | case IrInstructionIdCompileLog: |
| ... | @@ -21399,8 +21281,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -21399,8 +21281,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 21399 | case IrInstructionIdSwitchTarget: | 21281 | case IrInstructionIdSwitchTarget: |
| 21400 | case IrInstructionIdUnionTag: | 21282 | case IrInstructionIdUnionTag: |
| 21401 | case IrInstructionIdRef: | 21283 | case IrInstructionIdRef: |
| 21402 | case IrInstructionIdMinValue: | ||
| 21403 | case IrInstructionIdMaxValue: | ||
| 21404 | case IrInstructionIdEmbedFile: | 21284 | case IrInstructionIdEmbedFile: |
| 21405 | case IrInstructionIdTruncate: | 21285 | case IrInstructionIdTruncate: |
| 21406 | case IrInstructionIdIntType: | 21286 | case IrInstructionIdIntType: |
src/ir_print.cpp-18| ... | @@ -565,18 +565,6 @@ static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) { | ... | @@ -565,18 +565,6 @@ static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) { |
| 565 | ir_print_other_instruction(irp, instruction->value); | 565 | ir_print_other_instruction(irp, instruction->value); |
| 566 | } | 566 | } |
| 567 | 567 | ||
| 568 | static void ir_print_min_value(IrPrint *irp, IrInstructionMinValue *instruction) { | ||
| 569 | fprintf(irp->f, "@minValue("); | ||
| 570 | ir_print_other_instruction(irp, instruction->value); | ||
| 571 | fprintf(irp->f, ")"); | ||
| 572 | } | ||
| 573 | |||
| 574 | static void ir_print_max_value(IrPrint *irp, IrInstructionMaxValue *instruction) { | ||
| 575 | fprintf(irp->f, "@maxValue("); | ||
| 576 | ir_print_other_instruction(irp, instruction->value); | ||
| 577 | fprintf(irp->f, ")"); | ||
| 578 | } | ||
| 579 | |||
| 580 | static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) { | 568 | static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) { |
| 581 | fprintf(irp->f, "@compileError("); | 569 | fprintf(irp->f, "@compileError("); |
| 582 | ir_print_other_instruction(irp, instruction->msg); | 570 | ir_print_other_instruction(irp, instruction->msg); |
| ... | @@ -1480,12 +1468,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) { | ... | @@ -1480,12 +1468,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) { |
| 1480 | case IrInstructionIdRef: | 1468 | case IrInstructionIdRef: |
| 1481 | ir_print_ref(irp, (IrInstructionRef *)instruction); | 1469 | ir_print_ref(irp, (IrInstructionRef *)instruction); |
| 1482 | break; | 1470 | break; |
| 1483 | case IrInstructionIdMinValue: | ||
| 1484 | ir_print_min_value(irp, (IrInstructionMinValue *)instruction); | ||
| 1485 | break; | ||
| 1486 | case IrInstructionIdMaxValue: | ||
| 1487 | ir_print_max_value(irp, (IrInstructionMaxValue *)instruction); | ||
| 1488 | break; | ||
| 1489 | case IrInstructionIdCompileErr: | 1471 | case IrInstructionIdCompileErr: |
| 1490 | ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction); | 1472 | ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction); |
| 1491 | break; | 1473 | break; |
std/crypto/chacha20.zig+3-2| ... | @@ -5,6 +5,7 @@ const mem = std.mem; | ... | @@ -5,6 +5,7 @@ const mem = std.mem; |
| 5 | const endian = std.endian; | 5 | const endian = std.endian; |
| 6 | const assert = std.debug.assert; | 6 | const assert = std.debug.assert; |
| 7 | const builtin = @import("builtin"); | 7 | const builtin = @import("builtin"); |
| 8 | const maxInt = std.math.maxInt; | ||
| 8 | 9 | ||
| 9 | const QuarterRound = struct.{ | 10 | const QuarterRound = struct.{ |
| 10 | a: usize, | 11 | a: usize, |
| ... | @@ -111,7 +112,7 @@ fn chaCha20_internal(out: []u8, in: []const u8, key: [8]u32, counter: [4]u32) vo | ... | @@ -111,7 +112,7 @@ fn chaCha20_internal(out: []u8, in: []const u8, key: [8]u32, counter: [4]u32) vo |
| 111 | /// counter, nonce, and key. | 112 | /// counter, nonce, and key. |
| 112 | pub fn chaCha20IETF(out: []u8, in: []const u8, counter: u32, key: [32]u8, nonce: [12]u8) void { | 113 | pub fn chaCha20IETF(out: []u8, in: []const u8, counter: u32, key: [32]u8, nonce: [12]u8) void { |
| 113 | assert(in.len >= out.len); | 114 | assert(in.len >= out.len); |
| 114 | assert((in.len >> 6) + counter <= @maxValue(u32)); | 115 | assert((in.len >> 6) + counter <= maxInt(u32)); |
| 115 | 116 | ||
| 116 | var k: [8]u32 = undefined; | 117 | var k: [8]u32 = undefined; |
| 117 | var c: [4]u32 = undefined; | 118 | var c: [4]u32 = undefined; |
| ... | @@ -161,7 +162,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32] | ... | @@ -161,7 +162,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32] |
| 161 | const big_block = (block_size << 32); | 162 | const big_block = (block_size << 32); |
| 162 | 163 | ||
| 163 | // first partial big block | 164 | // first partial big block |
| 164 | if (((@intCast(u64, @maxValue(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) { | 165 | if (((@intCast(u64, maxInt(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) { |
| 165 | chaCha20_internal(out[cursor..big_block], in[cursor..big_block], k, c); | 166 | chaCha20_internal(out[cursor..big_block], in[cursor..big_block], k, c); |
| 166 | cursor = big_block - cursor; | 167 | cursor = big_block - cursor; |
| 167 | c[1] += 1; | 168 | c[1] += 1; |
std/debug/index.zig+3-2| ... | @@ -11,6 +11,7 @@ const pdb = std.pdb; | ... | @@ -11,6 +11,7 @@ const pdb = std.pdb; |
| 11 | const windows = os.windows; | 11 | const windows = os.windows; |
| 12 | const ArrayList = std.ArrayList; | 12 | const ArrayList = std.ArrayList; |
| 13 | const builtin = @import("builtin"); | 13 | const builtin = @import("builtin"); |
| 14 | const maxInt = std.math.maxInt; | ||
| 14 | 15 | ||
| 15 | pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator; | 16 | pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator; |
| 16 | pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator; | 17 | pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator; |
| ... | @@ -842,7 +843,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize { | ... | @@ -842,7 +843,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize { |
| 842 | if (word & (u32(1) << bit_i) != 0) { | 843 | if (word & (u32(1) << bit_i) != 0) { |
| 843 | try list.append(word_i * 32 + bit_i); | 844 | try list.append(word_i * 32 + bit_i); |
| 844 | } | 845 | } |
| 845 | if (bit_i == @maxValue(u5)) break; | 846 | if (bit_i == maxInt(u5)) break; |
| 846 | } | 847 | } |
| 847 | } | 848 | } |
| 848 | return list.toOwnedSlice(); | 849 | return list.toOwnedSlice(); |
| ... | @@ -1939,7 +1940,7 @@ fn findCompileUnit(st: *DebugInfo, target_address: u64) !*const CompileUnit { | ... | @@ -1939,7 +1940,7 @@ fn findCompileUnit(st: *DebugInfo, target_address: u64) !*const CompileUnit { |
| 1939 | if (begin_addr == 0 and end_addr == 0) { | 1940 | if (begin_addr == 0 and end_addr == 0) { |
| 1940 | break; | 1941 | break; |
| 1941 | } | 1942 | } |
| 1942 | if (begin_addr == @maxValue(usize)) { | 1943 | if (begin_addr == maxInt(usize)) { |
| 1943 | base_address = begin_addr; | 1944 | base_address = begin_addr; |
| 1944 | continue; | 1945 | continue; |
| 1945 | } | 1946 | } |
std/dynamic_library.zig+3-2| ... | @@ -10,6 +10,7 @@ const elf = std.elf; | ... | @@ -10,6 +10,7 @@ const elf = std.elf; |
| 10 | const linux = os.linux; | 10 | const linux = os.linux; |
| 11 | const windows = os.windows; | 11 | const windows = os.windows; |
| 12 | const win_util = @import("os/windows/util.zig"); | 12 | const win_util = @import("os/windows/util.zig"); |
| 13 | const maxInt = std.math.maxInt; | ||
| 13 | 14 | ||
| 14 | pub const DynLib = switch (builtin.os) { | 15 | pub const DynLib = switch (builtin.os) { |
| 15 | Os.linux => LinuxDynLib, | 16 | Os.linux => LinuxDynLib, |
| ... | @@ -80,7 +81,7 @@ pub const ElfLib = struct.{ | ... | @@ -80,7 +81,7 @@ pub const ElfLib = struct.{ |
| 80 | const elf_addr = @ptrToInt(bytes.ptr); | 81 | const elf_addr = @ptrToInt(bytes.ptr); |
| 81 | var ph_addr: usize = elf_addr + eh.e_phoff; | 82 | var ph_addr: usize = elf_addr + eh.e_phoff; |
| 82 | 83 | ||
| 83 | var base: usize = @maxValue(usize); | 84 | var base: usize = maxInt(usize); |
| 84 | var maybe_dynv: ?[*]usize = null; | 85 | var maybe_dynv: ?[*]usize = null; |
| 85 | { | 86 | { |
| 86 | var i: usize = 0; | 87 | var i: usize = 0; |
| ... | @@ -97,7 +98,7 @@ pub const ElfLib = struct.{ | ... | @@ -97,7 +98,7 @@ pub const ElfLib = struct.{ |
| 97 | } | 98 | } |
| 98 | } | 99 | } |
| 99 | const dynv = maybe_dynv orelse return error.MissingDynamicLinkingInformation; | 100 | const dynv = maybe_dynv orelse return error.MissingDynamicLinkingInformation; |
| 100 | if (base == @maxValue(usize)) return error.BaseNotFound; | 101 | if (base == maxInt(usize)) return error.BaseNotFound; |
| 101 | 102 | ||
| 102 | var maybe_strings: ?[*]u8 = null; | 103 | var maybe_strings: ?[*]u8 = null; |
| 103 | var maybe_syms: ?[*]elf.Sym = null; | 104 | var maybe_syms: ?[*]elf.Sym = null; |
std/event/loop.zig+2-1| ... | @@ -8,6 +8,7 @@ const fs = std.event.fs; | ... | @@ -8,6 +8,7 @@ const fs = std.event.fs; |
| 8 | const os = std.os; | 8 | const os = std.os; |
| 9 | const posix = os.posix; | 9 | const posix = os.posix; |
| 10 | const windows = os.windows; | 10 | const windows = os.windows; |
| 11 | const maxInt = std.math.maxInt; | ||
| 11 | 12 | ||
| 12 | pub const Loop = struct.{ | 13 | pub const Loop = struct.{ |
| 13 | allocator: *mem.Allocator, | 14 | allocator: *mem.Allocator, |
| ... | @@ -317,7 +318,7 @@ pub const Loop = struct.{ | ... | @@ -317,7 +318,7 @@ pub const Loop = struct.{ |
| 317 | windows.INVALID_HANDLE_VALUE, | 318 | windows.INVALID_HANDLE_VALUE, |
| 318 | null, | 319 | null, |
| 319 | undefined, | 320 | undefined, |
| 320 | @maxValue(windows.DWORD), | 321 | maxInt(windows.DWORD), |
| 321 | ); | 322 | ); |
| 322 | errdefer os.close(self.os_data.io_port); | 323 | errdefer os.close(self.os_data.io_port); |
| 323 | 324 |
std/heap.zig+2-1| ... | @@ -6,6 +6,7 @@ const os = std.os; | ... | @@ -6,6 +6,7 @@ const os = std.os; |
| 6 | const builtin = @import("builtin"); | 6 | const builtin = @import("builtin"); |
| 7 | const Os = builtin.Os; | 7 | const Os = builtin.Os; |
| 8 | const c = std.c; | 8 | const c = std.c; |
| 9 | const maxInt = std.math.maxInt; | ||
| 9 | 10 | ||
| 10 | const Allocator = mem.Allocator; | 11 | const Allocator = mem.Allocator; |
| 11 | 12 | ||
| ... | @@ -567,7 +568,7 @@ fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !voi | ... | @@ -567,7 +568,7 @@ fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !voi |
| 567 | fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void { | 568 | fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void { |
| 568 | //Maybe a platform's page_size is actually the same as or | 569 | //Maybe a platform's page_size is actually the same as or |
| 569 | // very near usize? | 570 | // very near usize? |
| 570 | if (os.page_size << 2 > @maxValue(usize)) return; | 571 | if (os.page_size << 2 > maxInt(usize)) return; |
| 571 | 572 | ||
| 572 | const USizeShift = @IntType(false, std.math.log2(usize.bit_count)); | 573 | const USizeShift = @IntType(false, std.math.log2(usize.bit_count)); |
| 573 | const large_align = u29(os.page_size << 2); | 574 | const large_align = u29(os.page_size << 2); |
std/json.zig+2-1| ... | @@ -5,6 +5,7 @@ | ... | @@ -5,6 +5,7 @@ |
| 5 | const std = @import("index.zig"); | 5 | const std = @import("index.zig"); |
| 6 | const debug = std.debug; | 6 | const debug = std.debug; |
| 7 | const mem = std.mem; | 7 | const mem = std.mem; |
| 8 | const maxInt = std.math.maxInt; | ||
| 8 | 9 | ||
| 9 | // A single token slice into the parent string. | 10 | // A single token slice into the parent string. |
| 10 | // | 11 | // |
| ... | @@ -107,7 +108,7 @@ pub const StreamingParser = struct.{ | ... | @@ -107,7 +108,7 @@ pub const StreamingParser = struct.{ |
| 107 | 108 | ||
| 108 | const object_bit = 0; | 109 | const object_bit = 0; |
| 109 | const array_bit = 1; | 110 | const array_bit = 1; |
| 110 | const max_stack_size = @maxValue(u8); | 111 | const max_stack_size = maxInt(u8); |
| 111 | 112 | ||
| 112 | pub fn init() StreamingParser { | 113 | pub fn init() StreamingParser { |
| 113 | var p: StreamingParser = undefined; | 114 | var p: StreamingParser = undefined; |
std/math/asinh.zig+2-1| ... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
| 7 | const std = @import("../index.zig"); | 7 | const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | const maxInt = std.math.maxInt; | ||
| 10 | 11 | ||
| 11 | pub fn asinh(x: var) @typeOf(x) { | 12 | pub fn asinh(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| ... | @@ -55,7 +56,7 @@ fn asinh64(x: f64) f64 { | ... | @@ -55,7 +56,7 @@ fn asinh64(x: f64) f64 { |
| 55 | const e = (u >> 52) & 0x7FF; | 56 | const e = (u >> 52) & 0x7FF; |
| 56 | const s = u >> 63; | 57 | const s = u >> 63; |
| 57 | 58 | ||
| 58 | var rx = @bitCast(f64, u & (@maxValue(u64) >> 1)); // |x| | 59 | var rx = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x| |
| 59 | 60 | ||
| 60 | if (math.isNegativeInf(x)) { | 61 | if (math.isNegativeInf(x)) { |
| 61 | return x; | 62 | return x; |
std/math/atanh.zig+2-1| ... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
| 7 | const std = @import("../index.zig"); | 7 | const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | const maxInt = std.math.maxInt; | ||
| 10 | 11 | ||
| 11 | pub fn atanh(x: var) @typeOf(x) { | 12 | pub fn atanh(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| ... | @@ -52,7 +53,7 @@ fn atanh_64(x: f64) f64 { | ... | @@ -52,7 +53,7 @@ fn atanh_64(x: f64) f64 { |
| 52 | const e = (u >> 52) & 0x7FF; | 53 | const e = (u >> 52) & 0x7FF; |
| 53 | const s = u >> 63; | 54 | const s = u >> 63; |
| 54 | 55 | ||
| 55 | var y = @bitCast(f64, u & (@maxValue(u64) >> 1)); // |x| | 56 | var y = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x| |
| 56 | 57 | ||
| 57 | if (y == 1.0) { | 58 | if (y == 1.0) { |
| 58 | return math.copysign(f64, math.inf(f64), x); | 59 | return math.copysign(f64, math.inf(f64), x); |
std/math/big/int.zig+31-29| ... | @@ -5,6 +5,8 @@ const math = std.math; | ... | @@ -5,6 +5,8 @@ const math = std.math; |
| 5 | const mem = std.mem; | 5 | const mem = std.mem; |
| 6 | const Allocator = mem.Allocator; | 6 | const Allocator = mem.Allocator; |
| 7 | const ArrayList = std.ArrayList; | 7 | const ArrayList = std.ArrayList; |
| 8 | const maxInt = std.math.maxInt; | ||
| 9 | const minInt = std.math.minInt; | ||
| 8 | 10 | ||
| 9 | const TypeId = builtin.TypeId; | 11 | const TypeId = builtin.TypeId; |
| 10 | 12 | ||
| ... | @@ -212,7 +214,7 @@ pub const Int = struct.{ | ... | @@ -212,7 +214,7 @@ pub const Int = struct.{ |
| 212 | self.positive = value >= 0; | 214 | self.positive = value >= 0; |
| 213 | self.len = req_limbs; | 215 | self.len = req_limbs; |
| 214 | 216 | ||
| 215 | if (w_value <= @maxValue(Limb)) { | 217 | if (w_value <= maxInt(Limb)) { |
| 216 | self.limbs[0] = w_value; | 218 | self.limbs[0] = w_value; |
| 217 | } else { | 219 | } else { |
| 218 | const mask = (1 << Limb.bit_count) - 1; | 220 | const mask = (1 << Limb.bit_count) - 1; |
| ... | @@ -267,7 +269,7 @@ pub const Int = struct.{ | ... | @@ -267,7 +269,7 @@ pub const Int = struct.{ |
| 267 | if (math.cast(T, r)) |ok| { | 269 | if (math.cast(T, r)) |ok| { |
| 268 | return -ok; | 270 | return -ok; |
| 269 | } else |_| { | 271 | } else |_| { |
| 270 | return @minValue(T); | 272 | return minInt(T); |
| 271 | } | 273 | } |
| 272 | } | 274 | } |
| 273 | } | 275 | } |
| ... | @@ -371,7 +373,7 @@ pub const Int = struct.{ | ... | @@ -371,7 +373,7 @@ pub const Int = struct.{ |
| 371 | } | 373 | } |
| 372 | } // Non power-of-two: batch divisions per word size. | 374 | } // Non power-of-two: batch divisions per word size. |
| 373 | else { | 375 | else { |
| 374 | const digits_per_limb = math.log(Limb, base, @maxValue(Limb)); | 376 | const digits_per_limb = math.log(Limb, base, maxInt(Limb)); |
| 375 | var limb_base: Limb = 1; | 377 | var limb_base: Limb = 1; |
| 376 | var j: usize = 0; | 378 | var j: usize = 0; |
| 377 | while (j < digits_per_limb) : (j += 1) { | 379 | while (j < digits_per_limb) : (j += 1) { |
| ... | @@ -717,7 +719,7 @@ pub const Int = struct.{ | ... | @@ -717,7 +719,7 @@ pub const Int = struct.{ |
| 717 | const c3: Limb = @boolToInt(@addWithOverflow(Limb, r1, r2, &r1)); | 719 | const c3: Limb = @boolToInt(@addWithOverflow(Limb, r1, r2, &r1)); |
| 718 | 720 | ||
| 719 | // This never overflows, c1, c3 are either 0 or 1 and if both are 1 then | 721 | // This never overflows, c1, c3 are either 0 or 1 and if both are 1 then |
| 720 | // c2 is at least <= @maxValue(Limb) - 2. | 722 | // c2 is at least <= maxInt(Limb) - 2. |
| 721 | carry.* = c1 + c2 + c3; | 723 | carry.* = c1 + c2 + c3; |
| 722 | 724 | ||
| 723 | return r1; | 725 | return r1; |
| ... | @@ -873,11 +875,11 @@ pub const Int = struct.{ | ... | @@ -873,11 +875,11 @@ pub const Int = struct.{ |
| 873 | while (i > t) : (i -= 1) { | 875 | while (i > t) : (i -= 1) { |
| 874 | // 3.1 | 876 | // 3.1 |
| 875 | if (x.limbs[i] == y.limbs[t]) { | 877 | if (x.limbs[i] == y.limbs[t]) { |
| 876 | q.limbs[i - t - 1] = @maxValue(Limb); | 878 | q.limbs[i - t - 1] = maxInt(Limb); |
| 877 | } else { | 879 | } else { |
| 878 | const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]); | 880 | const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]); |
| 879 | const z = @intCast(Limb, num / DoubleLimb(y.limbs[t])); | 881 | const z = @intCast(Limb, num / DoubleLimb(y.limbs[t])); |
| 880 | q.limbs[i - t - 1] = if (z > @maxValue(Limb)) @maxValue(Limb) else Limb(z); | 882 | q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else Limb(z); |
| 881 | } | 883 | } |
| 882 | 884 | ||
| 883 | // 3.2 | 885 | // 3.2 |
| ... | @@ -1081,7 +1083,7 @@ test "big.int comptime_int set" { | ... | @@ -1081,7 +1083,7 @@ test "big.int comptime_int set" { |
| 1081 | 1083 | ||
| 1082 | comptime var i: usize = 0; | 1084 | comptime var i: usize = 0; |
| 1083 | inline while (i < s_limb_count) : (i += 1) { | 1085 | inline while (i < s_limb_count) : (i += 1) { |
| 1084 | const result = Limb(s & @maxValue(Limb)); | 1086 | const result = Limb(s & maxInt(Limb)); |
| 1085 | s >>= Limb.bit_count / 2; | 1087 | s >>= Limb.bit_count / 2; |
| 1086 | s >>= Limb.bit_count / 2; | 1088 | s >>= Limb.bit_count / 2; |
| 1087 | debug.assert(a.limbs[i] == result); | 1089 | debug.assert(a.limbs[i] == result); |
| ... | @@ -1403,7 +1405,7 @@ test "big.int compare similar" { | ... | @@ -1403,7 +1405,7 @@ test "big.int compare similar" { |
| 1403 | } | 1405 | } |
| 1404 | 1406 | ||
| 1405 | test "big.int compare different limb size" { | 1407 | test "big.int compare different limb size" { |
| 1406 | var a = try Int.initSet(al, @maxValue(Limb) + 1); | 1408 | var a = try Int.initSet(al, maxInt(Limb) + 1); |
| 1407 | var b = try Int.initSet(al, 1); | 1409 | var b = try Int.initSet(al, 1); |
| 1408 | 1410 | ||
| 1409 | debug.assert(a.cmpAbs(b) == 1); | 1411 | debug.assert(a.cmpAbs(b) == 1); |
| ... | @@ -1457,16 +1459,16 @@ test "big.int add single-single" { | ... | @@ -1457,16 +1459,16 @@ test "big.int add single-single" { |
| 1457 | } | 1459 | } |
| 1458 | 1460 | ||
| 1459 | test "big.int add multi-single" { | 1461 | test "big.int add multi-single" { |
| 1460 | var a = try Int.initSet(al, @maxValue(Limb) + 1); | 1462 | var a = try Int.initSet(al, maxInt(Limb) + 1); |
| 1461 | var b = try Int.initSet(al, 1); | 1463 | var b = try Int.initSet(al, 1); |
| 1462 | 1464 | ||
| 1463 | var c = try Int.init(al); | 1465 | var c = try Int.init(al); |
| 1464 | 1466 | ||
| 1465 | try c.add(a, b); | 1467 | try c.add(a, b); |
| 1466 | debug.assert((try c.to(DoubleLimb)) == @maxValue(Limb) + 2); | 1468 | debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2); |
| 1467 | 1469 | ||
| 1468 | try c.add(b, a); | 1470 | try c.add(b, a); |
| 1469 | debug.assert((try c.to(DoubleLimb)) == @maxValue(Limb) + 2); | 1471 | debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2); |
| 1470 | } | 1472 | } |
| 1471 | 1473 | ||
| 1472 | test "big.int add multi-multi" { | 1474 | test "big.int add multi-multi" { |
| ... | @@ -1533,13 +1535,13 @@ test "big.int sub single-single" { | ... | @@ -1533,13 +1535,13 @@ test "big.int sub single-single" { |
| 1533 | } | 1535 | } |
| 1534 | 1536 | ||
| 1535 | test "big.int sub multi-single" { | 1537 | test "big.int sub multi-single" { |
| 1536 | var a = try Int.initSet(al, @maxValue(Limb) + 1); | 1538 | var a = try Int.initSet(al, maxInt(Limb) + 1); |
| 1537 | var b = try Int.initSet(al, 1); | 1539 | var b = try Int.initSet(al, 1); |
| 1538 | 1540 | ||
| 1539 | var c = try Int.init(al); | 1541 | var c = try Int.init(al); |
| 1540 | try c.sub(a, b); | 1542 | try c.sub(a, b); |
| 1541 | 1543 | ||
| 1542 | debug.assert((try c.to(Limb)) == @maxValue(Limb)); | 1544 | debug.assert((try c.to(Limb)) == maxInt(Limb)); |
| 1543 | } | 1545 | } |
| 1544 | 1546 | ||
| 1545 | test "big.int sub multi-multi" { | 1547 | test "big.int sub multi-multi" { |
| ... | @@ -1600,13 +1602,13 @@ test "big.int mul single-single" { | ... | @@ -1600,13 +1602,13 @@ test "big.int mul single-single" { |
| 1600 | } | 1602 | } |
| 1601 | 1603 | ||
| 1602 | test "big.int mul multi-single" { | 1604 | test "big.int mul multi-single" { |
| 1603 | var a = try Int.initSet(al, @maxValue(Limb)); | 1605 | var a = try Int.initSet(al, maxInt(Limb)); |
| 1604 | var b = try Int.initSet(al, 2); | 1606 | var b = try Int.initSet(al, 2); |
| 1605 | 1607 | ||
| 1606 | var c = try Int.init(al); | 1608 | var c = try Int.init(al); |
| 1607 | try c.mul(a, b); | 1609 | try c.mul(a, b); |
| 1608 | 1610 | ||
| 1609 | debug.assert((try c.to(DoubleLimb)) == 2 * @maxValue(Limb)); | 1611 | debug.assert((try c.to(DoubleLimb)) == 2 * maxInt(Limb)); |
| 1610 | } | 1612 | } |
| 1611 | 1613 | ||
| 1612 | test "big.int mul multi-multi" { | 1614 | test "big.int mul multi-multi" { |
| ... | @@ -1622,29 +1624,29 @@ test "big.int mul multi-multi" { | ... | @@ -1622,29 +1624,29 @@ test "big.int mul multi-multi" { |
| 1622 | } | 1624 | } |
| 1623 | 1625 | ||
| 1624 | test "big.int mul alias r with a" { | 1626 | test "big.int mul alias r with a" { |
| 1625 | var a = try Int.initSet(al, @maxValue(Limb)); | 1627 | var a = try Int.initSet(al, maxInt(Limb)); |
| 1626 | var b = try Int.initSet(al, 2); | 1628 | var b = try Int.initSet(al, 2); |
| 1627 | 1629 | ||
| 1628 | try a.mul(a, b); | 1630 | try a.mul(a, b); |
| 1629 | 1631 | ||
| 1630 | debug.assert((try a.to(DoubleLimb)) == 2 * @maxValue(Limb)); | 1632 | debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); |
| 1631 | } | 1633 | } |
| 1632 | 1634 | ||
| 1633 | test "big.int mul alias r with b" { | 1635 | test "big.int mul alias r with b" { |
| 1634 | var a = try Int.initSet(al, @maxValue(Limb)); | 1636 | var a = try Int.initSet(al, maxInt(Limb)); |
| 1635 | var b = try Int.initSet(al, 2); | 1637 | var b = try Int.initSet(al, 2); |
| 1636 | 1638 | ||
| 1637 | try a.mul(b, a); | 1639 | try a.mul(b, a); |
| 1638 | 1640 | ||
| 1639 | debug.assert((try a.to(DoubleLimb)) == 2 * @maxValue(Limb)); | 1641 | debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); |
| 1640 | } | 1642 | } |
| 1641 | 1643 | ||
| 1642 | test "big.int mul alias r with a and b" { | 1644 | test "big.int mul alias r with a and b" { |
| 1643 | var a = try Int.initSet(al, @maxValue(Limb)); | 1645 | var a = try Int.initSet(al, maxInt(Limb)); |
| 1644 | 1646 | ||
| 1645 | try a.mul(a, a); | 1647 | try a.mul(a, a); |
| 1646 | 1648 | ||
| 1647 | debug.assert((try a.to(DoubleLimb)) == @maxValue(Limb) * @maxValue(Limb)); | 1649 | debug.assert((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb)); |
| 1648 | } | 1650 | } |
| 1649 | 1651 | ||
| 1650 | test "big.int mul a*0" { | 1652 | test "big.int mul a*0" { |
| ... | @@ -2047,8 +2049,8 @@ test "big.int bitwise and simple" { | ... | @@ -2047,8 +2049,8 @@ test "big.int bitwise and simple" { |
| 2047 | } | 2049 | } |
| 2048 | 2050 | ||
| 2049 | test "big.int bitwise and multi-limb" { | 2051 | test "big.int bitwise and multi-limb" { |
| 2050 | var a = try Int.initSet(al, @maxValue(Limb) + 1); | 2052 | var a = try Int.initSet(al, maxInt(Limb) + 1); |
| 2051 | var b = try Int.initSet(al, @maxValue(Limb)); | 2053 | var b = try Int.initSet(al, maxInt(Limb)); |
| 2052 | 2054 | ||
| 2053 | try a.bitAnd(a, b); | 2055 | try a.bitAnd(a, b); |
| 2054 | 2056 | ||
| ... | @@ -2065,12 +2067,12 @@ test "big.int bitwise xor simple" { | ... | @@ -2065,12 +2067,12 @@ test "big.int bitwise xor simple" { |
| 2065 | } | 2067 | } |
| 2066 | 2068 | ||
| 2067 | test "big.int bitwise xor multi-limb" { | 2069 | test "big.int bitwise xor multi-limb" { |
| 2068 | var a = try Int.initSet(al, @maxValue(Limb) + 1); | 2070 | var a = try Int.initSet(al, maxInt(Limb) + 1); |
| 2069 | var b = try Int.initSet(al, @maxValue(Limb)); | 2071 | var b = try Int.initSet(al, maxInt(Limb)); |
| 2070 | 2072 | ||
| 2071 | try a.bitXor(a, b); | 2073 | try a.bitXor(a, b); |
| 2072 | 2074 | ||
| 2073 | debug.assert((try a.to(DoubleLimb)) == (@maxValue(Limb) + 1) ^ @maxValue(Limb)); | 2075 | debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb)); |
| 2074 | } | 2076 | } |
| 2075 | 2077 | ||
| 2076 | test "big.int bitwise or simple" { | 2078 | test "big.int bitwise or simple" { |
| ... | @@ -2083,13 +2085,13 @@ test "big.int bitwise or simple" { | ... | @@ -2083,13 +2085,13 @@ test "big.int bitwise or simple" { |
| 2083 | } | 2085 | } |
| 2084 | 2086 | ||
| 2085 | test "big.int bitwise or multi-limb" { | 2087 | test "big.int bitwise or multi-limb" { |
| 2086 | var a = try Int.initSet(al, @maxValue(Limb) + 1); | 2088 | var a = try Int.initSet(al, maxInt(Limb) + 1); |
| 2087 | var b = try Int.initSet(al, @maxValue(Limb)); | 2089 | var b = try Int.initSet(al, maxInt(Limb)); |
| 2088 | 2090 | ||
| 2089 | try a.bitOr(a, b); | 2091 | try a.bitOr(a, b); |
| 2090 | 2092 | ||
| 2091 | // TODO: big.int.cpp or is wrong on multi-limb. | 2093 | // TODO: big.int.cpp or is wrong on multi-limb. |
| 2092 | debug.assert((try a.to(DoubleLimb)) == (@maxValue(Limb) + 1) + @maxValue(Limb)); | 2094 | debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb)); |
| 2093 | } | 2095 | } |
| 2094 | 2096 | ||
| 2095 | test "big.int var args" { | 2097 | test "big.int var args" { |
std/math/copysign.zig+4-3| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../index.zig"); | 1 | const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | 5 | ||
| 5 | pub fn copysign(comptime T: type, x: T, y: T) T { | 6 | pub fn copysign(comptime T: type, x: T, y: T) T { |
| 6 | return switch (T) { | 7 | return switch (T) { |
| ... | @@ -15,7 +16,7 @@ fn copysign16(x: f16, y: f16) f16 { | ... | @@ -15,7 +16,7 @@ fn copysign16(x: f16, y: f16) f16 { |
| 15 | const ux = @bitCast(u16, x); | 16 | const ux = @bitCast(u16, x); |
| 16 | const uy = @bitCast(u16, y); | 17 | const uy = @bitCast(u16, y); |
| 17 | 18 | ||
| 18 | const h1 = ux & (@maxValue(u16) / 2); | 19 | const h1 = ux & (maxInt(u16) / 2); |
| 19 | const h2 = uy & (u16(1) << 15); | 20 | const h2 = uy & (u16(1) << 15); |
| 20 | return @bitCast(f16, h1 | h2); | 21 | return @bitCast(f16, h1 | h2); |
| 21 | } | 22 | } |
| ... | @@ -24,7 +25,7 @@ fn copysign32(x: f32, y: f32) f32 { | ... | @@ -24,7 +25,7 @@ fn copysign32(x: f32, y: f32) f32 { |
| 24 | const ux = @bitCast(u32, x); | 25 | const ux = @bitCast(u32, x); |
| 25 | const uy = @bitCast(u32, y); | 26 | const uy = @bitCast(u32, y); |
| 26 | 27 | ||
| 27 | const h1 = ux & (@maxValue(u32) / 2); | 28 | const h1 = ux & (maxInt(u32) / 2); |
| 28 | const h2 = uy & (u32(1) << 31); | 29 | const h2 = uy & (u32(1) << 31); |
| 29 | return @bitCast(f32, h1 | h2); | 30 | return @bitCast(f32, h1 | h2); |
| 30 | } | 31 | } |
| ... | @@ -33,7 +34,7 @@ fn copysign64(x: f64, y: f64) f64 { | ... | @@ -33,7 +34,7 @@ fn copysign64(x: f64, y: f64) f64 { |
| 33 | const ux = @bitCast(u64, x); | 34 | const ux = @bitCast(u64, x); |
| 34 | const uy = @bitCast(u64, y); | 35 | const uy = @bitCast(u64, y); |
| 35 | 36 | ||
| 36 | const h1 = ux & (@maxValue(u64) / 2); | 37 | const h1 = ux & (maxInt(u64) / 2); |
| 37 | const h2 = uy & (u64(1) << 63); | 38 | const h2 = uy & (u64(1) << 63); |
| 38 | return @bitCast(f64, h1 | h2); | 39 | return @bitCast(f64, h1 | h2); |
| 39 | } | 40 | } |
std/math/cosh.zig+2-1| ... | @@ -9,6 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,6 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const expo2 = @import("expo2.zig").expo2; | 10 | const expo2 = @import("expo2.zig").expo2; |
| 11 | const assert = std.debug.assert; | 11 | const assert = std.debug.assert; |
| 12 | const maxInt = std.math.maxInt; | ||
| 12 | 13 | ||
| 13 | pub fn cosh(x: var) @typeOf(x) { | 14 | pub fn cosh(x: var) @typeOf(x) { |
| 14 | const T = @typeOf(x); | 15 | const T = @typeOf(x); |
| ... | @@ -50,7 +51,7 @@ fn cosh32(x: f32) f32 { | ... | @@ -50,7 +51,7 @@ fn cosh32(x: f32) f32 { |
| 50 | fn cosh64(x: f64) f64 { | 51 | fn cosh64(x: f64) f64 { |
| 51 | const u = @bitCast(u64, x); | 52 | const u = @bitCast(u64, x); |
| 52 | const w = @intCast(u32, u >> 32); | 53 | const w = @intCast(u32, u >> 32); |
| 53 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); | 54 | const ax = @bitCast(f64, u & (maxInt(u64) >> 1)); |
| 54 | 55 | ||
| 55 | // TODO: Shouldn't need this explicit check. | 56 | // TODO: Shouldn't need this explicit check. |
| 56 | if (x == 0.0) { | 57 | if (x == 0.0) { |
std/math/fabs.zig+2-1| ... | @@ -6,6 +6,7 @@ | ... | @@ -6,6 +6,7 @@ |
| 6 | const std = @import("../index.zig"); | 6 | const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | const maxInt = std.math.maxInt; | ||
| 9 | 10 | ||
| 10 | pub fn fabs(x: var) @typeOf(x) { | 11 | pub fn fabs(x: var) @typeOf(x) { |
| 11 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| ... | @@ -31,7 +32,7 @@ fn fabs32(x: f32) f32 { | ... | @@ -31,7 +32,7 @@ fn fabs32(x: f32) f32 { |
| 31 | 32 | ||
| 32 | fn fabs64(x: f64) f64 { | 33 | fn fabs64(x: f64) f64 { |
| 33 | var u = @bitCast(u64, x); | 34 | var u = @bitCast(u64, x); |
| 34 | u &= @maxValue(u64) >> 1; | 35 | u &= maxInt(u64) >> 1; |
| 35 | return @bitCast(f64, u); | 36 | return @bitCast(f64, u); |
| 36 | } | 37 | } |
| 37 | 38 |
std/math/hypot.zig+5-4| ... | @@ -8,6 +8,7 @@ | ... | @@ -8,6 +8,7 @@ |
| 8 | const std = @import("../index.zig"); | 8 | const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const maxInt = std.math.maxInt; | ||
| 11 | 12 | ||
| 12 | pub fn hypot(comptime T: type, x: T, y: T) T { | 13 | pub fn hypot(comptime T: type, x: T, y: T) T { |
| 13 | return switch (T) { | 14 | return switch (T) { |
| ... | @@ -21,8 +22,8 @@ fn hypot32(x: f32, y: f32) f32 { | ... | @@ -21,8 +22,8 @@ fn hypot32(x: f32, y: f32) f32 { |
| 21 | var ux = @bitCast(u32, x); | 22 | var ux = @bitCast(u32, x); |
| 22 | var uy = @bitCast(u32, y); | 23 | var uy = @bitCast(u32, y); |
| 23 | 24 | ||
| 24 | ux &= @maxValue(u32) >> 1; | 25 | ux &= maxInt(u32) >> 1; |
| 25 | uy &= @maxValue(u32) >> 1; | 26 | uy &= maxInt(u32) >> 1; |
| 26 | if (ux < uy) { | 27 | if (ux < uy) { |
| 27 | const tmp = ux; | 28 | const tmp = ux; |
| 28 | ux = uy; | 29 | ux = uy; |
| ... | @@ -65,8 +66,8 @@ fn hypot64(x: f64, y: f64) f64 { | ... | @@ -65,8 +66,8 @@ fn hypot64(x: f64, y: f64) f64 { |
| 65 | var ux = @bitCast(u64, x); | 66 | var ux = @bitCast(u64, x); |
| 66 | var uy = @bitCast(u64, y); | 67 | var uy = @bitCast(u64, y); |
| 67 | 68 | ||
| 68 | ux &= @maxValue(u64) >> 1; | 69 | ux &= maxInt(u64) >> 1; |
| 69 | uy &= @maxValue(u64) >> 1; | 70 | uy &= maxInt(u64) >> 1; |
| 70 | if (ux < uy) { | 71 | if (ux < uy) { |
| 71 | const tmp = ux; | 72 | const tmp = ux; |
| 72 | ux = uy; | 73 | ux = uy; |
std/math/ilogb.zig+18-16| ... | @@ -1,12 +1,14 @@ | ... | @@ -1,12 +1,14 @@ |
| 1 | // Special Cases: | 1 | // Special Cases: |
| 2 | // | 2 | // |
| 3 | // - ilogb(+-inf) = @maxValue(i32) | 3 | // - ilogb(+-inf) = maxInt(i32) |
| 4 | // - ilogb(0) = @maxValue(i32) | 4 | // - ilogb(0) = maxInt(i32) |
| 5 | // - ilogb(nan) = @maxValue(i32) | 5 | // - ilogb(nan) = maxInt(i32) |
| 6 | 6 | ||
| 7 | const std = @import("../index.zig"); | 7 | const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | const maxInt = std.math.maxInt; | ||
| 11 | const minInt = std.math.minInt; | ||
| 10 | 12 | ||
| 11 | pub fn ilogb(x: var) i32 { | 13 | pub fn ilogb(x: var) i32 { |
| 12 | const T = @typeOf(x); | 14 | const T = @typeOf(x); |
| ... | @@ -18,7 +20,7 @@ pub fn ilogb(x: var) i32 { | ... | @@ -18,7 +20,7 @@ pub fn ilogb(x: var) i32 { |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | // NOTE: Should these be exposed publically? | 22 | // NOTE: Should these be exposed publically? |
| 21 | const fp_ilogbnan = -1 - i32(@maxValue(u32) >> 1); | 23 | const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1); |
| 22 | const fp_ilogb0 = fp_ilogbnan; | 24 | const fp_ilogb0 = fp_ilogbnan; |
| 23 | 25 | ||
| 24 | fn ilogb32(x: f32) i32 { | 26 | fn ilogb32(x: f32) i32 { |
| ... | @@ -27,7 +29,7 @@ fn ilogb32(x: f32) i32 { | ... | @@ -27,7 +29,7 @@ fn ilogb32(x: f32) i32 { |
| 27 | 29 | ||
| 28 | // TODO: We should be able to merge this with the lower check. | 30 | // TODO: We should be able to merge this with the lower check. |
| 29 | if (math.isNan(x)) { | 31 | if (math.isNan(x)) { |
| 30 | return @maxValue(i32); | 32 | return maxInt(i32); |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | if (e == 0) { | 35 | if (e == 0) { |
| ... | @@ -50,7 +52,7 @@ fn ilogb32(x: f32) i32 { | ... | @@ -50,7 +52,7 @@ fn ilogb32(x: f32) i32 { |
| 50 | if (u << 9 != 0) { | 52 | if (u << 9 != 0) { |
| 51 | return fp_ilogbnan; | 53 | return fp_ilogbnan; |
| 52 | } else { | 54 | } else { |
| 53 | return @maxValue(i32); | 55 | return maxInt(i32); |
| 54 | } | 56 | } |
| 55 | } | 57 | } |
| 56 | 58 | ||
| ... | @@ -62,7 +64,7 @@ fn ilogb64(x: f64) i32 { | ... | @@ -62,7 +64,7 @@ fn ilogb64(x: f64) i32 { |
| 62 | var e = @intCast(i32, (u >> 52) & 0x7FF); | 64 | var e = @intCast(i32, (u >> 52) & 0x7FF); |
| 63 | 65 | ||
| 64 | if (math.isNan(x)) { | 66 | if (math.isNan(x)) { |
| 65 | return @maxValue(i32); | 67 | return maxInt(i32); |
| 66 | } | 68 | } |
| 67 | 69 | ||
| 68 | if (e == 0) { | 70 | if (e == 0) { |
| ... | @@ -85,7 +87,7 @@ fn ilogb64(x: f64) i32 { | ... | @@ -85,7 +87,7 @@ fn ilogb64(x: f64) i32 { |
| 85 | if (u << 12 != 0) { | 87 | if (u << 12 != 0) { |
| 86 | return fp_ilogbnan; | 88 | return fp_ilogbnan; |
| 87 | } else { | 89 | } else { |
| 88 | return @maxValue(i32); | 90 | return maxInt(i32); |
| 89 | } | 91 | } |
| 90 | } | 92 | } |
| 91 | 93 | ||
| ... | @@ -116,15 +118,15 @@ test "math.ilogb64" { | ... | @@ -116,15 +118,15 @@ test "math.ilogb64" { |
| 116 | } | 118 | } |
| 117 | 119 | ||
| 118 | test "math.ilogb32.special" { | 120 | test "math.ilogb32.special" { |
| 119 | assert(ilogb32(math.inf(f32)) == @maxValue(i32)); | 121 | assert(ilogb32(math.inf(f32)) == maxInt(i32)); |
| 120 | assert(ilogb32(-math.inf(f32)) == @maxValue(i32)); | 122 | assert(ilogb32(-math.inf(f32)) == maxInt(i32)); |
| 121 | assert(ilogb32(0.0) == @minValue(i32)); | 123 | assert(ilogb32(0.0) == minInt(i32)); |
| 122 | assert(ilogb32(math.nan(f32)) == @maxValue(i32)); | 124 | assert(ilogb32(math.nan(f32)) == maxInt(i32)); |
| 123 | } | 125 | } |
| 124 | 126 | ||
| 125 | test "math.ilogb64.special" { | 127 | test "math.ilogb64.special" { |
| 126 | assert(ilogb64(math.inf(f64)) == @maxValue(i32)); | 128 | assert(ilogb64(math.inf(f64)) == maxInt(i32)); |
| 127 | assert(ilogb64(-math.inf(f64)) == @maxValue(i32)); | 129 | assert(ilogb64(-math.inf(f64)) == maxInt(i32)); |
| 128 | assert(ilogb64(0.0) == @minValue(i32)); | 130 | assert(ilogb64(0.0) == minInt(i32)); |
| 129 | assert(ilogb64(math.nan(f64)) == @maxValue(i32)); | 131 | assert(ilogb64(math.nan(f64)) == maxInt(i32)); |
| 130 | } | 132 | } |
std/math/index.zig+69-13| ... | @@ -382,7 +382,7 @@ pub fn absInt(x: var) !@typeOf(x) { | ... | @@ -382,7 +382,7 @@ pub fn absInt(x: var) !@typeOf(x) { |
| 382 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt | 382 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt |
| 383 | comptime assert(T.is_signed); // must pass a signed integer to absInt | 383 | comptime assert(T.is_signed); // must pass a signed integer to absInt |
| 384 | 384 | ||
| 385 | if (x == @minValue(@typeOf(x))) { | 385 | if (x == minInt(@typeOf(x))) { |
| 386 | return error.Overflow; | 386 | return error.Overflow; |
| 387 | } else { | 387 | } else { |
| 388 | @setRuntimeSafety(false); | 388 | @setRuntimeSafety(false); |
| ... | @@ -404,7 +404,7 @@ pub const absFloat = @import("fabs.zig").fabs; | ... | @@ -404,7 +404,7 @@ pub const absFloat = @import("fabs.zig").fabs; |
| 404 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { | 404 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { |
| 405 | @setRuntimeSafety(false); | 405 | @setRuntimeSafety(false); |
| 406 | if (denominator == 0) return error.DivisionByZero; | 406 | if (denominator == 0) return error.DivisionByZero; |
| 407 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1) return error.Overflow; | 407 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; |
| 408 | return @divTrunc(numerator, denominator); | 408 | return @divTrunc(numerator, denominator); |
| 409 | } | 409 | } |
| 410 | 410 | ||
| ... | @@ -425,7 +425,7 @@ fn testDivTrunc() void { | ... | @@ -425,7 +425,7 @@ fn testDivTrunc() void { |
| 425 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { | 425 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { |
| 426 | @setRuntimeSafety(false); | 426 | @setRuntimeSafety(false); |
| 427 | if (denominator == 0) return error.DivisionByZero; | 427 | if (denominator == 0) return error.DivisionByZero; |
| 428 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1) return error.Overflow; | 428 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; |
| 429 | return @divFloor(numerator, denominator); | 429 | return @divFloor(numerator, denominator); |
| 430 | } | 430 | } |
| 431 | 431 | ||
| ... | @@ -446,7 +446,7 @@ fn testDivFloor() void { | ... | @@ -446,7 +446,7 @@ fn testDivFloor() void { |
| 446 | pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { | 446 | pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { |
| 447 | @setRuntimeSafety(false); | 447 | @setRuntimeSafety(false); |
| 448 | if (denominator == 0) return error.DivisionByZero; | 448 | if (denominator == 0) return error.DivisionByZero; |
| 449 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1) return error.Overflow; | 449 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; |
| 450 | const result = @divTrunc(numerator, denominator); | 450 | const result = @divTrunc(numerator, denominator); |
| 451 | if (result * denominator != numerator) return error.UnexpectedRemainder; | 451 | if (result * denominator != numerator) return error.UnexpectedRemainder; |
| 452 | return result; | 452 | return result; |
| ... | @@ -530,8 +530,8 @@ test "math.absCast" { | ... | @@ -530,8 +530,8 @@ test "math.absCast" { |
| 530 | assert(absCast(i32(999)) == 999); | 530 | assert(absCast(i32(999)) == 999); |
| 531 | assert(@typeOf(absCast(i32(999))) == u32); | 531 | assert(@typeOf(absCast(i32(999))) == u32); |
| 532 | 532 | ||
| 533 | assert(absCast(i32(@minValue(i32))) == -@minValue(i32)); | 533 | assert(absCast(i32(minInt(i32))) == -minInt(i32)); |
| 534 | assert(@typeOf(absCast(i32(@minValue(i32)))) == u32); | 534 | assert(@typeOf(absCast(i32(minInt(i32)))) == u32); |
| 535 | } | 535 | } |
| 536 | 536 | ||
| 537 | /// Returns the negation of the integer parameter. | 537 | /// Returns the negation of the integer parameter. |
| ... | @@ -540,9 +540,9 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { | ... | @@ -540,9 +540,9 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { |
| 540 | if (@typeOf(x).is_signed) return negate(x); | 540 | if (@typeOf(x).is_signed) return negate(x); |
| 541 | 541 | ||
| 542 | const int = @IntType(true, @typeOf(x).bit_count); | 542 | const int = @IntType(true, @typeOf(x).bit_count); |
| 543 | if (x > -@minValue(int)) return error.Overflow; | 543 | if (x > -minInt(int)) return error.Overflow; |
| 544 | 544 | ||
| 545 | if (x == -@minValue(int)) return @minValue(int); | 545 | if (x == -minInt(int)) return minInt(int); |
| 546 | 546 | ||
| 547 | return -@intCast(int, x); | 547 | return -@intCast(int, x); |
| 548 | } | 548 | } |
| ... | @@ -551,10 +551,10 @@ test "math.negateCast" { | ... | @@ -551,10 +551,10 @@ test "math.negateCast" { |
| 551 | assert((negateCast(u32(999)) catch unreachable) == -999); | 551 | assert((negateCast(u32(999)) catch unreachable) == -999); |
| 552 | assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32); | 552 | assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32); |
| 553 | 553 | ||
| 554 | assert((negateCast(u32(-@minValue(i32))) catch unreachable) == @minValue(i32)); | 554 | assert((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32)); |
| 555 | assert(@typeOf(negateCast(u32(-@minValue(i32))) catch unreachable) == i32); | 555 | assert(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32); |
| 556 | 556 | ||
| 557 | if (negateCast(u32(@maxValue(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow); | 557 | if (negateCast(u32(maxInt(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow); |
| 558 | } | 558 | } |
| 559 | 559 | ||
| 560 | /// Cast an integer to a different integer type. If the value doesn't fit, | 560 | /// Cast an integer to a different integer type. If the value doesn't fit, |
| ... | @@ -562,9 +562,9 @@ test "math.negateCast" { | ... | @@ -562,9 +562,9 @@ test "math.negateCast" { |
| 562 | pub fn cast(comptime T: type, x: var) (error.{Overflow}!T) { | 562 | pub fn cast(comptime T: type, x: var) (error.{Overflow}!T) { |
| 563 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer | 563 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer |
| 564 | comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer | 564 | comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer |
| 565 | if (@maxValue(@typeOf(x)) > @maxValue(T) and x > @maxValue(T)) { | 565 | if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) { |
| 566 | return error.Overflow; | 566 | return error.Overflow; |
| 567 | } else if (@minValue(@typeOf(x)) < @minValue(T) and x < @minValue(T)) { | 567 | } else if (minInt(@typeOf(x)) < minInt(T) and x < minInt(T)) { |
| 568 | return error.Overflow; | 568 | return error.Overflow; |
| 569 | } else { | 569 | } else { |
| 570 | return @intCast(T, x); | 570 | return @intCast(T, x); |
| ... | @@ -658,3 +658,59 @@ test "math.f64_min" { | ... | @@ -658,3 +658,59 @@ test "math.f64_min" { |
| 658 | const fmin: f64 = f64_min; | 658 | const fmin: f64 = f64_min; |
| 659 | assert(@bitCast(u64, fmin) == f64_min_u64); | 659 | assert(@bitCast(u64, fmin) == f64_min_u64); |
| 660 | } | 660 | } |
| 661 | |||
| 662 | pub fn maxInt(comptime T: type) comptime_int { | ||
| 663 | const info = @typeInfo(T); | ||
| 664 | const bit_count = comptime_int(info.Int.bits); // TODO #1683 | ||
| 665 | if (bit_count == 0) return 0; | ||
| 666 | return (1 << (bit_count - @boolToInt(info.Int.is_signed))) - 1; | ||
| 667 | } | ||
| 668 | |||
| 669 | pub fn minInt(comptime T: type) comptime_int { | ||
| 670 | const info = @typeInfo(T); | ||
| 671 | const bit_count = comptime_int(info.Int.bits); // TODO #1683 | ||
| 672 | if (!info.Int.is_signed) return 0; | ||
| 673 | if (bit_count == 0) return 0; | ||
| 674 | return -(1 << (bit_count - 1)); | ||
| 675 | } | ||
| 676 | |||
| 677 | test "minInt and maxInt" { | ||
| 678 | assert(maxInt(u0) == 0); | ||
| 679 | assert(maxInt(u1) == 1); | ||
| 680 | assert(maxInt(u8) == 255); | ||
| 681 | assert(maxInt(u16) == 65535); | ||
| 682 | assert(maxInt(u32) == 4294967295); | ||
| 683 | assert(maxInt(u64) == 18446744073709551615); | ||
| 684 | |||
| 685 | assert(maxInt(i0) == 0); | ||
| 686 | assert(maxInt(i1) == 0); | ||
| 687 | assert(maxInt(i8) == 127); | ||
| 688 | assert(maxInt(i16) == 32767); | ||
| 689 | assert(maxInt(i32) == 2147483647); | ||
| 690 | assert(maxInt(i63) == 4611686018427387903); | ||
| 691 | assert(maxInt(i64) == 9223372036854775807); | ||
| 692 | |||
| 693 | assert(minInt(u0) == 0); | ||
| 694 | assert(minInt(u1) == 0); | ||
| 695 | assert(minInt(u8) == 0); | ||
| 696 | assert(minInt(u16) == 0); | ||
| 697 | assert(minInt(u32) == 0); | ||
| 698 | assert(minInt(u63) == 0); | ||
| 699 | assert(minInt(u64) == 0); | ||
| 700 | |||
| 701 | assert(minInt(i0) == 0); | ||
| 702 | assert(minInt(i1) == -1); | ||
| 703 | assert(minInt(i8) == -128); | ||
| 704 | assert(minInt(i16) == -32768); | ||
| 705 | assert(minInt(i32) == -2147483648); | ||
| 706 | assert(minInt(i63) == -4611686018427387904); | ||
| 707 | assert(minInt(i64) == -9223372036854775808); | ||
| 708 | } | ||
| 709 | |||
| 710 | test "max value type" { | ||
| 711 | // If the type of maxInt(i32) was i32 then this implicit cast to | ||
| 712 | // u32 would not work. But since the value is a number literal, | ||
| 713 | // it works fine. | ||
| 714 | const x: u32 = maxInt(i32); | ||
| 715 | assert(x == 2147483647); | ||
| 716 | } |
std/math/isfinite.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../index.zig"); | 1 | const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | 5 | ||
| 5 | pub fn isFinite(x: var) bool { | 6 | pub fn isFinite(x: var) bool { |
| 6 | const T = @typeOf(x); | 7 | const T = @typeOf(x); |
| ... | @@ -15,7 +16,7 @@ pub fn isFinite(x: var) bool { | ... | @@ -15,7 +16,7 @@ pub fn isFinite(x: var) bool { |
| 15 | }, | 16 | }, |
| 16 | f64 => { | 17 | f64 => { |
| 17 | const bits = @bitCast(u64, x); | 18 | const bits = @bitCast(u64, x); |
| 18 | return bits & (@maxValue(u64) >> 1) < (0x7FF << 52); | 19 | return bits & (maxInt(u64) >> 1) < (0x7FF << 52); |
| 19 | }, | 20 | }, |
| 20 | else => { | 21 | else => { |
| 21 | @compileError("isFinite not implemented for " ++ @typeName(T)); | 22 | @compileError("isFinite not implemented for " ++ @typeName(T)); |
std/math/isinf.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../index.zig"); | 1 | const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | 5 | ||
| 5 | pub fn isInf(x: var) bool { | 6 | pub fn isInf(x: var) bool { |
| 6 | const T = @typeOf(x); | 7 | const T = @typeOf(x); |
| ... | @@ -15,7 +16,7 @@ pub fn isInf(x: var) bool { | ... | @@ -15,7 +16,7 @@ pub fn isInf(x: var) bool { |
| 15 | }, | 16 | }, |
| 16 | f64 => { | 17 | f64 => { |
| 17 | const bits = @bitCast(u64, x); | 18 | const bits = @bitCast(u64, x); |
| 18 | return bits & (@maxValue(u64) >> 1) == (0x7FF << 52); | 19 | return bits & (maxInt(u64) >> 1) == (0x7FF << 52); |
| 19 | }, | 20 | }, |
| 20 | else => { | 21 | else => { |
| 21 | @compileError("isInf not implemented for " ++ @typeName(T)); | 22 | @compileError("isInf not implemented for " ++ @typeName(T)); |
std/math/isnan.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../index.zig"); | 1 | const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | 5 | ||
| 5 | pub fn isNan(x: var) bool { | 6 | pub fn isNan(x: var) bool { |
| 6 | const T = @typeOf(x); | 7 | const T = @typeOf(x); |
| ... | @@ -15,7 +16,7 @@ pub fn isNan(x: var) bool { | ... | @@ -15,7 +16,7 @@ pub fn isNan(x: var) bool { |
| 15 | }, | 16 | }, |
| 16 | f64 => { | 17 | f64 => { |
| 17 | const bits = @bitCast(u64, x); | 18 | const bits = @bitCast(u64, x); |
| 18 | return (bits & (@maxValue(u64) >> 1)) > (u64(0x7FF) << 52); | 19 | return (bits & (maxInt(u64) >> 1)) > (u64(0x7FF) << 52); |
| 19 | }, | 20 | }, |
| 20 | else => { | 21 | else => { |
| 21 | @compileError("isNan not implemented for " ++ @typeName(T)); | 22 | @compileError("isNan not implemented for " ++ @typeName(T)); |
std/math/isnormal.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../index.zig"); | 1 | const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | 5 | ||
| 5 | pub fn isNormal(x: var) bool { | 6 | pub fn isNormal(x: var) bool { |
| 6 | const T = @typeOf(x); | 7 | const T = @typeOf(x); |
| ... | @@ -15,7 +16,7 @@ pub fn isNormal(x: var) bool { | ... | @@ -15,7 +16,7 @@ pub fn isNormal(x: var) bool { |
| 15 | }, | 16 | }, |
| 16 | f64 => { | 17 | f64 => { |
| 17 | const bits = @bitCast(u64, x); | 18 | const bits = @bitCast(u64, x); |
| 18 | return (bits + (1 << 52)) & (@maxValue(u64) >> 1) >= (1 << 53); | 19 | return (bits + (1 << 52)) & (maxInt(u64) >> 1) >= (1 << 53); |
| 19 | }, | 20 | }, |
| 20 | else => { | 21 | else => { |
| 21 | @compileError("isNormal not implemented for " ++ @typeName(T)); | 22 | @compileError("isNormal not implemented for " ++ @typeName(T)); |
std/math/log10.zig+2-1| ... | @@ -10,6 +10,7 @@ const math = std.math; | ... | @@ -10,6 +10,7 @@ const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const builtin = @import("builtin"); | 11 | const builtin = @import("builtin"); |
| 12 | const TypeId = builtin.TypeId; | 12 | const TypeId = builtin.TypeId; |
| 13 | const maxInt = std.math.maxInt; | ||
| 13 | 14 | ||
| 14 | pub fn log10(x: var) @typeOf(x) { | 15 | pub fn log10(x: var) @typeOf(x) { |
| 15 | const T = @typeOf(x); | 16 | const T = @typeOf(x); |
| ... | @@ -151,7 +152,7 @@ pub fn log10_64(x_: f64) f64 { | ... | @@ -151,7 +152,7 @@ pub fn log10_64(x_: f64) f64 { |
| 151 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) | 152 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) |
| 152 | var hi = f - hfsq; | 153 | var hi = f - hfsq; |
| 153 | var hii = @bitCast(u64, hi); | 154 | var hii = @bitCast(u64, hi); |
| 154 | hii &= u64(@maxValue(u64)) << 32; | 155 | hii &= u64(maxInt(u64)) << 32; |
| 155 | hi = @bitCast(f64, hii); | 156 | hi = @bitCast(f64, hii); |
| 156 | const lo = f - hi - hfsq + s * (hfsq + R); | 157 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 157 | 158 |
std/math/log2.zig+2-1| ... | @@ -10,6 +10,7 @@ const math = std.math; | ... | @@ -10,6 +10,7 @@ const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const builtin = @import("builtin"); | 11 | const builtin = @import("builtin"); |
| 12 | const TypeId = builtin.TypeId; | 12 | const TypeId = builtin.TypeId; |
| 13 | const maxInt = std.math.maxInt; | ||
| 13 | 14 | ||
| 14 | pub fn log2(x: var) @typeOf(x) { | 15 | pub fn log2(x: var) @typeOf(x) { |
| 15 | const T = @typeOf(x); | 16 | const T = @typeOf(x); |
| ... | @@ -151,7 +152,7 @@ pub fn log2_64(x_: f64) f64 { | ... | @@ -151,7 +152,7 @@ pub fn log2_64(x_: f64) f64 { |
| 151 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) | 152 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) |
| 152 | var hi = f - hfsq; | 153 | var hi = f - hfsq; |
| 153 | var hii = @bitCast(u64, hi); | 154 | var hii = @bitCast(u64, hi); |
| 154 | hii &= u64(@maxValue(u64)) << 32; | 155 | hii &= u64(maxInt(u64)) << 32; |
| 155 | hi = @bitCast(f64, hii); | 156 | hi = @bitCast(f64, hii); |
| 156 | const lo = f - hi - hfsq + s * (hfsq + R); | 157 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 157 | 158 |
std/math/modf.zig+2-1| ... | @@ -6,6 +6,7 @@ | ... | @@ -6,6 +6,7 @@ |
| 6 | const std = @import("../index.zig"); | 6 | const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | const maxInt = std.math.maxInt; | ||
| 9 | 10 | ||
| 10 | fn modf_result(comptime T: type) type { | 11 | fn modf_result(comptime T: type) type { |
| 11 | return struct.{ | 12 | return struct.{ |
| ... | @@ -101,7 +102,7 @@ fn modf64(x: f64) modf64_result { | ... | @@ -101,7 +102,7 @@ fn modf64(x: f64) modf64_result { |
| 101 | return result; | 102 | return result; |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | const mask = u64(@maxValue(u64) >> 12) >> @intCast(u6, e); | 105 | const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e); |
| 105 | if (u & mask == 0) { | 106 | if (u & mask == 0) { |
| 106 | result.ipart = x; | 107 | result.ipart = x; |
| 107 | result.fpart = @bitCast(f64, us); | 108 | result.fpart = @bitCast(f64, us); |
std/math/sinh.zig+2-1| ... | @@ -9,6 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,6 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const expo2 = @import("expo2.zig").expo2; | 11 | const expo2 = @import("expo2.zig").expo2; |
| 12 | const maxInt = std.math.maxInt; | ||
| 12 | 13 | ||
| 13 | pub fn sinh(x: var) @typeOf(x) { | 14 | pub fn sinh(x: var) @typeOf(x) { |
| 14 | const T = @typeOf(x); | 15 | const T = @typeOf(x); |
| ... | @@ -56,7 +57,7 @@ fn sinh32(x: f32) f32 { | ... | @@ -56,7 +57,7 @@ fn sinh32(x: f32) f32 { |
| 56 | fn sinh64(x: f64) f64 { | 57 | fn sinh64(x: f64) f64 { |
| 57 | const u = @bitCast(u64, x); | 58 | const u = @bitCast(u64, x); |
| 58 | const w = @intCast(u32, u >> 32); | 59 | const w = @intCast(u32, u >> 32); |
| 59 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); | 60 | const ax = @bitCast(f64, u & (maxInt(u64) >> 1)); |
| 60 | 61 | ||
| 61 | if (x == 0.0 or math.isNan(x)) { | 62 | if (x == 0.0 or math.isNan(x)) { |
| 62 | return x; | 63 | return x; |
std/math/sqrt.zig+2-1| ... | @@ -10,6 +10,7 @@ const math = std.math; | ... | @@ -10,6 +10,7 @@ const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const builtin = @import("builtin"); | 11 | const builtin = @import("builtin"); |
| 12 | const TypeId = builtin.TypeId; | 12 | const TypeId = builtin.TypeId; |
| 13 | const maxInt = std.math.maxInt; | ||
| 13 | 14 | ||
| 14 | pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { | 15 | pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { |
| 15 | const T = @typeOf(x); | 16 | const T = @typeOf(x); |
| ... | @@ -17,7 +18,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ | ... | @@ -17,7 +18,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ |
| 17 | TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128 | 18 | TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128 |
| 18 | TypeId.Float => return @sqrt(T, x), | 19 | TypeId.Float => return @sqrt(T, x), |
| 19 | TypeId.ComptimeInt => comptime { | 20 | TypeId.ComptimeInt => comptime { |
| 20 | if (x > @maxValue(u128)) { | 21 | if (x > maxInt(u128)) { |
| 21 | @compileError("sqrt not implemented for comptime_int greater than 128 bits"); | 22 | @compileError("sqrt not implemented for comptime_int greater than 128 bits"); |
| 22 | } | 23 | } |
| 23 | if (x < 0) { | 24 | if (x < 0) { |
std/math/tanh.zig+2-1| ... | @@ -9,6 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,6 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const expo2 = @import("expo2.zig").expo2; | 11 | const expo2 = @import("expo2.zig").expo2; |
| 12 | const maxInt = std.math.maxInt; | ||
| 12 | 13 | ||
| 13 | pub fn tanh(x: var) @typeOf(x) { | 14 | pub fn tanh(x: var) @typeOf(x) { |
| 14 | const T = @typeOf(x); | 15 | const T = @typeOf(x); |
| ... | @@ -69,7 +70,7 @@ fn tanh32(x: f32) f32 { | ... | @@ -69,7 +70,7 @@ fn tanh32(x: f32) f32 { |
| 69 | fn tanh64(x: f64) f64 { | 70 | fn tanh64(x: f64) f64 { |
| 70 | const u = @bitCast(u64, x); | 71 | const u = @bitCast(u64, x); |
| 71 | const w = @intCast(u32, u >> 32); | 72 | const w = @intCast(u32, u >> 32); |
| 72 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); | 73 | const ax = @bitCast(f64, u & (maxInt(u64) >> 1)); |
| 73 | 74 | ||
| 74 | var t: f64 = undefined; | 75 | var t: f64 = undefined; |
| 75 | 76 |
std/math/trunc.zig+3-2| ... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
| 7 | const std = @import("../index.zig"); | 7 | const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | const maxInt = std.math.maxInt; | ||
| 10 | 11 | ||
| 11 | pub fn trunc(x: var) @typeOf(x) { | 12 | pub fn trunc(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| ... | @@ -29,7 +30,7 @@ fn trunc32(x: f32) f32 { | ... | @@ -29,7 +30,7 @@ fn trunc32(x: f32) f32 { |
| 29 | e = 1; | 30 | e = 1; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | m = u32(@maxValue(u32)) >> @intCast(u5, e); | 33 | m = u32(maxInt(u32)) >> @intCast(u5, e); |
| 33 | if (u & m == 0) { | 34 | if (u & m == 0) { |
| 34 | return x; | 35 | return x; |
| 35 | } else { | 36 | } else { |
| ... | @@ -50,7 +51,7 @@ fn trunc64(x: f64) f64 { | ... | @@ -50,7 +51,7 @@ fn trunc64(x: f64) f64 { |
| 50 | e = 1; | 51 | e = 1; |
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | m = u64(@maxValue(u64)) >> @intCast(u6, e); | 54 | m = u64(maxInt(u64)) >> @intCast(u6, e); |
| 54 | if (u & m == 0) { | 55 | if (u & m == 0) { |
| 55 | return x; | 56 | return x; |
| 56 | } else { | 57 | } else { |
std/os/child_process.zig+5-4| ... | @@ -14,6 +14,7 @@ const builtin = @import("builtin"); | ... | @@ -14,6 +14,7 @@ const builtin = @import("builtin"); |
| 14 | const Os = builtin.Os; | 14 | const Os = builtin.Os; |
| 15 | const LinkedList = std.LinkedList; | 15 | const LinkedList = std.LinkedList; |
| 16 | const windows_util = @import("windows/util.zig"); | 16 | const windows_util = @import("windows/util.zig"); |
| 17 | const maxInt = std.math.maxInt; | ||
| 17 | 18 | ||
| 18 | const is_windows = builtin.os == Os.windows; | 19 | const is_windows = builtin.os == Os.windows; |
| 19 | 20 | ||
| ... | @@ -307,16 +308,16 @@ pub const ChildProcess = struct.{ | ... | @@ -307,16 +308,16 @@ pub const ChildProcess = struct.{ |
| 307 | os.close(self.err_pipe[1]); | 308 | os.close(self.err_pipe[1]); |
| 308 | } | 309 | } |
| 309 | 310 | ||
| 310 | // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after | 311 | // Write maxInt(ErrInt) to the write end of the err_pipe. This is after |
| 311 | // waitpid, so this write is guaranteed to be after the child | 312 | // waitpid, so this write is guaranteed to be after the child |
| 312 | // pid potentially wrote an error. This way we can do a blocking | 313 | // pid potentially wrote an error. This way we can do a blocking |
| 313 | // read on the error pipe and either get @maxValue(ErrInt) (no error) or | 314 | // read on the error pipe and either get maxInt(ErrInt) (no error) or |
| 314 | // an error code. | 315 | // an error code. |
| 315 | try writeIntFd(self.err_pipe[1], @maxValue(ErrInt)); | 316 | try writeIntFd(self.err_pipe[1], maxInt(ErrInt)); |
| 316 | const err_int = try readIntFd(self.err_pipe[0]); | 317 | const err_int = try readIntFd(self.err_pipe[0]); |
| 317 | // Here we potentially return the fork child's error | 318 | // Here we potentially return the fork child's error |
| 318 | // from the parent pid. | 319 | // from the parent pid. |
| 319 | if (err_int != @maxValue(ErrInt)) { | 320 | if (err_int != maxInt(ErrInt)) { |
| 320 | return @errSetCast(SpawnError, @intToError(err_int)); | 321 | return @errSetCast(SpawnError, @intToError(err_int)); |
| 321 | } | 322 | } |
| 322 | 323 |
std/os/darwin.zig+2-1| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../index.zig"); | 1 | const std = @import("../index.zig"); |
| 2 | const c = std.c; | 2 | const c = std.c; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | 5 | ||
| 5 | pub use @import("darwin/errno.zig"); | 6 | pub use @import("darwin/errno.zig"); |
| 6 | 7 | ||
| ... | @@ -45,7 +46,7 @@ pub const MAP_NOCACHE = 0x0400; | ... | @@ -45,7 +46,7 @@ pub const MAP_NOCACHE = 0x0400; |
| 45 | 46 | ||
| 46 | /// don't reserve needed swap area | 47 | /// don't reserve needed swap area |
| 47 | pub const MAP_NORESERVE = 0x0040; | 48 | pub const MAP_NORESERVE = 0x0040; |
| 48 | pub const MAP_FAILED = @maxValue(usize); | 49 | pub const MAP_FAILED = maxInt(usize); |
| 49 | 50 | ||
| 50 | /// [XSI] no hang in wait/no child to reap | 51 | /// [XSI] no hang in wait/no child to reap |
| 51 | pub const WNOHANG = 0x00000001; | 52 | pub const WNOHANG = 0x00000001; |
std/os/file.zig+2-1| ... | @@ -9,6 +9,7 @@ const posix = os.posix; | ... | @@ -9,6 +9,7 @@ const posix = os.posix; |
| 9 | const windows = os.windows; | 9 | const windows = os.windows; |
| 10 | const Os = builtin.Os; | 10 | const Os = builtin.Os; |
| 11 | const windows_util = @import("windows/util.zig"); | 11 | const windows_util = @import("windows/util.zig"); |
| 12 | const maxInt = std.math.maxInt; | ||
| 12 | 13 | ||
| 13 | const is_posix = builtin.os != builtin.Os.windows; | 14 | const is_posix = builtin.os != builtin.Os.windows; |
| 14 | const is_windows = builtin.os == builtin.Os.windows; | 15 | const is_windows = builtin.os == builtin.Os.windows; |
| ... | @@ -385,7 +386,7 @@ pub const File = struct.{ | ... | @@ -385,7 +386,7 @@ pub const File = struct.{ |
| 385 | } else if (is_windows) { | 386 | } else if (is_windows) { |
| 386 | var index: usize = 0; | 387 | var index: usize = 0; |
| 387 | while (index < buffer.len) { | 388 | while (index < buffer.len) { |
| 388 | const want_read_count = @intCast(windows.DWORD, math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index)); | 389 | const want_read_count = @intCast(windows.DWORD, math.min(windows.DWORD(maxInt(windows.DWORD)), buffer.len - index)); |
| 389 | var amt_read: windows.DWORD = undefined; | 390 | var amt_read: windows.DWORD = undefined; |
| 390 | if (windows.ReadFile(self.handle, buffer.ptr + index, want_read_count, &amt_read, null) == 0) { | 391 | if (windows.ReadFile(self.handle, buffer.ptr + index, want_read_count, &amt_read, null) == 0) { |
| 391 | const err = windows.GetLastError(); | 392 | const err = windows.GetLastError(); |
std/os/linux/index.zig+4-3| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../../index.zig"); | 1 | const std = @import("../../index.zig"); |
| 2 | const assert = std.debug.assert; | 2 | const assert = std.debug.assert; |
| 3 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | const vdso = @import("vdso.zig"); | 5 | const vdso = @import("vdso.zig"); |
| 5 | pub use switch (builtin.arch) { | 6 | pub use switch (builtin.arch) { |
| 6 | builtin.Arch.x86_64 => @import("x86_64.zig"), | 7 | builtin.Arch.x86_64 => @import("x86_64.zig"), |
| ... | @@ -38,7 +39,7 @@ pub const PROT_EXEC = 4; | ... | @@ -38,7 +39,7 @@ pub const PROT_EXEC = 4; |
| 38 | pub const PROT_GROWSDOWN = 0x01000000; | 39 | pub const PROT_GROWSDOWN = 0x01000000; |
| 39 | pub const PROT_GROWSUP = 0x02000000; | 40 | pub const PROT_GROWSUP = 0x02000000; |
| 40 | 41 | ||
| 41 | pub const MAP_FAILED = @maxValue(usize); | 42 | pub const MAP_FAILED = maxInt(usize); |
| 42 | pub const MAP_SHARED = 0x01; | 43 | pub const MAP_SHARED = 0x01; |
| 43 | pub const MAP_PRIVATE = 0x02; | 44 | pub const MAP_PRIVATE = 0x02; |
| 44 | pub const MAP_TYPE = 0x0f; | 45 | pub const MAP_TYPE = 0x0f; |
| ... | @@ -1094,7 +1095,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti | ... | @@ -1094,7 +1095,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti |
| 1094 | 1095 | ||
| 1095 | const NSIG = 65; | 1096 | const NSIG = 65; |
| 1096 | const sigset_t = [128 / @sizeOf(usize)]usize; | 1097 | const sigset_t = [128 / @sizeOf(usize)]usize; |
| 1097 | const all_mask = []usize.{@maxValue(usize)}; | 1098 | const all_mask = []usize.{maxInt(usize)}; |
| 1098 | const app_mask = []usize.{0xfffffffc7fffffff}; | 1099 | const app_mask = []usize.{0xfffffffc7fffffff}; |
| 1099 | 1100 | ||
| 1100 | const k_sigaction = extern struct.{ | 1101 | const k_sigaction = extern struct.{ |
| ... | @@ -1111,7 +1112,7 @@ pub const Sigaction = struct.{ | ... | @@ -1111,7 +1112,7 @@ pub const Sigaction = struct.{ |
| 1111 | flags: u32, | 1112 | flags: u32, |
| 1112 | }; | 1113 | }; |
| 1113 | 1114 | ||
| 1114 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize)); | 1115 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); |
| 1115 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | 1116 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); |
| 1116 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | 1117 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); |
| 1117 | pub const empty_sigset = []usize.{0} ** sigset_t.len; | 1118 | pub const empty_sigset = []usize.{0} ** sigset_t.len; |
std/os/linux/vdso.zig+3-2| ... | @@ -3,6 +3,7 @@ const elf = std.elf; | ... | @@ -3,6 +3,7 @@ const elf = std.elf; |
| 3 | const linux = std.os.linux; | 3 | const linux = std.os.linux; |
| 4 | const cstr = std.cstr; | 4 | const cstr = std.cstr; |
| 5 | const mem = std.mem; | 5 | const mem = std.mem; |
| 6 | const maxInt = std.math.maxInt; | ||
| 6 | 7 | ||
| 7 | pub fn lookup(vername: []const u8, name: []const u8) usize { | 8 | pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 8 | const vdso_addr = std.os.linuxGetAuxVal(std.elf.AT_SYSINFO_EHDR); | 9 | const vdso_addr = std.os.linuxGetAuxVal(std.elf.AT_SYSINFO_EHDR); |
| ... | @@ -13,7 +14,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { | ... | @@ -13,7 +14,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 13 | const ph = @intToPtr(*elf.Phdr, ph_addr); | 14 | const ph = @intToPtr(*elf.Phdr, ph_addr); |
| 14 | 15 | ||
| 15 | var maybe_dynv: ?[*]usize = null; | 16 | var maybe_dynv: ?[*]usize = null; |
| 16 | var base: usize = @maxValue(usize); | 17 | var base: usize = maxInt(usize); |
| 17 | { | 18 | { |
| 18 | var i: usize = 0; | 19 | var i: usize = 0; |
| 19 | while (i < eh.e_phnum) : ({ | 20 | while (i < eh.e_phnum) : ({ |
| ... | @@ -29,7 +30,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { | ... | @@ -29,7 +30,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 29 | } | 30 | } |
| 30 | } | 31 | } |
| 31 | const dynv = maybe_dynv orelse return 0; | 32 | const dynv = maybe_dynv orelse return 0; |
| 32 | if (base == @maxValue(usize)) return 0; | 33 | if (base == maxInt(usize)) return 0; |
| 33 | 34 | ||
| 34 | var maybe_strings: ?[*]u8 = null; | 35 | var maybe_strings: ?[*]u8 = null; |
| 35 | var maybe_syms: ?[*]elf.Sym = null; | 36 | var maybe_syms: ?[*]elf.Sym = null; |
std/os/windows/index.zig+6-5| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | const std = @import("../../index.zig"); | 1 | const std = @import("../../index.zig"); |
| 2 | const assert = std.debug.assert; | 2 | const assert = std.debug.assert; |
| 3 | const maxInt = std.math.maxInt; | ||
| 3 | 4 | ||
| 4 | pub use @import("advapi32.zig"); | 5 | pub use @import("advapi32.zig"); |
| 5 | pub use @import("kernel32.zig"); | 6 | pub use @import("kernel32.zig"); |
| ... | @@ -53,17 +54,17 @@ pub const TRUE = 1; | ... | @@ -53,17 +54,17 @@ pub const TRUE = 1; |
| 53 | pub const FALSE = 0; | 54 | pub const FALSE = 0; |
| 54 | 55 | ||
| 55 | /// The standard input device. Initially, this is the console input buffer, CONIN$. | 56 | /// The standard input device. Initially, this is the console input buffer, CONIN$. |
| 56 | pub const STD_INPUT_HANDLE = @maxValue(DWORD) - 10 + 1; | 57 | pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1; |
| 57 | 58 | ||
| 58 | /// The standard output device. Initially, this is the active console screen buffer, CONOUT$. | 59 | /// The standard output device. Initially, this is the active console screen buffer, CONOUT$. |
| 59 | pub const STD_OUTPUT_HANDLE = @maxValue(DWORD) - 11 + 1; | 60 | pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; |
| 60 | 61 | ||
| 61 | /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. | 62 | /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. |
| 62 | pub const STD_ERROR_HANDLE = @maxValue(DWORD) - 12 + 1; | 63 | pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; |
| 63 | 64 | ||
| 64 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, @maxValue(usize)); | 65 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); |
| 65 | 66 | ||
| 66 | pub const INVALID_FILE_ATTRIBUTES = DWORD(@maxValue(DWORD)); | 67 | pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD)); |
| 67 | 68 | ||
| 68 | pub const OVERLAPPED = extern struct.{ | 69 | pub const OVERLAPPED = extern struct.{ |
| 69 | Internal: ULONG_PTR, | 70 | Internal: ULONG_PTR, |
std/rand/index.zig+6-5| ... | @@ -20,6 +20,7 @@ const assert = std.debug.assert; | ... | @@ -20,6 +20,7 @@ const assert = std.debug.assert; |
| 20 | const mem = std.mem; | 20 | const mem = std.mem; |
| 21 | const math = std.math; | 21 | const math = std.math; |
| 22 | const ziggurat = @import("ziggurat.zig"); | 22 | const ziggurat = @import("ziggurat.zig"); |
| 23 | const maxInt = std.math.maxInt; | ||
| 23 | 24 | ||
| 24 | // When you need fast unbiased random numbers | 25 | // When you need fast unbiased random numbers |
| 25 | pub const DefaultPrng = Xoroshiro128; | 26 | pub const DefaultPrng = Xoroshiro128; |
| ... | @@ -39,7 +40,7 @@ pub const Random = struct.{ | ... | @@ -39,7 +40,7 @@ pub const Random = struct.{ |
| 39 | return r.int(u1) != 0; | 40 | return r.int(u1) != 0; |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | /// Returns a random int `i` such that `0 <= i <= @maxValue(T)`. | 43 | /// Returns a random int `i` such that `0 <= i <= maxInt(T)`. |
| 43 | /// `i` is evenly distributed. | 44 | /// `i` is evenly distributed. |
| 44 | pub fn int(r: *Random, comptime T: type) T { | 45 | pub fn int(r: *Random, comptime T: type) T { |
| 45 | const UnsignedT = @IntType(false, T.bit_count); | 46 | const UnsignedT = @IntType(false, T.bit_count); |
| ... | @@ -69,14 +70,14 @@ pub const Random = struct.{ | ... | @@ -69,14 +70,14 @@ pub const Random = struct.{ |
| 69 | assert(T.is_signed == false); | 70 | assert(T.is_signed == false); |
| 70 | assert(0 < less_than); | 71 | assert(0 < less_than); |
| 71 | 72 | ||
| 72 | const last_group_size_minus_one: T = @maxValue(T) % less_than; | 73 | const last_group_size_minus_one: T = maxInt(T) % less_than; |
| 73 | if (last_group_size_minus_one == less_than - 1) { | 74 | if (last_group_size_minus_one == less_than - 1) { |
| 74 | // less_than is a power of two. | 75 | // less_than is a power of two. |
| 75 | assert(math.floorPowerOfTwo(T, less_than) == less_than); | 76 | assert(math.floorPowerOfTwo(T, less_than) == less_than); |
| 76 | // There is no retry zone. The optimal retry_zone_start would be @maxValue(T) + 1. | 77 | // There is no retry zone. The optimal retry_zone_start would be maxInt(T) + 1. |
| 77 | return r.int(T) % less_than; | 78 | return r.int(T) % less_than; |
| 78 | } | 79 | } |
| 79 | const retry_zone_start = @maxValue(T) - last_group_size_minus_one; | 80 | const retry_zone_start = maxInt(T) - last_group_size_minus_one; |
| 80 | 81 | ||
| 81 | while (true) { | 82 | while (true) { |
| 82 | const rand_val = r.int(T); | 83 | const rand_val = r.int(T); |
| ... | @@ -91,7 +92,7 @@ pub const Random = struct.{ | ... | @@ -91,7 +92,7 @@ pub const Random = struct.{ |
| 91 | /// for commentary on the runtime of this function. | 92 | /// for commentary on the runtime of this function. |
| 92 | pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T { | 93 | pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T { |
| 93 | assert(T.is_signed == false); | 94 | assert(T.is_signed == false); |
| 94 | if (at_most == @maxValue(T)) { | 95 | if (at_most == maxInt(T)) { |
| 95 | // have the full range | 96 | // have the full range |
| 96 | return r.int(T); | 97 | return r.int(T); |
| 97 | } | 98 | } |
std/special/builtin.zig+6-4| ... | @@ -1,14 +1,16 @@ | ... | @@ -1,14 +1,16 @@ |
| 1 | // These functions are provided when not linking against libc because LLVM | 1 | // These functions are provided when not linking against libc because LLVM |
| 2 | // sometimes generates code that calls them. | 2 | // sometimes generates code that calls them. |
| 3 | 3 | ||
| 4 | const std = @import("std"); | ||
| 4 | const builtin = @import("builtin"); | 5 | const builtin = @import("builtin"); |
| 6 | const maxInt = std.math.maxInt; | ||
| 5 | 7 | ||
| 6 | // Avoid dragging in the runtime safety mechanisms into this .o file, | 8 | // Avoid dragging in the runtime safety mechanisms into this .o file, |
| 7 | // unless we're trying to test this file. | 9 | // unless we're trying to test this file. |
| 8 | pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { | 10 | pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 9 | if (builtin.is_test) { | 11 | if (builtin.is_test) { |
| 10 | @setCold(true); | 12 | @setCold(true); |
| 11 | @import("std").debug.panic("{}", msg); | 13 | std.debug.panic("{}", msg); |
| 12 | } else { | 14 | } else { |
| 13 | unreachable; | 15 | unreachable; |
| 14 | } | 16 | } |
| ... | @@ -190,7 +192,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { | ... | @@ -190,7 +192,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 190 | }) {} | 192 | }) {} |
| 191 | ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1)); | 193 | ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1)); |
| 192 | } else { | 194 | } else { |
| 193 | ux &= @maxValue(uint) >> exp_bits; | 195 | ux &= maxInt(uint) >> exp_bits; |
| 194 | ux |= 1 << digits; | 196 | ux |= 1 << digits; |
| 195 | } | 197 | } |
| 196 | if (ey == 0) { | 198 | if (ey == 0) { |
| ... | @@ -201,7 +203,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { | ... | @@ -201,7 +203,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 201 | }) {} | 203 | }) {} |
| 202 | uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1)); | 204 | uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1)); |
| 203 | } else { | 205 | } else { |
| 204 | uy &= @maxValue(uint) >> exp_bits; | 206 | uy &= maxInt(uint) >> exp_bits; |
| 205 | uy |= 1 << digits; | 207 | uy |= 1 << digits; |
| 206 | } | 208 | } |
| 207 | 209 | ||
| ... | @@ -247,7 +249,7 @@ fn isNan(comptime T: type, bits: T) bool { | ... | @@ -247,7 +249,7 @@ fn isNan(comptime T: type, bits: T) bool { |
| 247 | } else if (T == u32) { | 249 | } else if (T == u32) { |
| 248 | return (bits & 0x7fffffff) > 0x7f800000; | 250 | return (bits & 0x7fffffff) > 0x7f800000; |
| 249 | } else if (T == u64) { | 251 | } else if (T == u64) { |
| 250 | return (bits & (@maxValue(u64) >> 1)) > (u64(0x7ff) << 52); | 252 | return (bits & (maxInt(u64) >> 1)) > (u64(0x7ff) << 52); |
| 251 | } else { | 253 | } else { |
| 252 | unreachable; | 254 | unreachable; |
| 253 | } | 255 | } |
std/special/compiler_rt/floattidf.zig+3-1| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const is_test = builtin.is_test; | 2 | const is_test = builtin.is_test; |
| 3 | const std = @import("std"); | ||
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const DBL_MANT_DIG = 53; | 6 | const DBL_MANT_DIG = 53; |
| 5 | 7 | ||
| ... | @@ -37,7 +39,7 @@ pub extern fn __floattidf(arg: i128) f64 { | ... | @@ -37,7 +39,7 @@ pub extern fn __floattidf(arg: i128) f64 { |
| 37 | const shift2_amt = @intCast(i32, N + (DBL_MANT_DIG + 2)) - sd; | 39 | const shift2_amt = @intCast(i32, N + (DBL_MANT_DIG + 2)) - sd; |
| 38 | const shift2_amt_u7 = @intCast(u7, shift2_amt); | 40 | const shift2_amt_u7 = @intCast(u7, shift2_amt); |
| 39 | 41 | ||
| 40 | a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, @maxValue(u128)) >> shift2_amt_u7)) != 0); | 42 | a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, maxInt(u128)) >> shift2_amt_u7)) != 0); |
| 41 | }, | 43 | }, |
| 42 | } | 44 | } |
| 43 | // finish | 45 | // finish |
std/special/compiler_rt/floattisf.zig+3-1| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const is_test = builtin.is_test; | 2 | const is_test = builtin.is_test; |
| 3 | const std = @import("std"); | ||
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const FLT_MANT_DIG = 24; | 6 | const FLT_MANT_DIG = 24; |
| 5 | 7 | ||
| ... | @@ -38,7 +40,7 @@ pub extern fn __floattisf(arg: i128) f32 { | ... | @@ -38,7 +40,7 @@ pub extern fn __floattisf(arg: i128) f32 { |
| 38 | const shift2_amt = @intCast(i32, N + (FLT_MANT_DIG + 2)) - sd; | 40 | const shift2_amt = @intCast(i32, N + (FLT_MANT_DIG + 2)) - sd; |
| 39 | const shift2_amt_u7 = @intCast(u7, shift2_amt); | 41 | const shift2_amt_u7 = @intCast(u7, shift2_amt); |
| 40 | 42 | ||
| 41 | a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, @maxValue(u128)) >> shift2_amt_u7)) != 0); | 43 | a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, maxInt(u128)) >> shift2_amt_u7)) != 0); |
| 42 | }, | 44 | }, |
| 43 | } | 45 | } |
| 44 | // finish | 46 | // finish |
std/special/compiler_rt/floattitf.zig+3-1| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const is_test = builtin.is_test; | 2 | const is_test = builtin.is_test; |
| 3 | const std = @import("std"); | ||
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const LDBL_MANT_DIG = 113; | 6 | const LDBL_MANT_DIG = 113; |
| 5 | 7 | ||
| ... | @@ -37,7 +39,7 @@ pub extern fn __floattitf(arg: i128) f128 { | ... | @@ -37,7 +39,7 @@ pub extern fn __floattitf(arg: i128) f128 { |
| 37 | const shift2_amt = @intCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; | 39 | const shift2_amt = @intCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; |
| 38 | const shift2_amt_u7 = @intCast(u7, shift2_amt); | 40 | const shift2_amt_u7 = @intCast(u7, shift2_amt); |
| 39 | 41 | ||
| 40 | a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, @maxValue(u128)) >> shift2_amt_u7)) != 0); | 42 | a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, maxInt(u128)) >> shift2_amt_u7)) != 0); |
| 41 | }, | 43 | }, |
| 42 | } | 44 | } |
| 43 | // finish | 45 | // finish |
std/special/compiler_rt/floatuntidf.zig+3-1| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const is_test = builtin.is_test; | 2 | const is_test = builtin.is_test; |
| 3 | const std = @import("std"); | ||
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const DBL_MANT_DIG = 53; | 6 | const DBL_MANT_DIG = 53; |
| 5 | 7 | ||
| ... | @@ -30,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { | ... | @@ -30,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { |
| 30 | const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd; | 32 | const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd; |
| 31 | const shift_amt_u7 = @intCast(u7, shift_amt); | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 32 | a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) | | 34 | a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) | |
| 33 | @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0); | 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); |
| 34 | }, | 36 | }, |
| 35 | } | 37 | } |
| 36 | // finish | 38 | // finish |
std/special/compiler_rt/floatuntisf.zig+3-1| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const is_test = builtin.is_test; | 2 | const is_test = builtin.is_test; |
| 3 | const std = @import("std"); | ||
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const FLT_MANT_DIG = 24; | 6 | const FLT_MANT_DIG = 24; |
| 5 | 7 | ||
| ... | @@ -30,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { | ... | @@ -30,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { |
| 30 | const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd; | 32 | const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd; |
| 31 | const shift_amt_u7 = @intCast(u7, shift_amt); | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 32 | a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) | | 34 | a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) | |
| 33 | @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0); | 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); |
| 34 | }, | 36 | }, |
| 35 | } | 37 | } |
| 36 | // finish | 38 | // finish |
std/special/compiler_rt/floatuntitf.zig+3-1| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const is_test = builtin.is_test; | 2 | const is_test = builtin.is_test; |
| 3 | const std = @import("std"); | ||
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const LDBL_MANT_DIG = 113; | 6 | const LDBL_MANT_DIG = 113; |
| 5 | 7 | ||
| ... | @@ -30,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { | ... | @@ -30,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { |
| 30 | const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; | 32 | const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; |
| 31 | const shift_amt_u7 = @intCast(u7, shift_amt); | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 32 | a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) | | 34 | a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) | |
| 33 | @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0); | 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); |
| 34 | }, | 36 | }, |
| 35 | } | 37 | } |
| 36 | // finish | 38 | // finish |
std/zig/parser_test.zig+2-1| ... | @@ -1868,6 +1868,7 @@ const std = @import("std"); | ... | @@ -1868,6 +1868,7 @@ const std = @import("std"); |
| 1868 | const mem = std.mem; | 1868 | const mem = std.mem; |
| 1869 | const warn = std.debug.warn; | 1869 | const warn = std.debug.warn; |
| 1870 | const io = std.io; | 1870 | const io = std.io; |
| 1871 | const maxInt = std.math.maxInt; | ||
| 1871 | 1872 | ||
| 1872 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; | 1873 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1873 | 1874 | ||
| ... | @@ -1916,7 +1917,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { | ... | @@ -1916,7 +1917,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 1916 | const needed_alloc_count = x: { | 1917 | const needed_alloc_count = x: { |
| 1917 | // Try it once with unlimited memory, make sure it works | 1918 | // Try it once with unlimited memory, make sure it works |
| 1918 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 1919 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1919 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize)); | 1920 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize)); |
| 1920 | var anything_changed: bool = undefined; | 1921 | var anything_changed: bool = undefined; |
| 1921 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); | 1922 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); |
| 1922 | if (!mem.eql(u8, result_source, expected_source)) { | 1923 | if (!mem.eql(u8, result_source, expected_source)) { |
test/cases/alignof.zig+4-2| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const std = @import("std"); |
| 2 | const assert = std.debug.assert; | ||
| 2 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const Foo = struct.{ | 6 | const Foo = struct.{ |
| 5 | x: u32, | 7 | x: u32, |
| ... | @@ -8,7 +10,7 @@ const Foo = struct.{ | ... | @@ -8,7 +10,7 @@ const Foo = struct.{ |
| 8 | }; | 10 | }; |
| 9 | 11 | ||
| 10 | test "@alignOf(T) before referencing T" { | 12 | test "@alignOf(T) before referencing T" { |
| 11 | comptime assert(@alignOf(Foo) != @maxValue(usize)); | 13 | comptime assert(@alignOf(Foo) != maxInt(usize)); |
| 12 | if (builtin.arch == builtin.Arch.x86_64) { | 14 | if (builtin.arch == builtin.Arch.x86_64) { |
| 13 | comptime assert(@alignOf(Foo) == 4); | 15 | comptime assert(@alignOf(Foo) == 4); |
| 14 | } | 16 | } |
test/cases/bitcast.zig+5-3| ... | @@ -1,4 +1,6 @@ | ... | @@ -1,4 +1,6 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const std = @import("std"); |
| 2 | const assert = std.debug.assert; | ||
| 3 | const maxInt = std.math.maxInt; | ||
| 2 | 4 | ||
| 3 | test "@bitCast i32 -> u32" { | 5 | test "@bitCast i32 -> u32" { |
| 4 | testBitCast_i32_u32(); | 6 | testBitCast_i32_u32(); |
| ... | @@ -6,8 +8,8 @@ test "@bitCast i32 -> u32" { | ... | @@ -6,8 +8,8 @@ test "@bitCast i32 -> u32" { |
| 6 | } | 8 | } |
| 7 | 9 | ||
| 8 | fn testBitCast_i32_u32() void { | 10 | fn testBitCast_i32_u32() void { |
| 9 | assert(conv(-1) == @maxValue(u32)); | 11 | assert(conv(-1) == maxInt(u32)); |
| 10 | assert(conv2(@maxValue(u32)) == -1); | 12 | assert(conv2(maxInt(u32)) == -1); |
| 11 | } | 13 | } |
| 12 | 14 | ||
| 13 | fn conv(x: i32) u32 { | 15 | fn conv(x: i32) u32 { |
test/cases/cast.zig+4-3| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const assert = std.debug.assert; | 2 | const assert = std.debug.assert; |
| 3 | const mem = std.mem; | 3 | const mem = std.mem; |
| 4 | const maxInt = std.math.maxInt; | ||
| 4 | 5 | ||
| 5 | test "int to ptr cast" { | 6 | test "int to ptr cast" { |
| 6 | const x = usize(13); | 7 | const x = usize(13); |
| ... | @@ -368,7 +369,7 @@ test "@bytesToSlice keeps pointer alignment" { | ... | @@ -368,7 +369,7 @@ test "@bytesToSlice keeps pointer alignment" { |
| 368 | } | 369 | } |
| 369 | 370 | ||
| 370 | test "@intCast i32 to u7" { | 371 | test "@intCast i32 to u7" { |
| 371 | var x: u128 = @maxValue(u128); | 372 | var x: u128 = maxInt(u128); |
| 372 | var y: i32 = 120; | 373 | var y: i32 = 120; |
| 373 | var z = x >> @intCast(u7, y); | 374 | var z = x >> @intCast(u7, y); |
| 374 | assert(z == 0xff); | 375 | assert(z == 0xff); |
| ... | @@ -435,11 +436,11 @@ test "compile time int to ptr of function" { | ... | @@ -435,11 +436,11 @@ test "compile time int to ptr of function" { |
| 435 | foobar(FUNCTION_CONSTANT); | 436 | foobar(FUNCTION_CONSTANT); |
| 436 | } | 437 | } |
| 437 | 438 | ||
| 438 | pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, @maxValue(usize)); | 439 | pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize)); |
| 439 | pub const PFN_void = extern fn (*c_void) void; | 440 | pub const PFN_void = extern fn (*c_void) void; |
| 440 | 441 | ||
| 441 | fn foobar(func: PFN_void) void { | 442 | fn foobar(func: PFN_void) void { |
| 442 | std.debug.assert(@ptrToInt(func) == @maxValue(usize)); | 443 | std.debug.assert(@ptrToInt(func) == maxInt(usize)); |
| 443 | } | 444 | } |
| 444 | 445 | ||
| 445 | test "implicit ptr to *c_void" { | 446 | test "implicit ptr to *c_void" { |
test/cases/math.zig+17-14| ... | @@ -1,4 +1,7 @@ | ... | @@ -1,4 +1,7 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const std = @import("std"); |
| 2 | const assert = std.debug.assert; | ||
| 3 | const maxInt = std.math.maxInt; | ||
| 4 | const minInt = std.math.minInt; | ||
| 2 | 5 | ||
| 3 | test "division" { | 6 | test "division" { |
| 4 | testDivision(); | 7 | testDivision(); |
| ... | @@ -179,30 +182,30 @@ test "const number literal" { | ... | @@ -179,30 +182,30 @@ test "const number literal" { |
| 179 | const ten = 10; | 182 | const ten = 10; |
| 180 | 183 | ||
| 181 | test "unsigned wrapping" { | 184 | test "unsigned wrapping" { |
| 182 | testUnsignedWrappingEval(@maxValue(u32)); | 185 | testUnsignedWrappingEval(maxInt(u32)); |
| 183 | comptime testUnsignedWrappingEval(@maxValue(u32)); | 186 | comptime testUnsignedWrappingEval(maxInt(u32)); |
| 184 | } | 187 | } |
| 185 | fn testUnsignedWrappingEval(x: u32) void { | 188 | fn testUnsignedWrappingEval(x: u32) void { |
| 186 | const zero = x +% 1; | 189 | const zero = x +% 1; |
| 187 | assert(zero == 0); | 190 | assert(zero == 0); |
| 188 | const orig = zero -% 1; | 191 | const orig = zero -% 1; |
| 189 | assert(orig == @maxValue(u32)); | 192 | assert(orig == maxInt(u32)); |
| 190 | } | 193 | } |
| 191 | 194 | ||
| 192 | test "signed wrapping" { | 195 | test "signed wrapping" { |
| 193 | testSignedWrappingEval(@maxValue(i32)); | 196 | testSignedWrappingEval(maxInt(i32)); |
| 194 | comptime testSignedWrappingEval(@maxValue(i32)); | 197 | comptime testSignedWrappingEval(maxInt(i32)); |
| 195 | } | 198 | } |
| 196 | fn testSignedWrappingEval(x: i32) void { | 199 | fn testSignedWrappingEval(x: i32) void { |
| 197 | const min_val = x +% 1; | 200 | const min_val = x +% 1; |
| 198 | assert(min_val == @minValue(i32)); | 201 | assert(min_val == minInt(i32)); |
| 199 | const max_val = min_val -% 1; | 202 | const max_val = min_val -% 1; |
| 200 | assert(max_val == @maxValue(i32)); | 203 | assert(max_val == maxInt(i32)); |
| 201 | } | 204 | } |
| 202 | 205 | ||
| 203 | test "negation wrapping" { | 206 | test "negation wrapping" { |
| 204 | testNegationWrappingEval(@minValue(i16)); | 207 | testNegationWrappingEval(minInt(i16)); |
| 205 | comptime testNegationWrappingEval(@minValue(i16)); | 208 | comptime testNegationWrappingEval(minInt(i16)); |
| 206 | } | 209 | } |
| 207 | fn testNegationWrappingEval(x: i16) void { | 210 | fn testNegationWrappingEval(x: i16) void { |
| 208 | assert(x == -32768); | 211 | assert(x == -32768); |
| ... | @@ -311,8 +314,8 @@ test "hex float literal within range" { | ... | @@ -311,8 +314,8 @@ test "hex float literal within range" { |
| 311 | } | 314 | } |
| 312 | 315 | ||
| 313 | test "truncating shift left" { | 316 | test "truncating shift left" { |
| 314 | testShlTrunc(@maxValue(u16)); | 317 | testShlTrunc(maxInt(u16)); |
| 315 | comptime testShlTrunc(@maxValue(u16)); | 318 | comptime testShlTrunc(maxInt(u16)); |
| 316 | } | 319 | } |
| 317 | fn testShlTrunc(x: u16) void { | 320 | fn testShlTrunc(x: u16) void { |
| 318 | const shifted = x << 1; | 321 | const shifted = x << 1; |
| ... | @@ -320,8 +323,8 @@ fn testShlTrunc(x: u16) void { | ... | @@ -320,8 +323,8 @@ fn testShlTrunc(x: u16) void { |
| 320 | } | 323 | } |
| 321 | 324 | ||
| 322 | test "truncating shift right" { | 325 | test "truncating shift right" { |
| 323 | testShrTrunc(@maxValue(u16)); | 326 | testShrTrunc(maxInt(u16)); |
| 324 | comptime testShrTrunc(@maxValue(u16)); | 327 | comptime testShrTrunc(maxInt(u16)); |
| 325 | } | 328 | } |
| 326 | fn testShrTrunc(x: u16) void { | 329 | fn testShrTrunc(x: u16) void { |
| 327 | const shifted = x >> 1; | 330 | const shifted = x >> 1; |
test/cases/misc.zig+9-44| ... | @@ -1,7 +1,9 @@ | ... | @@ -1,7 +1,9 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const std = @import("std"); |
| 2 | const mem = @import("std").mem; | 2 | const assert = std.debug.assert; |
| 3 | const cstr = @import("std").cstr; | 3 | const mem = std.mem; |
| 4 | const cstr = std.cstr; | ||
| 4 | const builtin = @import("builtin"); | 5 | const builtin = @import("builtin"); |
| 6 | const maxInt = std.math.maxInt; | ||
| 5 | 7 | ||
| 6 | // normal comment | 8 | // normal comment |
| 7 | 9 | ||
| ... | @@ -58,43 +60,6 @@ test "floating point primitive bit counts" { | ... | @@ -58,43 +60,6 @@ test "floating point primitive bit counts" { |
| 58 | assert(f64.bit_count == 64); | 60 | assert(f64.bit_count == 64); |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | test "@minValue and @maxValue" { | ||
| 62 | assert(@maxValue(u1) == 1); | ||
| 63 | assert(@maxValue(u8) == 255); | ||
| 64 | assert(@maxValue(u16) == 65535); | ||
| 65 | assert(@maxValue(u32) == 4294967295); | ||
| 66 | assert(@maxValue(u64) == 18446744073709551615); | ||
| 67 | |||
| 68 | assert(@maxValue(i1) == 0); | ||
| 69 | assert(@maxValue(i8) == 127); | ||
| 70 | assert(@maxValue(i16) == 32767); | ||
| 71 | assert(@maxValue(i32) == 2147483647); | ||
| 72 | assert(@maxValue(i63) == 4611686018427387903); | ||
| 73 | assert(@maxValue(i64) == 9223372036854775807); | ||
| 74 | |||
| 75 | assert(@minValue(u1) == 0); | ||
| 76 | assert(@minValue(u8) == 0); | ||
| 77 | assert(@minValue(u16) == 0); | ||
| 78 | assert(@minValue(u32) == 0); | ||
| 79 | assert(@minValue(u63) == 0); | ||
| 80 | assert(@minValue(u64) == 0); | ||
| 81 | |||
| 82 | assert(@minValue(i1) == -1); | ||
| 83 | assert(@minValue(i8) == -128); | ||
| 84 | assert(@minValue(i16) == -32768); | ||
| 85 | assert(@minValue(i32) == -2147483648); | ||
| 86 | assert(@minValue(i63) == -4611686018427387904); | ||
| 87 | assert(@minValue(i64) == -9223372036854775808); | ||
| 88 | } | ||
| 89 | |||
| 90 | test "max value type" { | ||
| 91 | // If the type of @maxValue(i32) was i32 then this implicit cast to | ||
| 92 | // u32 would not work. But since the value is a number literal, | ||
| 93 | // it works fine. | ||
| 94 | const x: u32 = @maxValue(i32); | ||
| 95 | assert(x == 2147483647); | ||
| 96 | } | ||
| 97 | |||
| 98 | test "short circuit" { | 63 | test "short circuit" { |
| 99 | testShortCircuit(false, true); | 64 | testShortCircuit(false, true); |
| 100 | comptime testShortCircuit(false, true); | 65 | comptime testShortCircuit(false, true); |
| ... | @@ -428,10 +393,10 @@ test "cast slice to u8 slice" { | ... | @@ -428,10 +393,10 @@ test "cast slice to u8 slice" { |
| 428 | const big_thing_again = @bytesToSlice(i32, bytes); | 393 | const big_thing_again = @bytesToSlice(i32, bytes); |
| 429 | assert(big_thing_again[2] == 3); | 394 | assert(big_thing_again[2] == 3); |
| 430 | big_thing_again[2] = -1; | 395 | big_thing_again[2] = -1; |
| 431 | assert(bytes[8] == @maxValue(u8)); | 396 | assert(bytes[8] == maxInt(u8)); |
| 432 | assert(bytes[9] == @maxValue(u8)); | 397 | assert(bytes[9] == maxInt(u8)); |
| 433 | assert(bytes[10] == @maxValue(u8)); | 398 | assert(bytes[10] == maxInt(u8)); |
| 434 | assert(bytes[11] == @maxValue(u8)); | 399 | assert(bytes[11] == maxInt(u8)); |
| 435 | } | 400 | } |
| 436 | 401 | ||
| 437 | test "pointer to void return type" { | 402 | test "pointer to void return type" { |
test/cases/struct.zig+17-15| ... | @@ -1,5 +1,7 @@ | ... | @@ -1,5 +1,7 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const std = @import("std"); |
| 2 | const assert = std.debug.assert; | ||
| 2 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 4 | const maxInt = std.math.maxInt; | ||
| 3 | 5 | ||
| 4 | const StructWithNoFields = struct.{ | 6 | const StructWithNoFields = struct.{ |
| 5 | fn add(a: i32, b: i32) i32 { | 7 | fn add(a: i32, b: i32) i32 { |
| ... | @@ -307,29 +309,29 @@ test "packed array 24bits" { | ... | @@ -307,29 +309,29 @@ test "packed array 24bits" { |
| 307 | assert(ptr.b[1].field == 0); | 309 | assert(ptr.b[1].field == 0); |
| 308 | assert(ptr.c == 0); | 310 | assert(ptr.c == 0); |
| 309 | 311 | ||
| 310 | ptr.a = @maxValue(u16); | 312 | ptr.a = maxInt(u16); |
| 311 | assert(ptr.a == @maxValue(u16)); | 313 | assert(ptr.a == maxInt(u16)); |
| 312 | assert(ptr.b[0].field == 0); | 314 | assert(ptr.b[0].field == 0); |
| 313 | assert(ptr.b[1].field == 0); | 315 | assert(ptr.b[1].field == 0); |
| 314 | assert(ptr.c == 0); | 316 | assert(ptr.c == 0); |
| 315 | 317 | ||
| 316 | ptr.b[0].field = @maxValue(u24); | 318 | ptr.b[0].field = maxInt(u24); |
| 317 | assert(ptr.a == @maxValue(u16)); | 319 | assert(ptr.a == maxInt(u16)); |
| 318 | assert(ptr.b[0].field == @maxValue(u24)); | 320 | assert(ptr.b[0].field == maxInt(u24)); |
| 319 | assert(ptr.b[1].field == 0); | 321 | assert(ptr.b[1].field == 0); |
| 320 | assert(ptr.c == 0); | 322 | assert(ptr.c == 0); |
| 321 | 323 | ||
| 322 | ptr.b[1].field = @maxValue(u24); | 324 | ptr.b[1].field = maxInt(u24); |
| 323 | assert(ptr.a == @maxValue(u16)); | 325 | assert(ptr.a == maxInt(u16)); |
| 324 | assert(ptr.b[0].field == @maxValue(u24)); | 326 | assert(ptr.b[0].field == maxInt(u24)); |
| 325 | assert(ptr.b[1].field == @maxValue(u24)); | 327 | assert(ptr.b[1].field == maxInt(u24)); |
| 326 | assert(ptr.c == 0); | 328 | assert(ptr.c == 0); |
| 327 | 329 | ||
| 328 | ptr.c = @maxValue(u16); | 330 | ptr.c = maxInt(u16); |
| 329 | assert(ptr.a == @maxValue(u16)); | 331 | assert(ptr.a == maxInt(u16)); |
| 330 | assert(ptr.b[0].field == @maxValue(u24)); | 332 | assert(ptr.b[0].field == maxInt(u24)); |
| 331 | assert(ptr.b[1].field == @maxValue(u24)); | 333 | assert(ptr.b[1].field == maxInt(u24)); |
| 332 | assert(ptr.c == @maxValue(u16)); | 334 | assert(ptr.c == maxInt(u16)); |
| 333 | 335 | ||
| 334 | assert(bytes[bytes.len - 1] == 0xaa); | 336 | assert(bytes[bytes.len - 1] == 0xaa); |
| 335 | } | 337 | } |
test/compile_errors.zig+3-3| ... | @@ -535,12 +535,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -535,12 +535,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 535 | ); | 535 | ); |
| 536 | 536 | ||
| 537 | cases.add( | 537 | cases.add( |
| 538 | "optional pointer to void in extern struct", | 538 | "bit count of @IntType too large", |
| 539 | \\comptime { | 539 | \\comptime { |
| 540 | \\ _ = @IntType(false, @maxValue(u32) + 1); | 540 | \\ _ = @IntType(false, @import("std").math.maxInt(u32) + 1); |
| 541 | \\} | 541 | \\} |
| 542 | , | 542 | , |
| 543 | ".tmp_source.zig:2:40: error: integer value 4294967296 cannot be implicitly casted to type 'u32'", | 543 | ".tmp_source.zig:2:57: error: integer value 4294967296 cannot be implicitly casted to type 'u32'", |
| 544 | ); | 544 | ); |
| 545 | 545 | ||
| 546 | cases.add( | 546 | cases.add( |
test/standalone/brace_expansion/main.zig+2-1| ... | @@ -5,6 +5,7 @@ const debug = std.debug; | ... | @@ -5,6 +5,7 @@ const debug = std.debug; |
| 5 | const assert = debug.assert; | 5 | const assert = debug.assert; |
| 6 | const Buffer = std.Buffer; | 6 | const Buffer = std.Buffer; |
| 7 | const ArrayList = std.ArrayList; | 7 | const ArrayList = std.ArrayList; |
| 8 | const maxInt = std.math.maxInt; | ||
| 8 | 9 | ||
| 9 | const Token = union(enum).{ | 10 | const Token = union(enum).{ |
| 10 | Word: []const u8, | 11 | Word: []const u8, |
| ... | @@ -192,7 +193,7 @@ pub fn main() !void { | ... | @@ -192,7 +193,7 @@ pub fn main() !void { |
| 192 | defer stdin_buf.deinit(); | 193 | defer stdin_buf.deinit(); |
| 193 | 194 | ||
| 194 | var stdin_adapter = stdin_file.inStream(); | 195 | var stdin_adapter = stdin_file.inStream(); |
| 195 | try stdin_adapter.stream.readAllBuffer(&stdin_buf, @maxValue(usize)); | 196 | try stdin_adapter.stream.readAllBuffer(&stdin_buf, maxInt(usize)); |
| 196 | 197 | ||
| 197 | var result_buf = try Buffer.initSize(global_allocator, 0); | 198 | var result_buf = try Buffer.initSize(global_allocator, 0); |
| 198 | defer result_buf.deinit(); | 199 | defer result_buf.deinit(); |