authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-10-26 14:59:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-10-26 15:01:51-04:00
log2b395d4ede2d8ef356c54e1c7c09da88c634be11
treeddb9806afc26bc55554e20066b29d076bec71f79
parent40b7652a6da135aed68a0067f2de60b8b276713c
signaturelock-open Commit is signed but in an unrecognized format.

remove @minValue,@maxValue; add std.math.minInt,maxInt

closes #1466 closes #1476

55 files changed, 310 insertions(+), 398 deletions(-)

doc/langref.html.in+18-30
......@@ -827,7 +827,7 @@ a +%= b{#endsyntax#}</pre></td>
827827 </ul>
828828 </td>
829829 <td>
830 <pre>{#syntax#}u32(@maxValue(u32)) +% 1 == 0{#endsyntax#}</pre>
830 <pre>{#syntax#}u32(std.math.maxInt(u32)) +% 1 == 0{#endsyntax#}</pre>
831831 </td>
832832 </tr>
833833 <tr>
......@@ -866,7 +866,7 @@ a -%= b{#endsyntax#}</pre></td>
866866 </ul>
867867 </td>
868868 <td>
869 <pre>{#syntax#}u32(0) -% 1 == @maxValue(u32){#endsyntax#}</pre>
869 <pre>{#syntax#}u32(0) -% 1 == std.math.maxInt(u32){#endsyntax#}</pre>
870870 </td>
871871 </tr>
872872 <tr>
......@@ -901,7 +901,7 @@ a -%= b{#endsyntax#}</pre></td>
901901 </ul>
902902 </td>
903903 <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>
905905 </td>
906906 </tr>
907907 <tr>
......@@ -3298,6 +3298,9 @@ const err = (error.{FileNotFound}).FileNotFound;
32983298 Here is a function to parse a string into a 64-bit integer:
32993299 </p>
33003300 {#code_begin|test#}
3301const std = @import("std");
3302const maxInt = std.math.maxInt;
3303
33013304pub fn parseU64(buf: []const u8, radix: u8) !u64 {
33023305 var x: u64 = 0;
33033306
......@@ -3327,13 +3330,13 @@ fn charToDigit(c: u8) u8 {
33273330 '0' ... '9' => c - '0',
33283331 'A' ... 'Z' => c - 'A' + 10,
33293332 'a' ... 'z' => c - 'a' + 10,
3330 else => @maxValue(u8),
3333 else => maxInt(u8),
33313334 };
33323335}
33333336
33343337test "parse u64" {
33353338 const result = try parseU64("1234", 10);
3336 @import("std").debug.assert(result == 1234);
3339 std.debug.assert(result == 1234);
33373340}
33383341 {#code_end#}
33393342 <p>
......@@ -5539,7 +5542,7 @@ test "main" {
55395542 <p>
55405543 Floored division. Rounds toward negative infinity. For unsigned integers it is
55415544 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#}.
55435546 </p>
55445547 <ul>
55455548 <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
......@@ -5553,7 +5556,7 @@ test "main" {
55535556 <p>
55545557 Truncated division. Rounds toward zero. For unsigned integers it is
55555558 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#}.
55575560 </p>
55585561 <ul>
55595562 <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
......@@ -5816,15 +5819,6 @@ fn add(a: i32, b: i32) i32 { return a + b; }
58165819 This function returns an integer type with the given signness and bit count.
58175820 </p>
58185821 {#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#}
58285822 {#header_open|@memberCount#}
58295823 <pre>{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}</pre>
58305824 <p>
......@@ -5885,15 +5879,6 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);{#endsyntax#}</pre>
58855879 <p>There is also a standard library function for this:</p>
58865880 <pre>{#syntax#}const mem = @import("std").mem;
58875881mem.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>
58975882 {#header_close#}
58985883 {#header_open|@mod#}
58995884 <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>
......@@ -6688,7 +6673,7 @@ pub fn main() void {
66886673}
66896674 {#code_end#}
66906675 <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#}.
66926677 </p>
66936678 {#header_close#}
66946679 {#header_open|Cast Truncates Data#}
......@@ -6810,14 +6795,17 @@ pub fn main() void {
68106795 <li>{#syntax#}*%{#endsyntax#} (wraparound multiplication)</li>
68116796 </ul>
68126797 {#code_begin|test#}
6813const assert = @import("std").debug.assert;
6798const std = @import("std");
6799const assert = std.debug.assert;
6800const minInt = std.math.minInt;
6801const maxInt = std.math.maxInt;
68146802
68156803test "wraparound addition and subtraction" {
6816 const x: i32 = @maxValue(i32);
6804 const x: i32 = maxInt(i32);
68176805 const min_val = x +% 1;
6818 assert(min_val == @minValue(i32));
6806 assert(min_val == minInt(i32));
68196807 const max_val = min_val -% 1;
6820 assert(max_val == @maxValue(i32));
6808 assert(max_val == maxInt(i32));
68216809}
68226810 {#code_end#}
68236811 {#header_close#}
src-self-hosted/codegen.zig+4-3
......@@ -10,6 +10,7 @@ const Scope = @import("scope.zig").Scope;
1010const event = std.event;
1111const assert = std.debug.assert;
1212const DW = std.dwarf;
13const maxInt = std.math.maxInt;
1314
1415pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) !void {
1516 fn_val.base.ref();
......@@ -362,15 +363,15 @@ fn addLLVMAttrInt(
362363}
363364
364365fn 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);
366367}
367368
368369fn 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);
370371}
371372
372373fn 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);
374375}
375376
376377fn renderLoadUntyped(
src/all_types.hpp-16
......@@ -1343,8 +1343,6 @@ enum BuiltinFnId {
13431343 BuiltinFnIdMemset,
13441344 BuiltinFnIdSizeof,
13451345 BuiltinFnIdAlignOf,
1346 BuiltinFnIdMaxValue,
1347 BuiltinFnIdMinValue,
13481346 BuiltinFnIdMemberCount,
13491347 BuiltinFnIdMemberType,
13501348 BuiltinFnIdMemberName,
......@@ -2081,8 +2079,6 @@ enum IrInstructionId {
20812079 IrInstructionIdCUndef,
20822080 IrInstructionIdArrayLen,
20832081 IrInstructionIdRef,
2084 IrInstructionIdMinValue,
2085 IrInstructionIdMaxValue,
20862082 IrInstructionIdCompileErr,
20872083 IrInstructionIdCompileLog,
20882084 IrInstructionIdErrName,
......@@ -2609,18 +2605,6 @@ struct IrInstructionRef {
26092605 bool is_volatile;
26102606};
26112607
2612struct IrInstructionMinValue {
2613 IrInstruction base;
2614
2615 IrInstruction *value;
2616};
2617
2618struct IrInstructionMaxValue {
2619 IrInstruction base;
2620
2621 IrInstruction *value;
2622};
2623
26242608struct IrInstructionCompileErr {
26252609 IrInstruction base;
26262610
src/codegen.cpp-4
......@@ -5100,8 +5100,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
51005100 case IrInstructionIdSizeOf:
51015101 case IrInstructionIdSwitchTarget:
51025102 case IrInstructionIdContainerInitFields:
5103 case IrInstructionIdMinValue:
5104 case IrInstructionIdMaxValue:
51055103 case IrInstructionIdCompileErr:
51065104 case IrInstructionIdCompileLog:
51075105 case IrInstructionIdArrayLen:
......@@ -6651,8 +6649,6 @@ static void define_builtin_fns(CodeGen *g) {
66516649 create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3);
66526650 create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1);
66536651 create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1);
6654 create_builtin_fn(g, BuiltinFnIdMaxValue, "maxValue", 1);
6655 create_builtin_fn(g, BuiltinFnIdMinValue, "minValue", 1);
66566652 create_builtin_fn(g, BuiltinFnIdMemberCount, "memberCount", 1);
66576653 create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2);
66586654 create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2);
src/ir.cpp-120
......@@ -495,14 +495,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) {
495495 return IrInstructionIdUnionInit;
496496}
497497
498static constexpr IrInstructionId ir_instruction_id(IrInstructionMinValue *) {
499 return IrInstructionIdMinValue;
500}
501
502static constexpr IrInstructionId ir_instruction_id(IrInstructionMaxValue *) {
503 return IrInstructionIdMaxValue;
504}
505
506498static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {
507499 return IrInstructionIdCompileErr;
508500}
......@@ -1693,24 +1685,6 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source
16931685 return &instruction->base;
16941686}
16951687
1696static 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
1705static 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
17141688static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
17151689 IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node);
17161690 instruction->msg = msg;
......@@ -3813,26 +3787,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
38133787 IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
38143788 return ir_lval_wrap(irb, scope, c_undef, lval);
38153789 }
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 }
38363790 case BuiltinFnIdCompileErr:
38373791 {
38383792 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
1640716361 instruction->field_count, instruction->fields);
1640816362}
1640916363
16410static 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
16466static 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
16472static 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
1647816364static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,
1647916365 IrInstructionCompileErr *instruction)
1648016366{
......@@ -21052,10 +20938,6 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio
2105220938 return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction);
2105320939 case IrInstructionIdContainerInitFields:
2105420940 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);
2105920941 case IrInstructionIdCompileErr:
2106020942 return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction);
2106120943 case IrInstructionIdCompileLog:
......@@ -21399,8 +21281,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2139921281 case IrInstructionIdSwitchTarget:
2140021282 case IrInstructionIdUnionTag:
2140121283 case IrInstructionIdRef:
21402 case IrInstructionIdMinValue:
21403 case IrInstructionIdMaxValue:
2140421284 case IrInstructionIdEmbedFile:
2140521285 case IrInstructionIdTruncate:
2140621286 case IrInstructionIdIntType:
src/ir_print.cpp-18
......@@ -565,18 +565,6 @@ static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {
565565 ir_print_other_instruction(irp, instruction->value);
566566}
567567
568static 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
574static 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
580568static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {
581569 fprintf(irp->f, "@compileError(");
582570 ir_print_other_instruction(irp, instruction->msg);
......@@ -1480,12 +1468,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
14801468 case IrInstructionIdRef:
14811469 ir_print_ref(irp, (IrInstructionRef *)instruction);
14821470 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;
14891471 case IrInstructionIdCompileErr:
14901472 ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);
14911473 break;
std/crypto/chacha20.zig+3-2
......@@ -5,6 +5,7 @@ const mem = std.mem;
55const endian = std.endian;
66const assert = std.debug.assert;
77const builtin = @import("builtin");
8const maxInt = std.math.maxInt;
89
910const QuarterRound = struct.{
1011 a: usize,
......@@ -111,7 +112,7 @@ fn chaCha20_internal(out: []u8, in: []const u8, key: [8]u32, counter: [4]u32) vo
111112/// counter, nonce, and key.
112113pub fn chaCha20IETF(out: []u8, in: []const u8, counter: u32, key: [32]u8, nonce: [12]u8) void {
113114 assert(in.len >= out.len);
114 assert((in.len >> 6) + counter <= @maxValue(u32));
115 assert((in.len >> 6) + counter <= maxInt(u32));
115116
116117 var k: [8]u32 = undefined;
117118 var c: [4]u32 = undefined;
......@@ -161,7 +162,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
161162 const big_block = (block_size << 32);
162163
163164 // 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) {
165166 chaCha20_internal(out[cursor..big_block], in[cursor..big_block], k, c);
166167 cursor = big_block - cursor;
167168 c[1] += 1;
std/debug/index.zig+3-2
......@@ -11,6 +11,7 @@ const pdb = std.pdb;
1111const windows = os.windows;
1212const ArrayList = std.ArrayList;
1313const builtin = @import("builtin");
14const maxInt = std.math.maxInt;
1415
1516pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator;
1617pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator;
......@@ -842,7 +843,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
842843 if (word & (u32(1) << bit_i) != 0) {
843844 try list.append(word_i * 32 + bit_i);
844845 }
845 if (bit_i == @maxValue(u5)) break;
846 if (bit_i == maxInt(u5)) break;
846847 }
847848 }
848849 return list.toOwnedSlice();
......@@ -1939,7 +1940,7 @@ fn findCompileUnit(st: *DebugInfo, target_address: u64) !*const CompileUnit {
19391940 if (begin_addr == 0 and end_addr == 0) {
19401941 break;
19411942 }
1942 if (begin_addr == @maxValue(usize)) {
1943 if (begin_addr == maxInt(usize)) {
19431944 base_address = begin_addr;
19441945 continue;
19451946 }
std/dynamic_library.zig+3-2
......@@ -10,6 +10,7 @@ const elf = std.elf;
1010const linux = os.linux;
1111const windows = os.windows;
1212const win_util = @import("os/windows/util.zig");
13const maxInt = std.math.maxInt;
1314
1415pub const DynLib = switch (builtin.os) {
1516 Os.linux => LinuxDynLib,
......@@ -80,7 +81,7 @@ pub const ElfLib = struct.{
8081 const elf_addr = @ptrToInt(bytes.ptr);
8182 var ph_addr: usize = elf_addr + eh.e_phoff;
8283
83 var base: usize = @maxValue(usize);
84 var base: usize = maxInt(usize);
8485 var maybe_dynv: ?[*]usize = null;
8586 {
8687 var i: usize = 0;
......@@ -97,7 +98,7 @@ pub const ElfLib = struct.{
9798 }
9899 }
99100 const dynv = maybe_dynv orelse return error.MissingDynamicLinkingInformation;
100 if (base == @maxValue(usize)) return error.BaseNotFound;
101 if (base == maxInt(usize)) return error.BaseNotFound;
101102
102103 var maybe_strings: ?[*]u8 = null;
103104 var maybe_syms: ?[*]elf.Sym = null;
std/event/loop.zig+2-1
......@@ -8,6 +8,7 @@ const fs = std.event.fs;
88const os = std.os;
99const posix = os.posix;
1010const windows = os.windows;
11const maxInt = std.math.maxInt;
1112
1213pub const Loop = struct.{
1314 allocator: *mem.Allocator,
......@@ -317,7 +318,7 @@ pub const Loop = struct.{
317318 windows.INVALID_HANDLE_VALUE,
318319 null,
319320 undefined,
320 @maxValue(windows.DWORD),
321 maxInt(windows.DWORD),
321322 );
322323 errdefer os.close(self.os_data.io_port);
323324
std/heap.zig+2-1
......@@ -6,6 +6,7 @@ const os = std.os;
66const builtin = @import("builtin");
77const Os = builtin.Os;
88const c = std.c;
9const maxInt = std.math.maxInt;
910
1011const Allocator = mem.Allocator;
1112
......@@ -567,7 +568,7 @@ fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !voi
567568fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
568569 //Maybe a platform's page_size is actually the same as or
569570 // very near usize?
570 if (os.page_size << 2 > @maxValue(usize)) return;
571 if (os.page_size << 2 > maxInt(usize)) return;
571572
572573 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
573574 const large_align = u29(os.page_size << 2);
std/json.zig+2-1
......@@ -5,6 +5,7 @@
55const std = @import("index.zig");
66const debug = std.debug;
77const mem = std.mem;
8const maxInt = std.math.maxInt;
89
910// A single token slice into the parent string.
1011//
......@@ -107,7 +108,7 @@ pub const StreamingParser = struct.{
107108
108109 const object_bit = 0;
109110 const array_bit = 1;
110 const max_stack_size = @maxValue(u8);
111 const max_stack_size = maxInt(u8);
111112
112113 pub fn init() StreamingParser {
113114 var p: StreamingParser = undefined;
std/math/asinh.zig+2-1
......@@ -7,6 +7,7 @@
77const std = @import("../index.zig");
88const math = std.math;
99const assert = std.debug.assert;
10const maxInt = std.math.maxInt;
1011
1112pub fn asinh(x: var) @typeOf(x) {
1213 const T = @typeOf(x);
......@@ -55,7 +56,7 @@ fn asinh64(x: f64) f64 {
5556 const e = (u >> 52) & 0x7FF;
5657 const s = u >> 63;
5758
58 var rx = @bitCast(f64, u & (@maxValue(u64) >> 1)); // |x|
59 var rx = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|
5960
6061 if (math.isNegativeInf(x)) {
6162 return x;
std/math/atanh.zig+2-1
......@@ -7,6 +7,7 @@
77const std = @import("../index.zig");
88const math = std.math;
99const assert = std.debug.assert;
10const maxInt = std.math.maxInt;
1011
1112pub fn atanh(x: var) @typeOf(x) {
1213 const T = @typeOf(x);
......@@ -52,7 +53,7 @@ fn atanh_64(x: f64) f64 {
5253 const e = (u >> 52) & 0x7FF;
5354 const s = u >> 63;
5455
55 var y = @bitCast(f64, u & (@maxValue(u64) >> 1)); // |x|
56 var y = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|
5657
5758 if (y == 1.0) {
5859 return math.copysign(f64, math.inf(f64), x);
std/math/big/int.zig+31-29
......@@ -5,6 +5,8 @@ const math = std.math;
55const mem = std.mem;
66const Allocator = mem.Allocator;
77const ArrayList = std.ArrayList;
8const maxInt = std.math.maxInt;
9const minInt = std.math.minInt;
810
911const TypeId = builtin.TypeId;
1012
......@@ -212,7 +214,7 @@ pub const Int = struct.{
212214 self.positive = value >= 0;
213215 self.len = req_limbs;
214216
215 if (w_value <= @maxValue(Limb)) {
217 if (w_value <= maxInt(Limb)) {
216218 self.limbs[0] = w_value;
217219 } else {
218220 const mask = (1 << Limb.bit_count) - 1;
......@@ -267,7 +269,7 @@ pub const Int = struct.{
267269 if (math.cast(T, r)) |ok| {
268270 return -ok;
269271 } else |_| {
270 return @minValue(T);
272 return minInt(T);
271273 }
272274 }
273275 }
......@@ -371,7 +373,7 @@ pub const Int = struct.{
371373 }
372374 } // Non power-of-two: batch divisions per word size.
373375 else {
374 const digits_per_limb = math.log(Limb, base, @maxValue(Limb));
376 const digits_per_limb = math.log(Limb, base, maxInt(Limb));
375377 var limb_base: Limb = 1;
376378 var j: usize = 0;
377379 while (j < digits_per_limb) : (j += 1) {
......@@ -717,7 +719,7 @@ pub const Int = struct.{
717719 const c3: Limb = @boolToInt(@addWithOverflow(Limb, r1, r2, &r1));
718720
719721 // 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.
721723 carry.* = c1 + c2 + c3;
722724
723725 return r1;
......@@ -873,11 +875,11 @@ pub const Int = struct.{
873875 while (i > t) : (i -= 1) {
874876 // 3.1
875877 if (x.limbs[i] == y.limbs[t]) {
876 q.limbs[i - t - 1] = @maxValue(Limb);
878 q.limbs[i - t - 1] = maxInt(Limb);
877879 } else {
878880 const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);
879881 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);
881883 }
882884
883885 // 3.2
......@@ -1081,7 +1083,7 @@ test "big.int comptime_int set" {
10811083
10821084 comptime var i: usize = 0;
10831085 inline while (i < s_limb_count) : (i += 1) {
1084 const result = Limb(s & @maxValue(Limb));
1086 const result = Limb(s & maxInt(Limb));
10851087 s >>= Limb.bit_count / 2;
10861088 s >>= Limb.bit_count / 2;
10871089 debug.assert(a.limbs[i] == result);
......@@ -1403,7 +1405,7 @@ test "big.int compare similar" {
14031405}
14041406
14051407test "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);
14071409 var b = try Int.initSet(al, 1);
14081410
14091411 debug.assert(a.cmpAbs(b) == 1);
......@@ -1457,16 +1459,16 @@ test "big.int add single-single" {
14571459}
14581460
14591461test "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);
14611463 var b = try Int.initSet(al, 1);
14621464
14631465 var c = try Int.init(al);
14641466
14651467 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);
14671469
14681470 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);
14701472}
14711473
14721474test "big.int add multi-multi" {
......@@ -1533,13 +1535,13 @@ test "big.int sub single-single" {
15331535}
15341536
15351537test "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);
15371539 var b = try Int.initSet(al, 1);
15381540
15391541 var c = try Int.init(al);
15401542 try c.sub(a, b);
15411543
1542 debug.assert((try c.to(Limb)) == @maxValue(Limb));
1544 debug.assert((try c.to(Limb)) == maxInt(Limb));
15431545}
15441546
15451547test "big.int sub multi-multi" {
......@@ -1600,13 +1602,13 @@ test "big.int mul single-single" {
16001602}
16011603
16021604test "big.int mul multi-single" {
1603 var a = try Int.initSet(al, @maxValue(Limb));
1605 var a = try Int.initSet(al, maxInt(Limb));
16041606 var b = try Int.initSet(al, 2);
16051607
16061608 var c = try Int.init(al);
16071609 try c.mul(a, b);
16081610
1609 debug.assert((try c.to(DoubleLimb)) == 2 * @maxValue(Limb));
1611 debug.assert((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
16101612}
16111613
16121614test "big.int mul multi-multi" {
......@@ -1622,29 +1624,29 @@ test "big.int mul multi-multi" {
16221624}
16231625
16241626test "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));
16261628 var b = try Int.initSet(al, 2);
16271629
16281630 try a.mul(a, b);
16291631
1630 debug.assert((try a.to(DoubleLimb)) == 2 * @maxValue(Limb));
1632 debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
16311633}
16321634
16331635test "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));
16351637 var b = try Int.initSet(al, 2);
16361638
16371639 try a.mul(b, a);
16381640
1639 debug.assert((try a.to(DoubleLimb)) == 2 * @maxValue(Limb));
1641 debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
16401642}
16411643
16421644test "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));
16441646
16451647 try a.mul(a, a);
16461648
1647 debug.assert((try a.to(DoubleLimb)) == @maxValue(Limb) * @maxValue(Limb));
1649 debug.assert((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
16481650}
16491651
16501652test "big.int mul a*0" {
......@@ -2047,8 +2049,8 @@ test "big.int bitwise and simple" {
20472049}
20482050
20492051test "big.int bitwise and multi-limb" {
2050 var a = try Int.initSet(al, @maxValue(Limb) + 1);
2051 var b = try Int.initSet(al, @maxValue(Limb));
2052 var a = try Int.initSet(al, maxInt(Limb) + 1);
2053 var b = try Int.initSet(al, maxInt(Limb));
20522054
20532055 try a.bitAnd(a, b);
20542056
......@@ -2065,12 +2067,12 @@ test "big.int bitwise xor simple" {
20652067}
20662068
20672069test "big.int bitwise xor multi-limb" {
2068 var a = try Int.initSet(al, @maxValue(Limb) + 1);
2069 var b = try Int.initSet(al, @maxValue(Limb));
2070 var a = try Int.initSet(al, maxInt(Limb) + 1);
2071 var b = try Int.initSet(al, maxInt(Limb));
20702072
20712073 try a.bitXor(a, b);
20722074
2073 debug.assert((try a.to(DoubleLimb)) == (@maxValue(Limb) + 1) ^ @maxValue(Limb));
2075 debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
20742076}
20752077
20762078test "big.int bitwise or simple" {
......@@ -2083,13 +2085,13 @@ test "big.int bitwise or simple" {
20832085}
20842086
20852087test "big.int bitwise or multi-limb" {
2086 var a = try Int.initSet(al, @maxValue(Limb) + 1);
2087 var b = try Int.initSet(al, @maxValue(Limb));
2088 var a = try Int.initSet(al, maxInt(Limb) + 1);
2089 var b = try Int.initSet(al, maxInt(Limb));
20882090
20892091 try a.bitOr(a, b);
20902092
20912093 // 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));
20932095}
20942096
20952097test "big.int var args" {
std/math/copysign.zig+4-3
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const math = std.math;
33const assert = std.debug.assert;
4const maxInt = std.math.maxInt;
45
56pub fn copysign(comptime T: type, x: T, y: T) T {
67 return switch (T) {
......@@ -15,7 +16,7 @@ fn copysign16(x: f16, y: f16) f16 {
1516 const ux = @bitCast(u16, x);
1617 const uy = @bitCast(u16, y);
1718
18 const h1 = ux & (@maxValue(u16) / 2);
19 const h1 = ux & (maxInt(u16) / 2);
1920 const h2 = uy & (u16(1) << 15);
2021 return @bitCast(f16, h1 | h2);
2122}
......@@ -24,7 +25,7 @@ fn copysign32(x: f32, y: f32) f32 {
2425 const ux = @bitCast(u32, x);
2526 const uy = @bitCast(u32, y);
2627
27 const h1 = ux & (@maxValue(u32) / 2);
28 const h1 = ux & (maxInt(u32) / 2);
2829 const h2 = uy & (u32(1) << 31);
2930 return @bitCast(f32, h1 | h2);
3031}
......@@ -33,7 +34,7 @@ fn copysign64(x: f64, y: f64) f64 {
3334 const ux = @bitCast(u64, x);
3435 const uy = @bitCast(u64, y);
3536
36 const h1 = ux & (@maxValue(u64) / 2);
37 const h1 = ux & (maxInt(u64) / 2);
3738 const h2 = uy & (u64(1) << 63);
3839 return @bitCast(f64, h1 | h2);
3940}
std/math/cosh.zig+2-1
......@@ -9,6 +9,7 @@ const std = @import("../index.zig");
99const math = std.math;
1010const expo2 = @import("expo2.zig").expo2;
1111const assert = std.debug.assert;
12const maxInt = std.math.maxInt;
1213
1314pub fn cosh(x: var) @typeOf(x) {
1415 const T = @typeOf(x);
......@@ -50,7 +51,7 @@ fn cosh32(x: f32) f32 {
5051fn cosh64(x: f64) f64 {
5152 const u = @bitCast(u64, x);
5253 const w = @intCast(u32, u >> 32);
53 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
54 const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
5455
5556 // TODO: Shouldn't need this explicit check.
5657 if (x == 0.0) {
std/math/fabs.zig+2-1
......@@ -6,6 +6,7 @@
66const std = @import("../index.zig");
77const math = std.math;
88const assert = std.debug.assert;
9const maxInt = std.math.maxInt;
910
1011pub fn fabs(x: var) @typeOf(x) {
1112 const T = @typeOf(x);
......@@ -31,7 +32,7 @@ fn fabs32(x: f32) f32 {
3132
3233fn fabs64(x: f64) f64 {
3334 var u = @bitCast(u64, x);
34 u &= @maxValue(u64) >> 1;
35 u &= maxInt(u64) >> 1;
3536 return @bitCast(f64, u);
3637}
3738
std/math/hypot.zig+5-4
......@@ -8,6 +8,7 @@
88const std = @import("../index.zig");
99const math = std.math;
1010const assert = std.debug.assert;
11const maxInt = std.math.maxInt;
1112
1213pub fn hypot(comptime T: type, x: T, y: T) T {
1314 return switch (T) {
......@@ -21,8 +22,8 @@ fn hypot32(x: f32, y: f32) f32 {
2122 var ux = @bitCast(u32, x);
2223 var uy = @bitCast(u32, y);
2324
24 ux &= @maxValue(u32) >> 1;
25 uy &= @maxValue(u32) >> 1;
25 ux &= maxInt(u32) >> 1;
26 uy &= maxInt(u32) >> 1;
2627 if (ux < uy) {
2728 const tmp = ux;
2829 ux = uy;
......@@ -65,8 +66,8 @@ fn hypot64(x: f64, y: f64) f64 {
6566 var ux = @bitCast(u64, x);
6667 var uy = @bitCast(u64, y);
6768
68 ux &= @maxValue(u64) >> 1;
69 uy &= @maxValue(u64) >> 1;
69 ux &= maxInt(u64) >> 1;
70 uy &= maxInt(u64) >> 1;
7071 if (ux < uy) {
7172 const tmp = ux;
7273 ux = uy;
std/math/ilogb.zig+18-16
......@@ -1,12 +1,14 @@
11// Special Cases:
22//
3// - ilogb(+-inf) = @maxValue(i32)
4// - ilogb(0) = @maxValue(i32)
5// - ilogb(nan) = @maxValue(i32)
3// - ilogb(+-inf) = maxInt(i32)
4// - ilogb(0) = maxInt(i32)
5// - ilogb(nan) = maxInt(i32)
66
77const std = @import("../index.zig");
88const math = std.math;
99const assert = std.debug.assert;
10const maxInt = std.math.maxInt;
11const minInt = std.math.minInt;
1012
1113pub fn ilogb(x: var) i32 {
1214 const T = @typeOf(x);
......@@ -18,7 +20,7 @@ pub fn ilogb(x: var) i32 {
1820}
1921
2022// NOTE: Should these be exposed publically?
21const fp_ilogbnan = -1 - i32(@maxValue(u32) >> 1);
23const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1);
2224const fp_ilogb0 = fp_ilogbnan;
2325
2426fn ilogb32(x: f32) i32 {
......@@ -27,7 +29,7 @@ fn ilogb32(x: f32) i32 {
2729
2830 // TODO: We should be able to merge this with the lower check.
2931 if (math.isNan(x)) {
30 return @maxValue(i32);
32 return maxInt(i32);
3133 }
3234
3335 if (e == 0) {
......@@ -50,7 +52,7 @@ fn ilogb32(x: f32) i32 {
5052 if (u << 9 != 0) {
5153 return fp_ilogbnan;
5254 } else {
53 return @maxValue(i32);
55 return maxInt(i32);
5456 }
5557 }
5658
......@@ -62,7 +64,7 @@ fn ilogb64(x: f64) i32 {
6264 var e = @intCast(i32, (u >> 52) & 0x7FF);
6365
6466 if (math.isNan(x)) {
65 return @maxValue(i32);
67 return maxInt(i32);
6668 }
6769
6870 if (e == 0) {
......@@ -85,7 +87,7 @@ fn ilogb64(x: f64) i32 {
8587 if (u << 12 != 0) {
8688 return fp_ilogbnan;
8789 } else {
88 return @maxValue(i32);
90 return maxInt(i32);
8991 }
9092 }
9193
......@@ -116,15 +118,15 @@ test "math.ilogb64" {
116118}
117119
118120test "math.ilogb32.special" {
119 assert(ilogb32(math.inf(f32)) == @maxValue(i32));
120 assert(ilogb32(-math.inf(f32)) == @maxValue(i32));
121 assert(ilogb32(0.0) == @minValue(i32));
122 assert(ilogb32(math.nan(f32)) == @maxValue(i32));
121 assert(ilogb32(math.inf(f32)) == maxInt(i32));
122 assert(ilogb32(-math.inf(f32)) == maxInt(i32));
123 assert(ilogb32(0.0) == minInt(i32));
124 assert(ilogb32(math.nan(f32)) == maxInt(i32));
123125}
124126
125127test "math.ilogb64.special" {
126 assert(ilogb64(math.inf(f64)) == @maxValue(i32));
127 assert(ilogb64(-math.inf(f64)) == @maxValue(i32));
128 assert(ilogb64(0.0) == @minValue(i32));
129 assert(ilogb64(math.nan(f64)) == @maxValue(i32));
128 assert(ilogb64(math.inf(f64)) == maxInt(i32));
129 assert(ilogb64(-math.inf(f64)) == maxInt(i32));
130 assert(ilogb64(0.0) == minInt(i32));
131 assert(ilogb64(math.nan(f64)) == maxInt(i32));
130132}
std/math/index.zig+69-13
......@@ -382,7 +382,7 @@ pub fn absInt(x: var) !@typeOf(x) {
382382 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
383383 comptime assert(T.is_signed); // must pass a signed integer to absInt
384384
385 if (x == @minValue(@typeOf(x))) {
385 if (x == minInt(@typeOf(x))) {
386386 return error.Overflow;
387387 } else {
388388 @setRuntimeSafety(false);
......@@ -404,7 +404,7 @@ pub const absFloat = @import("fabs.zig").fabs;
404404pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
405405 @setRuntimeSafety(false);
406406 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;
408408 return @divTrunc(numerator, denominator);
409409}
410410
......@@ -425,7 +425,7 @@ fn testDivTrunc() void {
425425pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
426426 @setRuntimeSafety(false);
427427 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;
429429 return @divFloor(numerator, denominator);
430430}
431431
......@@ -446,7 +446,7 @@ fn testDivFloor() void {
446446pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
447447 @setRuntimeSafety(false);
448448 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;
450450 const result = @divTrunc(numerator, denominator);
451451 if (result * denominator != numerator) return error.UnexpectedRemainder;
452452 return result;
......@@ -530,8 +530,8 @@ test "math.absCast" {
530530 assert(absCast(i32(999)) == 999);
531531 assert(@typeOf(absCast(i32(999))) == u32);
532532
533 assert(absCast(i32(@minValue(i32))) == -@minValue(i32));
534 assert(@typeOf(absCast(i32(@minValue(i32)))) == u32);
533 assert(absCast(i32(minInt(i32))) == -minInt(i32));
534 assert(@typeOf(absCast(i32(minInt(i32)))) == u32);
535535}
536536
537537/// Returns the negation of the integer parameter.
......@@ -540,9 +540,9 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
540540 if (@typeOf(x).is_signed) return negate(x);
541541
542542 const int = @IntType(true, @typeOf(x).bit_count);
543 if (x > -@minValue(int)) return error.Overflow;
543 if (x > -minInt(int)) return error.Overflow;
544544
545 if (x == -@minValue(int)) return @minValue(int);
545 if (x == -minInt(int)) return minInt(int);
546546
547547 return -@intCast(int, x);
548548}
......@@ -551,10 +551,10 @@ test "math.negateCast" {
551551 assert((negateCast(u32(999)) catch unreachable) == -999);
552552 assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
553553
554 assert((negateCast(u32(-@minValue(i32))) catch unreachable) == @minValue(i32));
555 assert(@typeOf(negateCast(u32(-@minValue(i32))) catch unreachable) == i32);
554 assert((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
555 assert(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
556556
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);
558558}
559559
560560/// Cast an integer to a different integer type. If the value doesn't fit,
......@@ -562,9 +562,9 @@ test "math.negateCast" {
562562pub fn cast(comptime T: type, x: var) (error.{Overflow}!T) {
563563 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
564564 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)) {
566566 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)) {
568568 return error.Overflow;
569569 } else {
570570 return @intCast(T, x);
......@@ -658,3 +658,59 @@ test "math.f64_min" {
658658 const fmin: f64 = f64_min;
659659 assert(@bitCast(u64, fmin) == f64_min_u64);
660660}
661
662pub 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
669pub 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
677test "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
710test "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 @@
11const std = @import("../index.zig");
22const math = std.math;
33const assert = std.debug.assert;
4const maxInt = std.math.maxInt;
45
56pub fn isFinite(x: var) bool {
67 const T = @typeOf(x);
......@@ -15,7 +16,7 @@ pub fn isFinite(x: var) bool {
1516 },
1617 f64 => {
1718 const bits = @bitCast(u64, x);
18 return bits & (@maxValue(u64) >> 1) < (0x7FF << 52);
19 return bits & (maxInt(u64) >> 1) < (0x7FF << 52);
1920 },
2021 else => {
2122 @compileError("isFinite not implemented for " ++ @typeName(T));
std/math/isinf.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const math = std.math;
33const assert = std.debug.assert;
4const maxInt = std.math.maxInt;
45
56pub fn isInf(x: var) bool {
67 const T = @typeOf(x);
......@@ -15,7 +16,7 @@ pub fn isInf(x: var) bool {
1516 },
1617 f64 => {
1718 const bits = @bitCast(u64, x);
18 return bits & (@maxValue(u64) >> 1) == (0x7FF << 52);
19 return bits & (maxInt(u64) >> 1) == (0x7FF << 52);
1920 },
2021 else => {
2122 @compileError("isInf not implemented for " ++ @typeName(T));
std/math/isnan.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const math = std.math;
33const assert = std.debug.assert;
4const maxInt = std.math.maxInt;
45
56pub fn isNan(x: var) bool {
67 const T = @typeOf(x);
......@@ -15,7 +16,7 @@ pub fn isNan(x: var) bool {
1516 },
1617 f64 => {
1718 const bits = @bitCast(u64, x);
18 return (bits & (@maxValue(u64) >> 1)) > (u64(0x7FF) << 52);
19 return (bits & (maxInt(u64) >> 1)) > (u64(0x7FF) << 52);
1920 },
2021 else => {
2122 @compileError("isNan not implemented for " ++ @typeName(T));
std/math/isnormal.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const math = std.math;
33const assert = std.debug.assert;
4const maxInt = std.math.maxInt;
45
56pub fn isNormal(x: var) bool {
67 const T = @typeOf(x);
......@@ -15,7 +16,7 @@ pub fn isNormal(x: var) bool {
1516 },
1617 f64 => {
1718 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);
1920 },
2021 else => {
2122 @compileError("isNormal not implemented for " ++ @typeName(T));
std/math/log10.zig+2-1
......@@ -10,6 +10,7 @@ const math = std.math;
1010const assert = std.debug.assert;
1111const builtin = @import("builtin");
1212const TypeId = builtin.TypeId;
13const maxInt = std.math.maxInt;
1314
1415pub fn log10(x: var) @typeOf(x) {
1516 const T = @typeOf(x);
......@@ -151,7 +152,7 @@ pub fn log10_64(x_: f64) f64 {
151152 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
152153 var hi = f - hfsq;
153154 var hii = @bitCast(u64, hi);
154 hii &= u64(@maxValue(u64)) << 32;
155 hii &= u64(maxInt(u64)) << 32;
155156 hi = @bitCast(f64, hii);
156157 const lo = f - hi - hfsq + s * (hfsq + R);
157158
std/math/log2.zig+2-1
......@@ -10,6 +10,7 @@ const math = std.math;
1010const assert = std.debug.assert;
1111const builtin = @import("builtin");
1212const TypeId = builtin.TypeId;
13const maxInt = std.math.maxInt;
1314
1415pub fn log2(x: var) @typeOf(x) {
1516 const T = @typeOf(x);
......@@ -151,7 +152,7 @@ pub fn log2_64(x_: f64) f64 {
151152 // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
152153 var hi = f - hfsq;
153154 var hii = @bitCast(u64, hi);
154 hii &= u64(@maxValue(u64)) << 32;
155 hii &= u64(maxInt(u64)) << 32;
155156 hi = @bitCast(f64, hii);
156157 const lo = f - hi - hfsq + s * (hfsq + R);
157158
std/math/modf.zig+2-1
......@@ -6,6 +6,7 @@
66const std = @import("../index.zig");
77const math = std.math;
88const assert = std.debug.assert;
9const maxInt = std.math.maxInt;
910
1011fn modf_result(comptime T: type) type {
1112 return struct.{
......@@ -101,7 +102,7 @@ fn modf64(x: f64) modf64_result {
101102 return result;
102103 }
103104
104 const mask = u64(@maxValue(u64) >> 12) >> @intCast(u6, e);
105 const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e);
105106 if (u & mask == 0) {
106107 result.ipart = x;
107108 result.fpart = @bitCast(f64, us);
std/math/sinh.zig+2-1
......@@ -9,6 +9,7 @@ const std = @import("../index.zig");
99const math = std.math;
1010const assert = std.debug.assert;
1111const expo2 = @import("expo2.zig").expo2;
12const maxInt = std.math.maxInt;
1213
1314pub fn sinh(x: var) @typeOf(x) {
1415 const T = @typeOf(x);
......@@ -56,7 +57,7 @@ fn sinh32(x: f32) f32 {
5657fn sinh64(x: f64) f64 {
5758 const u = @bitCast(u64, x);
5859 const w = @intCast(u32, u >> 32);
59 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
60 const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
6061
6162 if (x == 0.0 or math.isNan(x)) {
6263 return x;
std/math/sqrt.zig+2-1
......@@ -10,6 +10,7 @@ const math = std.math;
1010const assert = std.debug.assert;
1111const builtin = @import("builtin");
1212const TypeId = builtin.TypeId;
13const maxInt = std.math.maxInt;
1314
1415pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
1516 const T = @typeOf(x);
......@@ -17,7 +18,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
1718 TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128
1819 TypeId.Float => return @sqrt(T, x),
1920 TypeId.ComptimeInt => comptime {
20 if (x > @maxValue(u128)) {
21 if (x > maxInt(u128)) {
2122 @compileError("sqrt not implemented for comptime_int greater than 128 bits");
2223 }
2324 if (x < 0) {
std/math/tanh.zig+2-1
......@@ -9,6 +9,7 @@ const std = @import("../index.zig");
99const math = std.math;
1010const assert = std.debug.assert;
1111const expo2 = @import("expo2.zig").expo2;
12const maxInt = std.math.maxInt;
1213
1314pub fn tanh(x: var) @typeOf(x) {
1415 const T = @typeOf(x);
......@@ -69,7 +70,7 @@ fn tanh32(x: f32) f32 {
6970fn tanh64(x: f64) f64 {
7071 const u = @bitCast(u64, x);
7172 const w = @intCast(u32, u >> 32);
72 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
73 const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
7374
7475 var t: f64 = undefined;
7576
std/math/trunc.zig+3-2
......@@ -7,6 +7,7 @@
77const std = @import("../index.zig");
88const math = std.math;
99const assert = std.debug.assert;
10const maxInt = std.math.maxInt;
1011
1112pub fn trunc(x: var) @typeOf(x) {
1213 const T = @typeOf(x);
......@@ -29,7 +30,7 @@ fn trunc32(x: f32) f32 {
2930 e = 1;
3031 }
3132
32 m = u32(@maxValue(u32)) >> @intCast(u5, e);
33 m = u32(maxInt(u32)) >> @intCast(u5, e);
3334 if (u & m == 0) {
3435 return x;
3536 } else {
......@@ -50,7 +51,7 @@ fn trunc64(x: f64) f64 {
5051 e = 1;
5152 }
5253
53 m = u64(@maxValue(u64)) >> @intCast(u6, e);
54 m = u64(maxInt(u64)) >> @intCast(u6, e);
5455 if (u & m == 0) {
5556 return x;
5657 } else {
std/os/child_process.zig+5-4
......@@ -14,6 +14,7 @@ const builtin = @import("builtin");
1414const Os = builtin.Os;
1515const LinkedList = std.LinkedList;
1616const windows_util = @import("windows/util.zig");
17const maxInt = std.math.maxInt;
1718
1819const is_windows = builtin.os == Os.windows;
1920
......@@ -307,16 +308,16 @@ pub const ChildProcess = struct.{
307308 os.close(self.err_pipe[1]);
308309 }
309310
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
311312 // waitpid, so this write is guaranteed to be after the child
312313 // 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
314315 // an error code.
315 try writeIntFd(self.err_pipe[1], @maxValue(ErrInt));
316 try writeIntFd(self.err_pipe[1], maxInt(ErrInt));
316317 const err_int = try readIntFd(self.err_pipe[0]);
317318 // Here we potentially return the fork child's error
318319 // from the parent pid.
319 if (err_int != @maxValue(ErrInt)) {
320 if (err_int != maxInt(ErrInt)) {
320321 return @errSetCast(SpawnError, @intToError(err_int));
321322 }
322323
std/os/darwin.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const c = std.c;
33const assert = std.debug.assert;
4const maxInt = std.math.maxInt;
45
56pub use @import("darwin/errno.zig");
67
......@@ -45,7 +46,7 @@ pub const MAP_NOCACHE = 0x0400;
4546
4647/// don't reserve needed swap area
4748pub const MAP_NORESERVE = 0x0040;
48pub const MAP_FAILED = @maxValue(usize);
49pub const MAP_FAILED = maxInt(usize);
4950
5051/// [XSI] no hang in wait/no child to reap
5152pub const WNOHANG = 0x00000001;
std/os/file.zig+2-1
......@@ -9,6 +9,7 @@ const posix = os.posix;
99const windows = os.windows;
1010const Os = builtin.Os;
1111const windows_util = @import("windows/util.zig");
12const maxInt = std.math.maxInt;
1213
1314const is_posix = builtin.os != builtin.Os.windows;
1415const is_windows = builtin.os == builtin.Os.windows;
......@@ -385,7 +386,7 @@ pub const File = struct.{
385386 } else if (is_windows) {
386387 var index: usize = 0;
387388 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));
389390 var amt_read: windows.DWORD = undefined;
390391 if (windows.ReadFile(self.handle, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
391392 const err = windows.GetLastError();
std/os/linux/index.zig+4-3
......@@ -1,6 +1,7 @@
11const std = @import("../../index.zig");
22const assert = std.debug.assert;
33const builtin = @import("builtin");
4const maxInt = std.math.maxInt;
45const vdso = @import("vdso.zig");
56pub use switch (builtin.arch) {
67 builtin.Arch.x86_64 => @import("x86_64.zig"),
......@@ -38,7 +39,7 @@ pub const PROT_EXEC = 4;
3839pub const PROT_GROWSDOWN = 0x01000000;
3940pub const PROT_GROWSUP = 0x02000000;
4041
41pub const MAP_FAILED = @maxValue(usize);
42pub const MAP_FAILED = maxInt(usize);
4243pub const MAP_SHARED = 0x01;
4344pub const MAP_PRIVATE = 0x02;
4445pub const MAP_TYPE = 0x0f;
......@@ -1094,7 +1095,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
10941095
10951096const NSIG = 65;
10961097const sigset_t = [128 / @sizeOf(usize)]usize;
1097const all_mask = []usize.{@maxValue(usize)};
1098const all_mask = []usize.{maxInt(usize)};
10981099const app_mask = []usize.{0xfffffffc7fffffff};
10991100
11001101const k_sigaction = extern struct.{
......@@ -1111,7 +1112,7 @@ pub const Sigaction = struct.{
11111112 flags: u32,
11121113};
11131114
1114pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
1115pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
11151116pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
11161117pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
11171118pub const empty_sigset = []usize.{0} ** sigset_t.len;
std/os/linux/vdso.zig+3-2
......@@ -3,6 +3,7 @@ const elf = std.elf;
33const linux = std.os.linux;
44const cstr = std.cstr;
55const mem = std.mem;
6const maxInt = std.math.maxInt;
67
78pub fn lookup(vername: []const u8, name: []const u8) usize {
89 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 {
1314 const ph = @intToPtr(*elf.Phdr, ph_addr);
1415
1516 var maybe_dynv: ?[*]usize = null;
16 var base: usize = @maxValue(usize);
17 var base: usize = maxInt(usize);
1718 {
1819 var i: usize = 0;
1920 while (i < eh.e_phnum) : ({
......@@ -29,7 +30,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
2930 }
3031 }
3132 const dynv = maybe_dynv orelse return 0;
32 if (base == @maxValue(usize)) return 0;
33 if (base == maxInt(usize)) return 0;
3334
3435 var maybe_strings: ?[*]u8 = null;
3536 var maybe_syms: ?[*]elf.Sym = null;
std/os/windows/index.zig+6-5
......@@ -1,5 +1,6 @@
11const std = @import("../../index.zig");
22const assert = std.debug.assert;
3const maxInt = std.math.maxInt;
34
45pub use @import("advapi32.zig");
56pub use @import("kernel32.zig");
......@@ -53,17 +54,17 @@ pub const TRUE = 1;
5354pub const FALSE = 0;
5455
5556/// The standard input device. Initially, this is the console input buffer, CONIN$.
56pub const STD_INPUT_HANDLE = @maxValue(DWORD) - 10 + 1;
57pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
5758
5859/// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
59pub const STD_OUTPUT_HANDLE = @maxValue(DWORD) - 11 + 1;
60pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
6061
6162/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
62pub const STD_ERROR_HANDLE = @maxValue(DWORD) - 12 + 1;
63pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
6364
64pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, @maxValue(usize));
65pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
6566
66pub const INVALID_FILE_ATTRIBUTES = DWORD(@maxValue(DWORD));
67pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
6768
6869pub const OVERLAPPED = extern struct.{
6970 Internal: ULONG_PTR,
std/rand/index.zig+6-5
......@@ -20,6 +20,7 @@ const assert = std.debug.assert;
2020const mem = std.mem;
2121const math = std.math;
2222const ziggurat = @import("ziggurat.zig");
23const maxInt = std.math.maxInt;
2324
2425// When you need fast unbiased random numbers
2526pub const DefaultPrng = Xoroshiro128;
......@@ -39,7 +40,7 @@ pub const Random = struct.{
3940 return r.int(u1) != 0;
4041 }
4142
42 /// Returns a random int `i` such that `0 <= i <= @maxValue(T)`.
43 /// Returns a random int `i` such that `0 <= i <= maxInt(T)`.
4344 /// `i` is evenly distributed.
4445 pub fn int(r: *Random, comptime T: type) T {
4546 const UnsignedT = @IntType(false, T.bit_count);
......@@ -69,14 +70,14 @@ pub const Random = struct.{
6970 assert(T.is_signed == false);
7071 assert(0 < less_than);
7172
72 const last_group_size_minus_one: T = @maxValue(T) % less_than;
73 const last_group_size_minus_one: T = maxInt(T) % less_than;
7374 if (last_group_size_minus_one == less_than - 1) {
7475 // less_than is a power of two.
7576 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.
7778 return r.int(T) % less_than;
7879 }
79 const retry_zone_start = @maxValue(T) - last_group_size_minus_one;
80 const retry_zone_start = maxInt(T) - last_group_size_minus_one;
8081
8182 while (true) {
8283 const rand_val = r.int(T);
......@@ -91,7 +92,7 @@ pub const Random = struct.{
9192 /// for commentary on the runtime of this function.
9293 pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T {
9394 assert(T.is_signed == false);
94 if (at_most == @maxValue(T)) {
95 if (at_most == maxInt(T)) {
9596 // have the full range
9697 return r.int(T);
9798 }
std/special/builtin.zig+6-4
......@@ -1,14 +1,16 @@
11// These functions are provided when not linking against libc because LLVM
22// sometimes generates code that calls them.
33
4const std = @import("std");
45const builtin = @import("builtin");
6const maxInt = std.math.maxInt;
57
68// Avoid dragging in the runtime safety mechanisms into this .o file,
79// unless we're trying to test this file.
810pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
911 if (builtin.is_test) {
1012 @setCold(true);
11 @import("std").debug.panic("{}", msg);
13 std.debug.panic("{}", msg);
1214 } else {
1315 unreachable;
1416 }
......@@ -190,7 +192,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
190192 }) {}
191193 ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1));
192194 } else {
193 ux &= @maxValue(uint) >> exp_bits;
195 ux &= maxInt(uint) >> exp_bits;
194196 ux |= 1 << digits;
195197 }
196198 if (ey == 0) {
......@@ -201,7 +203,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
201203 }) {}
202204 uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1));
203205 } else {
204 uy &= @maxValue(uint) >> exp_bits;
206 uy &= maxInt(uint) >> exp_bits;
205207 uy |= 1 << digits;
206208 }
207209
......@@ -247,7 +249,7 @@ fn isNan(comptime T: type, bits: T) bool {
247249 } else if (T == u32) {
248250 return (bits & 0x7fffffff) > 0x7f800000;
249251 } else if (T == u64) {
250 return (bits & (@maxValue(u64) >> 1)) > (u64(0x7ff) << 52);
252 return (bits & (maxInt(u64) >> 1)) > (u64(0x7ff) << 52);
251253 } else {
252254 unreachable;
253255 }
std/special/compiler_rt/floattidf.zig+3-1
......@@ -1,5 +1,7 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("std");
4const maxInt = std.math.maxInt;
35
46const DBL_MANT_DIG = 53;
57
......@@ -37,7 +39,7 @@ pub extern fn __floattidf(arg: i128) f64 {
3739 const shift2_amt = @intCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
3840 const shift2_amt_u7 = @intCast(u7, shift2_amt);
3941
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);
4143 },
4244 }
4345 // finish
std/special/compiler_rt/floattisf.zig+3-1
......@@ -1,5 +1,7 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("std");
4const maxInt = std.math.maxInt;
35
46const FLT_MANT_DIG = 24;
57
......@@ -38,7 +40,7 @@ pub extern fn __floattisf(arg: i128) f32 {
3840 const shift2_amt = @intCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
3941 const shift2_amt_u7 = @intCast(u7, shift2_amt);
4042
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);
4244 },
4345 }
4446 // finish
std/special/compiler_rt/floattitf.zig+3-1
......@@ -1,5 +1,7 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("std");
4const maxInt = std.math.maxInt;
35
46const LDBL_MANT_DIG = 113;
57
......@@ -37,7 +39,7 @@ pub extern fn __floattitf(arg: i128) f128 {
3739 const shift2_amt = @intCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
3840 const shift2_amt_u7 = @intCast(u7, shift2_amt);
3941
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);
4143 },
4244 }
4345 // finish
std/special/compiler_rt/floatuntidf.zig+3-1
......@@ -1,5 +1,7 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("std");
4const maxInt = std.math.maxInt;
35
46const DBL_MANT_DIG = 53;
57
......@@ -30,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
3032 const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
3133 const shift_amt_u7 = @intCast(u7, shift_amt);
3234 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);
3436 },
3537 }
3638 // finish
std/special/compiler_rt/floatuntisf.zig+3-1
......@@ -1,5 +1,7 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("std");
4const maxInt = std.math.maxInt;
35
46const FLT_MANT_DIG = 24;
57
......@@ -30,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
3032 const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
3133 const shift_amt_u7 = @intCast(u7, shift_amt);
3234 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);
3436 },
3537 }
3638 // finish
std/special/compiler_rt/floatuntitf.zig+3-1
......@@ -1,5 +1,7 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("std");
4const maxInt = std.math.maxInt;
35
46const LDBL_MANT_DIG = 113;
57
......@@ -30,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
3032 const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
3133 const shift_amt_u7 = @intCast(u7, shift_amt);
3234 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);
3436 },
3537 }
3638 // finish
std/zig/parser_test.zig+2-1
......@@ -1868,6 +1868,7 @@ const std = @import("std");
18681868const mem = std.mem;
18691869const warn = std.debug.warn;
18701870const io = std.io;
1871const maxInt = std.math.maxInt;
18711872
18721873var fixed_buffer_mem: [100 * 1024]u8 = undefined;
18731874
......@@ -1916,7 +1917,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
19161917 const needed_alloc_count = x: {
19171918 // Try it once with unlimited memory, make sure it works
19181919 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));
19201921 var anything_changed: bool = undefined;
19211922 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
19221923 if (!mem.eql(u8, result_source, expected_source)) {
test/cases/alignof.zig+4-2
......@@ -1,5 +1,7 @@
1const assert = @import("std").debug.assert;
1const std = @import("std");
2const assert = std.debug.assert;
23const builtin = @import("builtin");
4const maxInt = std.math.maxInt;
35
46const Foo = struct.{
57 x: u32,
......@@ -8,7 +10,7 @@ const Foo = struct.{
810};
911
1012test "@alignOf(T) before referencing T" {
11 comptime assert(@alignOf(Foo) != @maxValue(usize));
13 comptime assert(@alignOf(Foo) != maxInt(usize));
1214 if (builtin.arch == builtin.Arch.x86_64) {
1315 comptime assert(@alignOf(Foo) == 4);
1416 }
test/cases/bitcast.zig+5-3
......@@ -1,4 +1,6 @@
1const assert = @import("std").debug.assert;
1const std = @import("std");
2const assert = std.debug.assert;
3const maxInt = std.math.maxInt;
24
35test "@bitCast i32 -> u32" {
46 testBitCast_i32_u32();
......@@ -6,8 +8,8 @@ test "@bitCast i32 -> u32" {
68}
79
810fn testBitCast_i32_u32() void {
9 assert(conv(-1) == @maxValue(u32));
10 assert(conv2(@maxValue(u32)) == -1);
11 assert(conv(-1) == maxInt(u32));
12 assert(conv2(maxInt(u32)) == -1);
1113}
1214
1315fn conv(x: i32) u32 {
test/cases/cast.zig+4-3
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const assert = std.debug.assert;
33const mem = std.mem;
4const maxInt = std.math.maxInt;
45
56test "int to ptr cast" {
67 const x = usize(13);
......@@ -368,7 +369,7 @@ test "@bytesToSlice keeps pointer alignment" {
368369}
369370
370371test "@intCast i32 to u7" {
371 var x: u128 = @maxValue(u128);
372 var x: u128 = maxInt(u128);
372373 var y: i32 = 120;
373374 var z = x >> @intCast(u7, y);
374375 assert(z == 0xff);
......@@ -435,11 +436,11 @@ test "compile time int to ptr of function" {
435436 foobar(FUNCTION_CONSTANT);
436437}
437438
438pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, @maxValue(usize));
439pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
439440pub const PFN_void = extern fn (*c_void) void;
440441
441442fn foobar(func: PFN_void) void {
442 std.debug.assert(@ptrToInt(func) == @maxValue(usize));
443 std.debug.assert(@ptrToInt(func) == maxInt(usize));
443444}
444445
445446test "implicit ptr to *c_void" {
test/cases/math.zig+17-14
......@@ -1,4 +1,7 @@
1const assert = @import("std").debug.assert;
1const std = @import("std");
2const assert = std.debug.assert;
3const maxInt = std.math.maxInt;
4const minInt = std.math.minInt;
25
36test "division" {
47 testDivision();
......@@ -179,30 +182,30 @@ test "const number literal" {
179182const ten = 10;
180183
181184test "unsigned wrapping" {
182 testUnsignedWrappingEval(@maxValue(u32));
183 comptime testUnsignedWrappingEval(@maxValue(u32));
185 testUnsignedWrappingEval(maxInt(u32));
186 comptime testUnsignedWrappingEval(maxInt(u32));
184187}
185188fn testUnsignedWrappingEval(x: u32) void {
186189 const zero = x +% 1;
187190 assert(zero == 0);
188191 const orig = zero -% 1;
189 assert(orig == @maxValue(u32));
192 assert(orig == maxInt(u32));
190193}
191194
192195test "signed wrapping" {
193 testSignedWrappingEval(@maxValue(i32));
194 comptime testSignedWrappingEval(@maxValue(i32));
196 testSignedWrappingEval(maxInt(i32));
197 comptime testSignedWrappingEval(maxInt(i32));
195198}
196199fn testSignedWrappingEval(x: i32) void {
197200 const min_val = x +% 1;
198 assert(min_val == @minValue(i32));
201 assert(min_val == minInt(i32));
199202 const max_val = min_val -% 1;
200 assert(max_val == @maxValue(i32));
203 assert(max_val == maxInt(i32));
201204}
202205
203206test "negation wrapping" {
204 testNegationWrappingEval(@minValue(i16));
205 comptime testNegationWrappingEval(@minValue(i16));
207 testNegationWrappingEval(minInt(i16));
208 comptime testNegationWrappingEval(minInt(i16));
206209}
207210fn testNegationWrappingEval(x: i16) void {
208211 assert(x == -32768);
......@@ -311,8 +314,8 @@ test "hex float literal within range" {
311314}
312315
313316test "truncating shift left" {
314 testShlTrunc(@maxValue(u16));
315 comptime testShlTrunc(@maxValue(u16));
317 testShlTrunc(maxInt(u16));
318 comptime testShlTrunc(maxInt(u16));
316319}
317320fn testShlTrunc(x: u16) void {
318321 const shifted = x << 1;
......@@ -320,8 +323,8 @@ fn testShlTrunc(x: u16) void {
320323}
321324
322325test "truncating shift right" {
323 testShrTrunc(@maxValue(u16));
324 comptime testShrTrunc(@maxValue(u16));
326 testShrTrunc(maxInt(u16));
327 comptime testShrTrunc(maxInt(u16));
325328}
326329fn testShrTrunc(x: u16) void {
327330 const shifted = x >> 1;
test/cases/misc.zig+9-44
......@@ -1,7 +1,9 @@
1const assert = @import("std").debug.assert;
2const mem = @import("std").mem;
3const cstr = @import("std").cstr;
1const std = @import("std");
2const assert = std.debug.assert;
3const mem = std.mem;
4const cstr = std.cstr;
45const builtin = @import("builtin");
6const maxInt = std.math.maxInt;
57
68// normal comment
79
......@@ -58,43 +60,6 @@ test "floating point primitive bit counts" {
5860 assert(f64.bit_count == 64);
5961}
6062
61test "@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
90test "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
9863test "short circuit" {
9964 testShortCircuit(false, true);
10065 comptime testShortCircuit(false, true);
......@@ -428,10 +393,10 @@ test "cast slice to u8 slice" {
428393 const big_thing_again = @bytesToSlice(i32, bytes);
429394 assert(big_thing_again[2] == 3);
430395 big_thing_again[2] = -1;
431 assert(bytes[8] == @maxValue(u8));
432 assert(bytes[9] == @maxValue(u8));
433 assert(bytes[10] == @maxValue(u8));
434 assert(bytes[11] == @maxValue(u8));
396 assert(bytes[8] == maxInt(u8));
397 assert(bytes[9] == maxInt(u8));
398 assert(bytes[10] == maxInt(u8));
399 assert(bytes[11] == maxInt(u8));
435400}
436401
437402test "pointer to void return type" {
test/cases/struct.zig+17-15
......@@ -1,5 +1,7 @@
1const assert = @import("std").debug.assert;
1const std = @import("std");
2const assert = std.debug.assert;
23const builtin = @import("builtin");
4const maxInt = std.math.maxInt;
35
46const StructWithNoFields = struct.{
57 fn add(a: i32, b: i32) i32 {
......@@ -307,29 +309,29 @@ test "packed array 24bits" {
307309 assert(ptr.b[1].field == 0);
308310 assert(ptr.c == 0);
309311
310 ptr.a = @maxValue(u16);
311 assert(ptr.a == @maxValue(u16));
312 ptr.a = maxInt(u16);
313 assert(ptr.a == maxInt(u16));
312314 assert(ptr.b[0].field == 0);
313315 assert(ptr.b[1].field == 0);
314316 assert(ptr.c == 0);
315317
316 ptr.b[0].field = @maxValue(u24);
317 assert(ptr.a == @maxValue(u16));
318 assert(ptr.b[0].field == @maxValue(u24));
318 ptr.b[0].field = maxInt(u24);
319 assert(ptr.a == maxInt(u16));
320 assert(ptr.b[0].field == maxInt(u24));
319321 assert(ptr.b[1].field == 0);
320322 assert(ptr.c == 0);
321323
322 ptr.b[1].field = @maxValue(u24);
323 assert(ptr.a == @maxValue(u16));
324 assert(ptr.b[0].field == @maxValue(u24));
325 assert(ptr.b[1].field == @maxValue(u24));
324 ptr.b[1].field = maxInt(u24);
325 assert(ptr.a == maxInt(u16));
326 assert(ptr.b[0].field == maxInt(u24));
327 assert(ptr.b[1].field == maxInt(u24));
326328 assert(ptr.c == 0);
327329
328 ptr.c = @maxValue(u16);
329 assert(ptr.a == @maxValue(u16));
330 assert(ptr.b[0].field == @maxValue(u24));
331 assert(ptr.b[1].field == @maxValue(u24));
332 assert(ptr.c == @maxValue(u16));
330 ptr.c = maxInt(u16);
331 assert(ptr.a == maxInt(u16));
332 assert(ptr.b[0].field == maxInt(u24));
333 assert(ptr.b[1].field == maxInt(u24));
334 assert(ptr.c == maxInt(u16));
333335
334336 assert(bytes[bytes.len - 1] == 0xaa);
335337}
test/compile_errors.zig+3-3
......@@ -535,12 +535,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
535535 );
536536
537537 cases.add(
538 "optional pointer to void in extern struct",
538 "bit count of @IntType too large",
539539 \\comptime {
540 \\ _ = @IntType(false, @maxValue(u32) + 1);
540 \\ _ = @IntType(false, @import("std").math.maxInt(u32) + 1);
541541 \\}
542542 ,
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'",
544544 );
545545
546546 cases.add(
test/standalone/brace_expansion/main.zig+2-1
......@@ -5,6 +5,7 @@ const debug = std.debug;
55const assert = debug.assert;
66const Buffer = std.Buffer;
77const ArrayList = std.ArrayList;
8const maxInt = std.math.maxInt;
89
910const Token = union(enum).{
1011 Word: []const u8,
......@@ -192,7 +193,7 @@ pub fn main() !void {
192193 defer stdin_buf.deinit();
193194
194195 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));
196197
197198 var result_buf = try Buffer.initSize(global_allocator, 0);
198199 defer result_buf.deinit();