Commit 2b395d4ede

Andrew Kelley <superjoe30@gmail.com>
2018-10-26 20:59:58
remove @minValue,@maxValue; add std.math.minInt,maxInt
closes #1466 closes #1476
1 parent 40b7652
doc/langref.html.in
@@ -827,7 +827,7 @@ a +%= b{#endsyntax#}</pre></td>
             </ul>
           </td>
           <td>
-            <pre>{#syntax#}u32(@maxValue(u32)) +% 1 == 0{#endsyntax#}</pre>
+            <pre>{#syntax#}u32(std.math.maxInt(u32)) +% 1 == 0{#endsyntax#}</pre>
           </td>
         </tr>
         <tr>
@@ -866,7 +866,7 @@ a -%= b{#endsyntax#}</pre></td>
             </ul>
           </td>
           <td>
-            <pre>{#syntax#}u32(0) -% 1 == @maxValue(u32){#endsyntax#}</pre>
+            <pre>{#syntax#}u32(0) -% 1 == std.math.maxInt(u32){#endsyntax#}</pre>
           </td>
         </tr>
         <tr>
@@ -901,7 +901,7 @@ a -%= b{#endsyntax#}</pre></td>
             </ul>
           </td>
           <td>
-            <pre>{#syntax#}-%i32(@minValue(i32)) == @minValue(i32){#endsyntax#}</pre>
+            <pre>{#syntax#}-%i32(std.math.minInt(i32)) == std.math.minInt(i32){#endsyntax#}</pre>
           </td>
         </tr>
         <tr>
@@ -3298,6 +3298,9 @@ const err = (error.{FileNotFound}).FileNotFound;
       Here is a function to parse a string into a 64-bit integer:
       </p>
       {#code_begin|test#}
+const std = @import("std");
+const maxInt = std.math.maxInt;
+
 pub fn parseU64(buf: []const u8, radix: u8) !u64 {
     var x: u64 = 0;
 
@@ -3327,13 +3330,13 @@ fn charToDigit(c: u8) u8 {
         '0' ... '9' => c - '0',
         'A' ... 'Z' => c - 'A' + 10,
         'a' ... 'z' => c - 'a' + 10,
-        else => @maxValue(u8),
+        else => maxInt(u8),
     };
 }
 
 test "parse u64" {
     const result = try parseU64("1234", 10);
-    @import("std").debug.assert(result == 1234);
+    std.debug.assert(result == 1234);
 }
       {#code_end#}
       <p>
@@ -5539,7 +5542,7 @@ test "main" {
       <p>
       Floored division. Rounds toward negative infinity. For unsigned integers it is
       the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
-              {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1){#endsyntax#}.
+              {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
       </p>
       <ul>
           <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
@@ -5553,7 +5556,7 @@ test "main" {
       <p>
       Truncated division. Rounds toward zero. For unsigned integers it is
       the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
-              {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1){#endsyntax#}.
+              {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
       </p>
       <ul>
           <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
@@ -5816,15 +5819,6 @@ fn add(a: i32, b: i32) i32 { return a + b; }
       This function returns an integer type with the given signness and bit count.
       </p>
       {#header_close#}
-      {#header_open|@maxValue#}
-      <pre>{#syntax#}@maxValue(comptime T: type) comptime_int{#endsyntax#}</pre>
-      <p>
-      This function returns the maximum value of the integer type {#syntax#}T{#endsyntax#}.
-      </p>
-      <p>
-      The result is a compile time constant.
-      </p>
-      {#header_close#}
       {#header_open|@memberCount#}
       <pre>{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}</pre>
       <p>
@@ -5885,15 +5879,6 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);{#endsyntax#}</pre>
       <p>There is also a standard library function for this:</p>
       <pre>{#syntax#}const mem = @import("std").mem;
 mem.set(u8, dest, c);{#endsyntax#}</pre>
-      {#header_close#}
-      {#header_open|@minValue#}
-      <pre>{#syntax#}@minValue(comptime T: type) comptime_int{#endsyntax#}</pre>
-      <p>
-      This function returns the minimum value of the integer type T.
-      </p>
-      <p>
-      The result is a compile time constant.
-      </p>
       {#header_close#}
       {#header_open|@mod#}
       <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>
@@ -6688,7 +6673,7 @@ pub fn main() void {
 }
       {#code_end#}
       <p>
-      To obtain the maximum value of an unsigned integer, use {#link|@maxValue#}.
+      To obtain the maximum value of an unsigned integer, use {#syntax#}std.math.maxInt{#endsyntax#}.
       </p>
       {#header_close#}
       {#header_open|Cast Truncates Data#}
@@ -6810,14 +6795,17 @@ pub fn main() void {
           <li>{#syntax#}*%{#endsyntax#} (wraparound multiplication)</li>
       </ul>
       {#code_begin|test#}
-const assert = @import("std").debug.assert;
+const std = @import("std");
+const assert = std.debug.assert;
+const minInt = std.math.minInt;
+const maxInt = std.math.maxInt;
 
 test "wraparound addition and subtraction" {
-    const x: i32 = @maxValue(i32);
+    const x: i32 = maxInt(i32);
     const min_val = x +% 1;
-    assert(min_val == @minValue(i32));
+    assert(min_val == minInt(i32));
     const max_val = min_val -% 1;
-    assert(max_val == @maxValue(i32));
+    assert(max_val == maxInt(i32));
 }
       {#code_end#}
       {#header_close#}
src/all_types.hpp
@@ -1343,8 +1343,6 @@ enum BuiltinFnId {
     BuiltinFnIdMemset,
     BuiltinFnIdSizeof,
     BuiltinFnIdAlignOf,
-    BuiltinFnIdMaxValue,
-    BuiltinFnIdMinValue,
     BuiltinFnIdMemberCount,
     BuiltinFnIdMemberType,
     BuiltinFnIdMemberName,
@@ -2081,8 +2079,6 @@ enum IrInstructionId {
     IrInstructionIdCUndef,
     IrInstructionIdArrayLen,
     IrInstructionIdRef,
-    IrInstructionIdMinValue,
-    IrInstructionIdMaxValue,
     IrInstructionIdCompileErr,
     IrInstructionIdCompileLog,
     IrInstructionIdErrName,
@@ -2609,18 +2605,6 @@ struct IrInstructionRef {
     bool is_volatile;
 };
 
-struct IrInstructionMinValue {
-    IrInstruction base;
-
-    IrInstruction *value;
-};
-
-struct IrInstructionMaxValue {
-    IrInstruction base;
-
-    IrInstruction *value;
-};
-
 struct IrInstructionCompileErr {
     IrInstruction base;
 
src/codegen.cpp
@@ -5100,8 +5100,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
         case IrInstructionIdSizeOf:
         case IrInstructionIdSwitchTarget:
         case IrInstructionIdContainerInitFields:
-        case IrInstructionIdMinValue:
-        case IrInstructionIdMaxValue:
         case IrInstructionIdCompileErr:
         case IrInstructionIdCompileLog:
         case IrInstructionIdArrayLen:
@@ -6651,8 +6649,6 @@ static void define_builtin_fns(CodeGen *g) {
     create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3);
     create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1);
     create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1);
-    create_builtin_fn(g, BuiltinFnIdMaxValue, "maxValue", 1);
-    create_builtin_fn(g, BuiltinFnIdMinValue, "minValue", 1);
     create_builtin_fn(g, BuiltinFnIdMemberCount, "memberCount", 1);
     create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2);
     create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2);
src/ir.cpp
@@ -495,14 +495,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) {
     return IrInstructionIdUnionInit;
 }
 
-static constexpr IrInstructionId ir_instruction_id(IrInstructionMinValue *) {
-    return IrInstructionIdMinValue;
-}
-
-static constexpr IrInstructionId ir_instruction_id(IrInstructionMaxValue *) {
-    return IrInstructionIdMaxValue;
-}
-
 static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {
     return IrInstructionIdCompileErr;
 }
@@ -1693,24 +1685,6 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source
     return &instruction->base;
 }
 
-static IrInstruction *ir_build_min_value(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
-    IrInstructionMinValue *instruction = ir_build_instruction<IrInstructionMinValue>(irb, scope, source_node);
-    instruction->value = value;
-
-    ir_ref_instruction(value, irb->current_basic_block);
-
-    return &instruction->base;
-}
-
-static IrInstruction *ir_build_max_value(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
-    IrInstructionMaxValue *instruction = ir_build_instruction<IrInstructionMaxValue>(irb, scope, source_node);
-    instruction->value = value;
-
-    ir_ref_instruction(value, irb->current_basic_block);
-
-    return &instruction->base;
-}
-
 static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
     IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node);
     instruction->msg = msg;
@@ -3813,26 +3787,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
                 IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
                 return ir_lval_wrap(irb, scope, c_undef, lval);
             }
-        case BuiltinFnIdMaxValue:
-            {
-                AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
-                IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
-                if (arg0_value == irb->codegen->invalid_instruction)
-                    return arg0_value;
-
-                IrInstruction *max_value = ir_build_max_value(irb, scope, node, arg0_value);
-                return ir_lval_wrap(irb, scope, max_value, lval);
-            }
-        case BuiltinFnIdMinValue:
-            {
-                AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
-                IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
-                if (arg0_value == irb->codegen->invalid_instruction)
-                    return arg0_value;
-
-                IrInstruction *min_value = ir_build_min_value(irb, scope, node, arg0_value);
-                return ir_lval_wrap(irb, scope, min_value, lval);
-            }
         case BuiltinFnIdCompileErr:
             {
                 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
         instruction->field_count, instruction->fields);
 }
 
-static IrInstruction *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,
-        IrInstruction *target_type_value, bool is_max)
-{
-    ZigType *target_type = ir_resolve_type(ira, target_type_value);
-    if (type_is_invalid(target_type))
-        return ira->codegen->invalid_instruction;
-    switch (target_type->id) {
-        case ZigTypeIdInvalid:
-            zig_unreachable();
-        case ZigTypeIdInt:
-            {
-                IrInstruction *result = ir_const(ira, source_instruction, 
-                    ira->codegen->builtin_types.entry_num_lit_int);
-                eval_min_max_value(ira->codegen, target_type, &result->value, is_max);
-                return result;
-            }
-        case ZigTypeIdBool:
-        case ZigTypeIdVoid:
-            {
-                IrInstruction *result = ir_const(ira, source_instruction, target_type);
-                eval_min_max_value(ira->codegen, target_type, &result->value, is_max);
-                return result;
-            }
-        case ZigTypeIdEnum:
-        case ZigTypeIdFloat:
-        case ZigTypeIdMetaType:
-        case ZigTypeIdUnreachable:
-        case ZigTypeIdPointer:
-        case ZigTypeIdPromise:
-        case ZigTypeIdArray:
-        case ZigTypeIdStruct:
-        case ZigTypeIdComptimeFloat:
-        case ZigTypeIdComptimeInt:
-        case ZigTypeIdUndefined:
-        case ZigTypeIdNull:
-        case ZigTypeIdOptional:
-        case ZigTypeIdErrorUnion:
-        case ZigTypeIdErrorSet:
-        case ZigTypeIdUnion:
-        case ZigTypeIdFn:
-        case ZigTypeIdNamespace:
-        case ZigTypeIdBoundFn:
-        case ZigTypeIdArgTuple:
-        case ZigTypeIdOpaque:
-            {
-                const char *err_format = is_max ?
-                    "no max value available for type '%s'" :
-                    "no min value available for type '%s'";
-                ir_add_error(ira, source_instruction,
-                        buf_sprintf(err_format, buf_ptr(&target_type->name)));
-                return ira->codegen->invalid_instruction;
-            }
-    }
-    zig_unreachable();
-}
-
-static IrInstruction *ir_analyze_instruction_min_value(IrAnalyze *ira,
-        IrInstructionMinValue *instruction)
-{
-    return ir_analyze_min_max(ira, &instruction->base, instruction->value->child, false);
-}
-
-static IrInstruction *ir_analyze_instruction_max_value(IrAnalyze *ira,
-        IrInstructionMaxValue *instruction)
-{
-    return ir_analyze_min_max(ira, &instruction->base, instruction->value->child, true);
-}
-
 static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,
         IrInstructionCompileErr *instruction)
 {
@@ -21052,10 +20938,6 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio
             return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction);
         case IrInstructionIdContainerInitFields:
             return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction);
-        case IrInstructionIdMinValue:
-            return ir_analyze_instruction_min_value(ira, (IrInstructionMinValue *)instruction);
-        case IrInstructionIdMaxValue:
-            return ir_analyze_instruction_max_value(ira, (IrInstructionMaxValue *)instruction);
         case IrInstructionIdCompileErr:
             return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction);
         case IrInstructionIdCompileLog:
@@ -21399,8 +21281,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
         case IrInstructionIdSwitchTarget:
         case IrInstructionIdUnionTag:
         case IrInstructionIdRef:
-        case IrInstructionIdMinValue:
-        case IrInstructionIdMaxValue:
         case IrInstructionIdEmbedFile:
         case IrInstructionIdTruncate:
         case IrInstructionIdIntType:
src/ir_print.cpp
@@ -565,18 +565,6 @@ static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {
     ir_print_other_instruction(irp, instruction->value);
 }
 
-static void ir_print_min_value(IrPrint *irp, IrInstructionMinValue *instruction) {
-    fprintf(irp->f, "@minValue(");
-    ir_print_other_instruction(irp, instruction->value);
-    fprintf(irp->f, ")");
-}
-
-static void ir_print_max_value(IrPrint *irp, IrInstructionMaxValue *instruction) {
-    fprintf(irp->f, "@maxValue(");
-    ir_print_other_instruction(irp, instruction->value);
-    fprintf(irp->f, ")");
-}
-
 static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {
     fprintf(irp->f, "@compileError(");
     ir_print_other_instruction(irp, instruction->msg);
@@ -1480,12 +1468,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
         case IrInstructionIdRef:
             ir_print_ref(irp, (IrInstructionRef *)instruction);
             break;
-        case IrInstructionIdMinValue:
-            ir_print_min_value(irp, (IrInstructionMinValue *)instruction);
-            break;
-        case IrInstructionIdMaxValue:
-            ir_print_max_value(irp, (IrInstructionMaxValue *)instruction);
-            break;
         case IrInstructionIdCompileErr:
             ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);
             break;
src-self-hosted/codegen.zig
@@ -10,6 +10,7 @@ const Scope = @import("scope.zig").Scope;
 const event = std.event;
 const assert = std.debug.assert;
 const DW = std.dwarf;
+const maxInt = std.math.maxInt;
 
 pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) !void {
     fn_val.base.ref();
@@ -362,15 +363,15 @@ fn addLLVMAttrInt(
 }
 
 fn addLLVMFnAttr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8) !void {
-    return addLLVMAttr(ofile, fn_val, @maxValue(llvm.AttributeIndex), attr_name);
+    return addLLVMAttr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name);
 }
 
 fn addLLVMFnAttrStr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: []const u8) !void {
-    return addLLVMAttrStr(ofile, fn_val, @maxValue(llvm.AttributeIndex), attr_name, attr_val);
+    return addLLVMAttrStr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val);
 }
 
 fn addLLVMFnAttrInt(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: u64) !void {
-    return addLLVMAttrInt(ofile, fn_val, @maxValue(llvm.AttributeIndex), attr_name, attr_val);
+    return addLLVMAttrInt(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val);
 }
 
 fn renderLoadUntyped(
std/crypto/chacha20.zig
@@ -5,6 +5,7 @@ const mem = std.mem;
 const endian = std.endian;
 const assert = std.debug.assert;
 const builtin = @import("builtin");
+const maxInt = std.math.maxInt;
 
 const QuarterRound = struct.{
     a: usize,
@@ -111,7 +112,7 @@ fn chaCha20_internal(out: []u8, in: []const u8, key: [8]u32, counter: [4]u32) vo
 /// counter, nonce, and key.
 pub fn chaCha20IETF(out: []u8, in: []const u8, counter: u32, key: [32]u8, nonce: [12]u8) void {
     assert(in.len >= out.len);
-    assert((in.len >> 6) + counter <= @maxValue(u32));
+    assert((in.len >> 6) + counter <= maxInt(u32));
 
     var k: [8]u32 = undefined;
     var c: [4]u32 = undefined;
@@ -161,7 +162,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
     const big_block = (block_size << 32);
 
     // first partial big block
-    if (((@intCast(u64, @maxValue(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) {
+    if (((@intCast(u64, maxInt(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) {
         chaCha20_internal(out[cursor..big_block], in[cursor..big_block], k, c);
         cursor = big_block - cursor;
         c[1] += 1;
std/debug/index.zig
@@ -11,6 +11,7 @@ const pdb = std.pdb;
 const windows = os.windows;
 const ArrayList = std.ArrayList;
 const builtin = @import("builtin");
+const maxInt = std.math.maxInt;
 
 pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator;
 pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator;
@@ -842,7 +843,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
             if (word & (u32(1) << bit_i) != 0) {
                 try list.append(word_i * 32 + bit_i);
             }
-            if (bit_i == @maxValue(u5)) break;
+            if (bit_i == maxInt(u5)) break;
         }
     }
     return list.toOwnedSlice();
@@ -1939,7 +1940,7 @@ fn findCompileUnit(st: *DebugInfo, target_address: u64) !*const CompileUnit {
                     if (begin_addr == 0 and end_addr == 0) {
                         break;
                     }
-                    if (begin_addr == @maxValue(usize)) {
+                    if (begin_addr == maxInt(usize)) {
                         base_address = begin_addr;
                         continue;
                     }
std/event/loop.zig
@@ -8,6 +8,7 @@ const fs = std.event.fs;
 const os = std.os;
 const posix = os.posix;
 const windows = os.windows;
+const maxInt = std.math.maxInt;
 
 pub const Loop = struct.{
     allocator: *mem.Allocator,
@@ -317,7 +318,7 @@ pub const Loop = struct.{
                     windows.INVALID_HANDLE_VALUE,
                     null,
                     undefined,
-                    @maxValue(windows.DWORD),
+                    maxInt(windows.DWORD),
                 );
                 errdefer os.close(self.os_data.io_port);
 
std/math/big/int.zig
@@ -5,6 +5,8 @@ const math = std.math;
 const mem = std.mem;
 const Allocator = mem.Allocator;
 const ArrayList = std.ArrayList;
+const maxInt = std.math.maxInt;
+const minInt = std.math.minInt;
 
 const TypeId = builtin.TypeId;
 
@@ -212,7 +214,7 @@ pub const Int = struct.{
                 self.positive = value >= 0;
                 self.len = req_limbs;
 
-                if (w_value <= @maxValue(Limb)) {
+                if (w_value <= maxInt(Limb)) {
                     self.limbs[0] = w_value;
                 } else {
                     const mask = (1 << Limb.bit_count) - 1;
@@ -267,7 +269,7 @@ pub const Int = struct.{
                         if (math.cast(T, r)) |ok| {
                             return -ok;
                         } else |_| {
-                            return @minValue(T);
+                            return minInt(T);
                         }
                     }
                 }
@@ -371,7 +373,7 @@ pub const Int = struct.{
             }
         } // Non power-of-two: batch divisions per word size.
         else {
-            const digits_per_limb = math.log(Limb, base, @maxValue(Limb));
+            const digits_per_limb = math.log(Limb, base, maxInt(Limb));
             var limb_base: Limb = 1;
             var j: usize = 0;
             while (j < digits_per_limb) : (j += 1) {
@@ -717,7 +719,7 @@ pub const Int = struct.{
         const c3: Limb = @boolToInt(@addWithOverflow(Limb, r1, r2, &r1));
 
         // This never overflows, c1, c3 are either 0 or 1 and if both are 1 then
-        // c2 is at least <= @maxValue(Limb) - 2.
+        // c2 is at least <= maxInt(Limb) - 2.
         carry.* = c1 + c2 + c3;
 
         return r1;
@@ -873,11 +875,11 @@ pub const Int = struct.{
         while (i > t) : (i -= 1) {
             // 3.1
             if (x.limbs[i] == y.limbs[t]) {
-                q.limbs[i - t - 1] = @maxValue(Limb);
+                q.limbs[i - t - 1] = maxInt(Limb);
             } else {
                 const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]);
                 const z = @intCast(Limb, num / DoubleLimb(y.limbs[t]));
-                q.limbs[i - t - 1] = if (z > @maxValue(Limb)) @maxValue(Limb) else Limb(z);
+                q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else Limb(z);
             }
 
             // 3.2
@@ -1081,7 +1083,7 @@ test "big.int comptime_int set" {
 
     comptime var i: usize = 0;
     inline while (i < s_limb_count) : (i += 1) {
-        const result = Limb(s & @maxValue(Limb));
+        const result = Limb(s & maxInt(Limb));
         s >>= Limb.bit_count / 2;
         s >>= Limb.bit_count / 2;
         debug.assert(a.limbs[i] == result);
@@ -1403,7 +1405,7 @@ test "big.int compare similar" {
 }
 
 test "big.int compare different limb size" {
-    var a = try Int.initSet(al, @maxValue(Limb) + 1);
+    var a = try Int.initSet(al, maxInt(Limb) + 1);
     var b = try Int.initSet(al, 1);
 
     debug.assert(a.cmpAbs(b) == 1);
@@ -1457,16 +1459,16 @@ test "big.int add single-single" {
 }
 
 test "big.int add multi-single" {
-    var a = try Int.initSet(al, @maxValue(Limb) + 1);
+    var a = try Int.initSet(al, maxInt(Limb) + 1);
     var b = try Int.initSet(al, 1);
 
     var c = try Int.init(al);
 
     try c.add(a, b);
-    debug.assert((try c.to(DoubleLimb)) == @maxValue(Limb) + 2);
+    debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
 
     try c.add(b, a);
-    debug.assert((try c.to(DoubleLimb)) == @maxValue(Limb) + 2);
+    debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
 }
 
 test "big.int add multi-multi" {
@@ -1533,13 +1535,13 @@ test "big.int sub single-single" {
 }
 
 test "big.int sub multi-single" {
-    var a = try Int.initSet(al, @maxValue(Limb) + 1);
+    var a = try Int.initSet(al, maxInt(Limb) + 1);
     var b = try Int.initSet(al, 1);
 
     var c = try Int.init(al);
     try c.sub(a, b);
 
-    debug.assert((try c.to(Limb)) == @maxValue(Limb));
+    debug.assert((try c.to(Limb)) == maxInt(Limb));
 }
 
 test "big.int sub multi-multi" {
@@ -1600,13 +1602,13 @@ test "big.int mul single-single" {
 }
 
 test "big.int mul multi-single" {
-    var a = try Int.initSet(al, @maxValue(Limb));
+    var a = try Int.initSet(al, maxInt(Limb));
     var b = try Int.initSet(al, 2);
 
     var c = try Int.init(al);
     try c.mul(a, b);
 
-    debug.assert((try c.to(DoubleLimb)) == 2 * @maxValue(Limb));
+    debug.assert((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
 }
 
 test "big.int mul multi-multi" {
@@ -1622,29 +1624,29 @@ test "big.int mul multi-multi" {
 }
 
 test "big.int mul alias r with a" {
-    var a = try Int.initSet(al, @maxValue(Limb));
+    var a = try Int.initSet(al, maxInt(Limb));
     var b = try Int.initSet(al, 2);
 
     try a.mul(a, b);
 
-    debug.assert((try a.to(DoubleLimb)) == 2 * @maxValue(Limb));
+    debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
 }
 
 test "big.int mul alias r with b" {
-    var a = try Int.initSet(al, @maxValue(Limb));
+    var a = try Int.initSet(al, maxInt(Limb));
     var b = try Int.initSet(al, 2);
 
     try a.mul(b, a);
 
-    debug.assert((try a.to(DoubleLimb)) == 2 * @maxValue(Limb));
+    debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
 }
 
 test "big.int mul alias r with a and b" {
-    var a = try Int.initSet(al, @maxValue(Limb));
+    var a = try Int.initSet(al, maxInt(Limb));
 
     try a.mul(a, a);
 
-    debug.assert((try a.to(DoubleLimb)) == @maxValue(Limb) * @maxValue(Limb));
+    debug.assert((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
 }
 
 test "big.int mul a*0" {
@@ -2047,8 +2049,8 @@ test "big.int bitwise and simple" {
 }
 
 test "big.int bitwise and multi-limb" {
-    var a = try Int.initSet(al, @maxValue(Limb) + 1);
-    var b = try Int.initSet(al, @maxValue(Limb));
+    var a = try Int.initSet(al, maxInt(Limb) + 1);
+    var b = try Int.initSet(al, maxInt(Limb));
 
     try a.bitAnd(a, b);
 
@@ -2065,12 +2067,12 @@ test "big.int bitwise xor simple" {
 }
 
 test "big.int bitwise xor multi-limb" {
-    var a = try Int.initSet(al, @maxValue(Limb) + 1);
-    var b = try Int.initSet(al, @maxValue(Limb));
+    var a = try Int.initSet(al, maxInt(Limb) + 1);
+    var b = try Int.initSet(al, maxInt(Limb));
 
     try a.bitXor(a, b);
 
-    debug.assert((try a.to(DoubleLimb)) == (@maxValue(Limb) + 1) ^ @maxValue(Limb));
+    debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
 }
 
 test "big.int bitwise or simple" {
@@ -2083,13 +2085,13 @@ test "big.int bitwise or simple" {
 }
 
 test "big.int bitwise or multi-limb" {
-    var a = try Int.initSet(al, @maxValue(Limb) + 1);
-    var b = try Int.initSet(al, @maxValue(Limb));
+    var a = try Int.initSet(al, maxInt(Limb) + 1);
+    var b = try Int.initSet(al, maxInt(Limb));
 
     try a.bitOr(a, b);
 
     // TODO: big.int.cpp or is wrong on multi-limb.
-    debug.assert((try a.to(DoubleLimb)) == (@maxValue(Limb) + 1) + @maxValue(Limb));
+    debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
 }
 
 test "big.int var args" {
std/math/asinh.zig
@@ -7,6 +7,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn asinh(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -55,7 +56,7 @@ fn asinh64(x: f64) f64 {
     const e = (u >> 52) & 0x7FF;
     const s = u >> 63;
 
-    var rx = @bitCast(f64, u & (@maxValue(u64) >> 1)); // |x|
+    var rx = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|
 
     if (math.isNegativeInf(x)) {
         return x;
std/math/atanh.zig
@@ -7,6 +7,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn atanh(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -52,7 +53,7 @@ fn atanh_64(x: f64) f64 {
     const e = (u >> 52) & 0x7FF;
     const s = u >> 63;
 
-    var y = @bitCast(f64, u & (@maxValue(u64) >> 1)); // |x|
+    var y = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|
 
     if (y == 1.0) {
         return math.copysign(f64, math.inf(f64), x);
std/math/copysign.zig
@@ -1,6 +1,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn copysign(comptime T: type, x: T, y: T) T {
     return switch (T) {
@@ -15,7 +16,7 @@ fn copysign16(x: f16, y: f16) f16 {
     const ux = @bitCast(u16, x);
     const uy = @bitCast(u16, y);
 
-    const h1 = ux & (@maxValue(u16) / 2);
+    const h1 = ux & (maxInt(u16) / 2);
     const h2 = uy & (u16(1) << 15);
     return @bitCast(f16, h1 | h2);
 }
@@ -24,7 +25,7 @@ fn copysign32(x: f32, y: f32) f32 {
     const ux = @bitCast(u32, x);
     const uy = @bitCast(u32, y);
 
-    const h1 = ux & (@maxValue(u32) / 2);
+    const h1 = ux & (maxInt(u32) / 2);
     const h2 = uy & (u32(1) << 31);
     return @bitCast(f32, h1 | h2);
 }
@@ -33,7 +34,7 @@ fn copysign64(x: f64, y: f64) f64 {
     const ux = @bitCast(u64, x);
     const uy = @bitCast(u64, y);
 
-    const h1 = ux & (@maxValue(u64) / 2);
+    const h1 = ux & (maxInt(u64) / 2);
     const h2 = uy & (u64(1) << 63);
     return @bitCast(f64, h1 | h2);
 }
std/math/cosh.zig
@@ -9,6 +9,7 @@ const std = @import("../index.zig");
 const math = std.math;
 const expo2 = @import("expo2.zig").expo2;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn cosh(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -50,7 +51,7 @@ fn cosh32(x: f32) f32 {
 fn cosh64(x: f64) f64 {
     const u = @bitCast(u64, x);
     const w = @intCast(u32, u >> 32);
-    const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
+    const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
 
     // TODO: Shouldn't need this explicit check.
     if (x == 0.0) {
std/math/fabs.zig
@@ -6,6 +6,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn fabs(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -31,7 +32,7 @@ fn fabs32(x: f32) f32 {
 
 fn fabs64(x: f64) f64 {
     var u = @bitCast(u64, x);
-    u &= @maxValue(u64) >> 1;
+    u &= maxInt(u64) >> 1;
     return @bitCast(f64, u);
 }
 
std/math/hypot.zig
@@ -8,6 +8,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn hypot(comptime T: type, x: T, y: T) T {
     return switch (T) {
@@ -21,8 +22,8 @@ fn hypot32(x: f32, y: f32) f32 {
     var ux = @bitCast(u32, x);
     var uy = @bitCast(u32, y);
 
-    ux &= @maxValue(u32) >> 1;
-    uy &= @maxValue(u32) >> 1;
+    ux &= maxInt(u32) >> 1;
+    uy &= maxInt(u32) >> 1;
     if (ux < uy) {
         const tmp = ux;
         ux = uy;
@@ -65,8 +66,8 @@ fn hypot64(x: f64, y: f64) f64 {
     var ux = @bitCast(u64, x);
     var uy = @bitCast(u64, y);
 
-    ux &= @maxValue(u64) >> 1;
-    uy &= @maxValue(u64) >> 1;
+    ux &= maxInt(u64) >> 1;
+    uy &= maxInt(u64) >> 1;
     if (ux < uy) {
         const tmp = ux;
         ux = uy;
std/math/ilogb.zig
@@ -1,12 +1,14 @@
 // Special Cases:
 //
-// - ilogb(+-inf) = @maxValue(i32)
-// - ilogb(0)     = @maxValue(i32)
-// - ilogb(nan)   = @maxValue(i32)
+// - ilogb(+-inf) = maxInt(i32)
+// - ilogb(0)     = maxInt(i32)
+// - ilogb(nan)   = maxInt(i32)
 
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
+const minInt = std.math.minInt;
 
 pub fn ilogb(x: var) i32 {
     const T = @typeOf(x);
@@ -18,7 +20,7 @@ pub fn ilogb(x: var) i32 {
 }
 
 // NOTE: Should these be exposed publically?
-const fp_ilogbnan = -1 - i32(@maxValue(u32) >> 1);
+const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1);
 const fp_ilogb0 = fp_ilogbnan;
 
 fn ilogb32(x: f32) i32 {
@@ -27,7 +29,7 @@ fn ilogb32(x: f32) i32 {
 
     // TODO: We should be able to merge this with the lower check.
     if (math.isNan(x)) {
-        return @maxValue(i32);
+        return maxInt(i32);
     }
 
     if (e == 0) {
@@ -50,7 +52,7 @@ fn ilogb32(x: f32) i32 {
         if (u << 9 != 0) {
             return fp_ilogbnan;
         } else {
-            return @maxValue(i32);
+            return maxInt(i32);
         }
     }
 
@@ -62,7 +64,7 @@ fn ilogb64(x: f64) i32 {
     var e = @intCast(i32, (u >> 52) & 0x7FF);
 
     if (math.isNan(x)) {
-        return @maxValue(i32);
+        return maxInt(i32);
     }
 
     if (e == 0) {
@@ -85,7 +87,7 @@ fn ilogb64(x: f64) i32 {
         if (u << 12 != 0) {
             return fp_ilogbnan;
         } else {
-            return @maxValue(i32);
+            return maxInt(i32);
         }
     }
 
@@ -116,15 +118,15 @@ test "math.ilogb64" {
 }
 
 test "math.ilogb32.special" {
-    assert(ilogb32(math.inf(f32)) == @maxValue(i32));
-    assert(ilogb32(-math.inf(f32)) == @maxValue(i32));
-    assert(ilogb32(0.0) == @minValue(i32));
-    assert(ilogb32(math.nan(f32)) == @maxValue(i32));
+    assert(ilogb32(math.inf(f32)) == maxInt(i32));
+    assert(ilogb32(-math.inf(f32)) == maxInt(i32));
+    assert(ilogb32(0.0) == minInt(i32));
+    assert(ilogb32(math.nan(f32)) == maxInt(i32));
 }
 
 test "math.ilogb64.special" {
-    assert(ilogb64(math.inf(f64)) == @maxValue(i32));
-    assert(ilogb64(-math.inf(f64)) == @maxValue(i32));
-    assert(ilogb64(0.0) == @minValue(i32));
-    assert(ilogb64(math.nan(f64)) == @maxValue(i32));
+    assert(ilogb64(math.inf(f64)) == maxInt(i32));
+    assert(ilogb64(-math.inf(f64)) == maxInt(i32));
+    assert(ilogb64(0.0) == minInt(i32));
+    assert(ilogb64(math.nan(f64)) == maxInt(i32));
 }
std/math/index.zig
@@ -382,7 +382,7 @@ pub fn absInt(x: var) !@typeOf(x) {
     comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
     comptime assert(T.is_signed); // must pass a signed integer to absInt
 
-    if (x == @minValue(@typeOf(x))) {
+    if (x == minInt(@typeOf(x))) {
         return error.Overflow;
     } else {
         @setRuntimeSafety(false);
@@ -404,7 +404,7 @@ pub const absFloat = @import("fabs.zig").fabs;
 pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
     @setRuntimeSafety(false);
     if (denominator == 0) return error.DivisionByZero;
-    if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1) return error.Overflow;
+    if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
     return @divTrunc(numerator, denominator);
 }
 
@@ -425,7 +425,7 @@ fn testDivTrunc() void {
 pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
     @setRuntimeSafety(false);
     if (denominator == 0) return error.DivisionByZero;
-    if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1) return error.Overflow;
+    if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
     return @divFloor(numerator, denominator);
 }
 
@@ -446,7 +446,7 @@ fn testDivFloor() void {
 pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
     @setRuntimeSafety(false);
     if (denominator == 0) return error.DivisionByZero;
-    if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1) return error.Overflow;
+    if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
     const result = @divTrunc(numerator, denominator);
     if (result * denominator != numerator) return error.UnexpectedRemainder;
     return result;
@@ -530,8 +530,8 @@ test "math.absCast" {
     assert(absCast(i32(999)) == 999);
     assert(@typeOf(absCast(i32(999))) == u32);
 
-    assert(absCast(i32(@minValue(i32))) == -@minValue(i32));
-    assert(@typeOf(absCast(i32(@minValue(i32)))) == u32);
+    assert(absCast(i32(minInt(i32))) == -minInt(i32));
+    assert(@typeOf(absCast(i32(minInt(i32)))) == u32);
 }
 
 /// Returns the negation of the integer parameter.
@@ -540,9 +540,9 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
     if (@typeOf(x).is_signed) return negate(x);
 
     const int = @IntType(true, @typeOf(x).bit_count);
-    if (x > -@minValue(int)) return error.Overflow;
+    if (x > -minInt(int)) return error.Overflow;
 
-    if (x == -@minValue(int)) return @minValue(int);
+    if (x == -minInt(int)) return minInt(int);
 
     return -@intCast(int, x);
 }
@@ -551,10 +551,10 @@ test "math.negateCast" {
     assert((negateCast(u32(999)) catch unreachable) == -999);
     assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
 
-    assert((negateCast(u32(-@minValue(i32))) catch unreachable) == @minValue(i32));
-    assert(@typeOf(negateCast(u32(-@minValue(i32))) catch unreachable) == i32);
+    assert((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
+    assert(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
 
-    if (negateCast(u32(@maxValue(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow);
+    if (negateCast(u32(maxInt(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow);
 }
 
 /// Cast an integer to a different integer type. If the value doesn't fit,
@@ -562,9 +562,9 @@ test "math.negateCast" {
 pub fn cast(comptime T: type, x: var) (error.{Overflow}!T) {
     comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
     comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer
-    if (@maxValue(@typeOf(x)) > @maxValue(T) and x > @maxValue(T)) {
+    if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) {
         return error.Overflow;
-    } else if (@minValue(@typeOf(x)) < @minValue(T) and x < @minValue(T)) {
+    } else if (minInt(@typeOf(x)) < minInt(T) and x < minInt(T)) {
         return error.Overflow;
     } else {
         return @intCast(T, x);
@@ -658,3 +658,59 @@ test "math.f64_min" {
     const fmin: f64 = f64_min;
     assert(@bitCast(u64, fmin) == f64_min_u64);
 }
+
+pub fn maxInt(comptime T: type) comptime_int {
+    const info = @typeInfo(T);
+    const bit_count = comptime_int(info.Int.bits); // TODO #1683
+    if (bit_count == 0) return 0;
+    return (1 << (bit_count - @boolToInt(info.Int.is_signed))) - 1;
+}
+
+pub fn minInt(comptime T: type) comptime_int {
+    const info = @typeInfo(T);
+    const bit_count = comptime_int(info.Int.bits); // TODO #1683
+    if (!info.Int.is_signed) return 0;
+    if (bit_count == 0) return 0;
+    return -(1 << (bit_count - 1));
+}
+
+test "minInt and maxInt" {
+    assert(maxInt(u0) == 0);
+    assert(maxInt(u1) == 1);
+    assert(maxInt(u8) == 255);
+    assert(maxInt(u16) == 65535);
+    assert(maxInt(u32) == 4294967295);
+    assert(maxInt(u64) == 18446744073709551615);
+
+    assert(maxInt(i0) == 0);
+    assert(maxInt(i1) == 0);
+    assert(maxInt(i8) == 127);
+    assert(maxInt(i16) == 32767);
+    assert(maxInt(i32) == 2147483647);
+    assert(maxInt(i63) == 4611686018427387903);
+    assert(maxInt(i64) == 9223372036854775807);
+
+    assert(minInt(u0) == 0);
+    assert(minInt(u1) == 0);
+    assert(minInt(u8) == 0);
+    assert(minInt(u16) == 0);
+    assert(minInt(u32) == 0);
+    assert(minInt(u63) == 0);
+    assert(minInt(u64) == 0);
+
+    assert(minInt(i0) == 0);
+    assert(minInt(i1) == -1);
+    assert(minInt(i8) == -128);
+    assert(minInt(i16) == -32768);
+    assert(minInt(i32) == -2147483648);
+    assert(minInt(i63) == -4611686018427387904);
+    assert(minInt(i64) == -9223372036854775808);
+}
+
+test "max value type" {
+    // If the type of maxInt(i32) was i32 then this implicit cast to
+    // u32 would not work. But since the value is a number literal,
+    // it works fine.
+    const x: u32 = maxInt(i32);
+    assert(x == 2147483647);
+}
std/math/isfinite.zig
@@ -1,6 +1,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn isFinite(x: var) bool {
     const T = @typeOf(x);
@@ -15,7 +16,7 @@ pub fn isFinite(x: var) bool {
         },
         f64 => {
             const bits = @bitCast(u64, x);
-            return bits & (@maxValue(u64) >> 1) < (0x7FF << 52);
+            return bits & (maxInt(u64) >> 1) < (0x7FF << 52);
         },
         else => {
             @compileError("isFinite not implemented for " ++ @typeName(T));
std/math/isinf.zig
@@ -1,6 +1,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn isInf(x: var) bool {
     const T = @typeOf(x);
@@ -15,7 +16,7 @@ pub fn isInf(x: var) bool {
         },
         f64 => {
             const bits = @bitCast(u64, x);
-            return bits & (@maxValue(u64) >> 1) == (0x7FF << 52);
+            return bits & (maxInt(u64) >> 1) == (0x7FF << 52);
         },
         else => {
             @compileError("isInf not implemented for " ++ @typeName(T));
std/math/isnan.zig
@@ -1,6 +1,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn isNan(x: var) bool {
     const T = @typeOf(x);
@@ -15,7 +16,7 @@ pub fn isNan(x: var) bool {
         },
         f64 => {
             const bits = @bitCast(u64, x);
-            return (bits & (@maxValue(u64) >> 1)) > (u64(0x7FF) << 52);
+            return (bits & (maxInt(u64) >> 1)) > (u64(0x7FF) << 52);
         },
         else => {
             @compileError("isNan not implemented for " ++ @typeName(T));
std/math/isnormal.zig
@@ -1,6 +1,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn isNormal(x: var) bool {
     const T = @typeOf(x);
@@ -15,7 +16,7 @@ pub fn isNormal(x: var) bool {
         },
         f64 => {
             const bits = @bitCast(u64, x);
-            return (bits + (1 << 52)) & (@maxValue(u64) >> 1) >= (1 << 53);
+            return (bits + (1 << 52)) & (maxInt(u64) >> 1) >= (1 << 53);
         },
         else => {
             @compileError("isNormal not implemented for " ++ @typeName(T));
std/math/log10.zig
@@ -10,6 +10,7 @@ const math = std.math;
 const assert = std.debug.assert;
 const builtin = @import("builtin");
 const TypeId = builtin.TypeId;
+const maxInt = std.math.maxInt;
 
 pub fn log10(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -151,7 +152,7 @@ pub fn log10_64(x_: f64) f64 {
     // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
     var hi = f - hfsq;
     var hii = @bitCast(u64, hi);
-    hii &= u64(@maxValue(u64)) << 32;
+    hii &= u64(maxInt(u64)) << 32;
     hi = @bitCast(f64, hii);
     const lo = f - hi - hfsq + s * (hfsq + R);
 
std/math/log2.zig
@@ -10,6 +10,7 @@ const math = std.math;
 const assert = std.debug.assert;
 const builtin = @import("builtin");
 const TypeId = builtin.TypeId;
+const maxInt = std.math.maxInt;
 
 pub fn log2(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -151,7 +152,7 @@ pub fn log2_64(x_: f64) f64 {
     // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f)
     var hi = f - hfsq;
     var hii = @bitCast(u64, hi);
-    hii &= u64(@maxValue(u64)) << 32;
+    hii &= u64(maxInt(u64)) << 32;
     hi = @bitCast(f64, hii);
     const lo = f - hi - hfsq + s * (hfsq + R);
 
std/math/modf.zig
@@ -6,6 +6,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 fn modf_result(comptime T: type) type {
     return struct.{
@@ -101,7 +102,7 @@ fn modf64(x: f64) modf64_result {
         return result;
     }
 
-    const mask = u64(@maxValue(u64) >> 12) >> @intCast(u6, e);
+    const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e);
     if (u & mask == 0) {
         result.ipart = x;
         result.fpart = @bitCast(f64, us);
std/math/sinh.zig
@@ -9,6 +9,7 @@ const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
 const expo2 = @import("expo2.zig").expo2;
+const maxInt = std.math.maxInt;
 
 pub fn sinh(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -56,7 +57,7 @@ fn sinh32(x: f32) f32 {
 fn sinh64(x: f64) f64 {
     const u = @bitCast(u64, x);
     const w = @intCast(u32, u >> 32);
-    const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
+    const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
 
     if (x == 0.0 or math.isNan(x)) {
         return x;
std/math/sqrt.zig
@@ -10,6 +10,7 @@ const math = std.math;
 const assert = std.debug.assert;
 const builtin = @import("builtin");
 const TypeId = builtin.TypeId;
+const maxInt = std.math.maxInt;
 
 pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
     const T = @typeOf(x);
@@ -17,7 +18,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
         TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128
         TypeId.Float => return @sqrt(T, x),
         TypeId.ComptimeInt => comptime {
-            if (x > @maxValue(u128)) {
+            if (x > maxInt(u128)) {
                 @compileError("sqrt not implemented for comptime_int greater than 128 bits");
             }
             if (x < 0) {
std/math/tanh.zig
@@ -9,6 +9,7 @@ const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
 const expo2 = @import("expo2.zig").expo2;
+const maxInt = std.math.maxInt;
 
 pub fn tanh(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -69,7 +70,7 @@ fn tanh32(x: f32) f32 {
 fn tanh64(x: f64) f64 {
     const u = @bitCast(u64, x);
     const w = @intCast(u32, u >> 32);
-    const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
+    const ax = @bitCast(f64, u & (maxInt(u64) >> 1));
 
     var t: f64 = undefined;
 
std/math/trunc.zig
@@ -7,6 +7,7 @@
 const std = @import("../index.zig");
 const math = std.math;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub fn trunc(x: var) @typeOf(x) {
     const T = @typeOf(x);
@@ -29,7 +30,7 @@ fn trunc32(x: f32) f32 {
         e = 1;
     }
 
-    m = u32(@maxValue(u32)) >> @intCast(u5, e);
+    m = u32(maxInt(u32)) >> @intCast(u5, e);
     if (u & m == 0) {
         return x;
     } else {
@@ -50,7 +51,7 @@ fn trunc64(x: f64) f64 {
         e = 1;
     }
 
-    m = u64(@maxValue(u64)) >> @intCast(u6, e);
+    m = u64(maxInt(u64)) >> @intCast(u6, e);
     if (u & m == 0) {
         return x;
     } else {
std/os/linux/index.zig
@@ -1,6 +1,7 @@
 const std = @import("../../index.zig");
 const assert = std.debug.assert;
 const builtin = @import("builtin");
+const maxInt = std.math.maxInt;
 const vdso = @import("vdso.zig");
 pub use switch (builtin.arch) {
     builtin.Arch.x86_64 => @import("x86_64.zig"),
@@ -38,7 +39,7 @@ pub const PROT_EXEC = 4;
 pub const PROT_GROWSDOWN = 0x01000000;
 pub const PROT_GROWSUP = 0x02000000;
 
-pub const MAP_FAILED = @maxValue(usize);
+pub const MAP_FAILED = maxInt(usize);
 pub const MAP_SHARED = 0x01;
 pub const MAP_PRIVATE = 0x02;
 pub const MAP_TYPE = 0x0f;
@@ -1094,7 +1095,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
 
 const NSIG = 65;
 const sigset_t = [128 / @sizeOf(usize)]usize;
-const all_mask = []usize.{@maxValue(usize)};
+const all_mask = []usize.{maxInt(usize)};
 const app_mask = []usize.{0xfffffffc7fffffff};
 
 const k_sigaction = extern struct.{
@@ -1111,7 +1112,7 @@ pub const Sigaction = struct.{
     flags: u32,
 };
 
-pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
+pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
 pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
 pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
 pub const empty_sigset = []usize.{0} ** sigset_t.len;
std/os/linux/vdso.zig
@@ -3,6 +3,7 @@ const elf = std.elf;
 const linux = std.os.linux;
 const cstr = std.cstr;
 const mem = std.mem;
+const maxInt = std.math.maxInt;
 
 pub fn lookup(vername: []const u8, name: []const u8) usize {
     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 {
     const ph = @intToPtr(*elf.Phdr, ph_addr);
 
     var maybe_dynv: ?[*]usize = null;
-    var base: usize = @maxValue(usize);
+    var base: usize = maxInt(usize);
     {
         var i: usize = 0;
         while (i < eh.e_phnum) : ({
@@ -29,7 +30,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
         }
     }
     const dynv = maybe_dynv orelse return 0;
-    if (base == @maxValue(usize)) return 0;
+    if (base == maxInt(usize)) return 0;
 
     var maybe_strings: ?[*]u8 = null;
     var maybe_syms: ?[*]elf.Sym = null;
std/os/windows/index.zig
@@ -1,5 +1,6 @@
 const std = @import("../../index.zig");
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub use @import("advapi32.zig");
 pub use @import("kernel32.zig");
@@ -53,17 +54,17 @@ pub const TRUE = 1;
 pub const FALSE = 0;
 
 /// The standard input device. Initially, this is the console input buffer, CONIN$.
-pub const STD_INPUT_HANDLE = @maxValue(DWORD) - 10 + 1;
+pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
 
 /// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
-pub const STD_OUTPUT_HANDLE = @maxValue(DWORD) - 11 + 1;
+pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
 
 /// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
-pub const STD_ERROR_HANDLE = @maxValue(DWORD) - 12 + 1;
+pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
 
-pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, @maxValue(usize));
+pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
 
-pub const INVALID_FILE_ATTRIBUTES = DWORD(@maxValue(DWORD));
+pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
 
 pub const OVERLAPPED = extern struct.{
     Internal: ULONG_PTR,
std/os/child_process.zig
@@ -14,6 +14,7 @@ const builtin = @import("builtin");
 const Os = builtin.Os;
 const LinkedList = std.LinkedList;
 const windows_util = @import("windows/util.zig");
+const maxInt = std.math.maxInt;
 
 const is_windows = builtin.os == Os.windows;
 
@@ -307,16 +308,16 @@ pub const ChildProcess = struct.{
             os.close(self.err_pipe[1]);
         }
 
-        // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after
+        // Write maxInt(ErrInt) to the write end of the err_pipe. This is after
         // waitpid, so this write is guaranteed to be after the child
         // pid potentially wrote an error. This way we can do a blocking
-        // read on the error pipe and either get @maxValue(ErrInt) (no error) or
+        // read on the error pipe and either get maxInt(ErrInt) (no error) or
         // an error code.
-        try writeIntFd(self.err_pipe[1], @maxValue(ErrInt));
+        try writeIntFd(self.err_pipe[1], maxInt(ErrInt));
         const err_int = try readIntFd(self.err_pipe[0]);
         // Here we potentially return the fork child's error
         // from the parent pid.
-        if (err_int != @maxValue(ErrInt)) {
+        if (err_int != maxInt(ErrInt)) {
             return @errSetCast(SpawnError, @intToError(err_int));
         }
 
std/os/darwin.zig
@@ -1,6 +1,7 @@
 const std = @import("../index.zig");
 const c = std.c;
 const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 pub use @import("darwin/errno.zig");
 
@@ -45,7 +46,7 @@ pub const MAP_NOCACHE = 0x0400;
 
 /// don't reserve needed swap area
 pub const MAP_NORESERVE = 0x0040;
-pub const MAP_FAILED = @maxValue(usize);
+pub const MAP_FAILED = maxInt(usize);
 
 /// [XSI] no hang in wait/no child to reap
 pub const WNOHANG = 0x00000001;
std/os/file.zig
@@ -9,6 +9,7 @@ const posix = os.posix;
 const windows = os.windows;
 const Os = builtin.Os;
 const windows_util = @import("windows/util.zig");
+const maxInt = std.math.maxInt;
 
 const is_posix = builtin.os != builtin.Os.windows;
 const is_windows = builtin.os == builtin.Os.windows;
@@ -385,7 +386,7 @@ pub const File = struct.{
         } else if (is_windows) {
             var index: usize = 0;
             while (index < buffer.len) {
-                const want_read_count = @intCast(windows.DWORD, math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index));
+                const want_read_count = @intCast(windows.DWORD, math.min(windows.DWORD(maxInt(windows.DWORD)), buffer.len - index));
                 var amt_read: windows.DWORD = undefined;
                 if (windows.ReadFile(self.handle, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
                     const err = windows.GetLastError();
std/rand/index.zig
@@ -20,6 +20,7 @@ const assert = std.debug.assert;
 const mem = std.mem;
 const math = std.math;
 const ziggurat = @import("ziggurat.zig");
+const maxInt = std.math.maxInt;
 
 // When you need fast unbiased random numbers
 pub const DefaultPrng = Xoroshiro128;
@@ -39,7 +40,7 @@ pub const Random = struct.{
         return r.int(u1) != 0;
     }
 
-    /// Returns a random int `i` such that `0 <= i <= @maxValue(T)`.
+    /// Returns a random int `i` such that `0 <= i <= maxInt(T)`.
     /// `i` is evenly distributed.
     pub fn int(r: *Random, comptime T: type) T {
         const UnsignedT = @IntType(false, T.bit_count);
@@ -69,14 +70,14 @@ pub const Random = struct.{
         assert(T.is_signed == false);
         assert(0 < less_than);
 
-        const last_group_size_minus_one: T = @maxValue(T) % less_than;
+        const last_group_size_minus_one: T = maxInt(T) % less_than;
         if (last_group_size_minus_one == less_than - 1) {
             // less_than is a power of two.
             assert(math.floorPowerOfTwo(T, less_than) == less_than);
-            // There is no retry zone. The optimal retry_zone_start would be @maxValue(T) + 1.
+            // There is no retry zone. The optimal retry_zone_start would be maxInt(T) + 1.
             return r.int(T) % less_than;
         }
-        const retry_zone_start = @maxValue(T) - last_group_size_minus_one;
+        const retry_zone_start = maxInt(T) - last_group_size_minus_one;
 
         while (true) {
             const rand_val = r.int(T);
@@ -91,7 +92,7 @@ pub const Random = struct.{
     /// for commentary on the runtime of this function.
     pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T {
         assert(T.is_signed == false);
-        if (at_most == @maxValue(T)) {
+        if (at_most == maxInt(T)) {
             // have the full range
             return r.int(T);
         }
std/special/compiler_rt/floattidf.zig
@@ -1,5 +1,7 @@
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
+const std = @import("std");
+const maxInt = std.math.maxInt;
 
 const DBL_MANT_DIG = 53;
 
@@ -37,7 +39,7 @@ pub extern fn __floattidf(arg: i128) f64 {
                 const shift2_amt = @intCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
                 const shift2_amt_u7 = @intCast(u7, shift2_amt);
 
-                a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, @maxValue(u128)) >> shift2_amt_u7)) != 0);
+                a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, maxInt(u128)) >> shift2_amt_u7)) != 0);
             },
         }
         // finish
std/special/compiler_rt/floattisf.zig
@@ -1,5 +1,7 @@
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
+const std = @import("std");
+const maxInt = std.math.maxInt;
 
 const FLT_MANT_DIG = 24;
 
@@ -38,7 +40,7 @@ pub extern fn __floattisf(arg: i128) f32 {
                 const shift2_amt = @intCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
                 const shift2_amt_u7 = @intCast(u7, shift2_amt);
 
-                a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, @maxValue(u128)) >> shift2_amt_u7)) != 0);
+                a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, maxInt(u128)) >> shift2_amt_u7)) != 0);
             },
         }
         // finish
std/special/compiler_rt/floattitf.zig
@@ -1,5 +1,7 @@
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
+const std = @import("std");
+const maxInt = std.math.maxInt;
 
 const LDBL_MANT_DIG = 113;
 
@@ -37,7 +39,7 @@ pub extern fn __floattitf(arg: i128) f128 {
                 const shift2_amt = @intCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
                 const shift2_amt_u7 = @intCast(u7, shift2_amt);
 
-                a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, @maxValue(u128)) >> shift2_amt_u7)) != 0);
+                a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, maxInt(u128)) >> shift2_amt_u7)) != 0);
             },
         }
         // finish
std/special/compiler_rt/floatuntidf.zig
@@ -1,5 +1,7 @@
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
+const std = @import("std");
+const maxInt = std.math.maxInt;
 
 const DBL_MANT_DIG = 53;
 
@@ -30,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 {
                 const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
                 const shift_amt_u7 = @intCast(u7, shift_amt);
                 a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) |
-                    @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
+                    @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);
             },
         }
         // finish
std/special/compiler_rt/floatuntisf.zig
@@ -1,5 +1,7 @@
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
+const std = @import("std");
+const maxInt = std.math.maxInt;
 
 const FLT_MANT_DIG = 24;
 
@@ -30,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 {
                 const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
                 const shift_amt_u7 = @intCast(u7, shift_amt);
                 a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) |
-                    @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
+                    @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);
             },
         }
         // finish
std/special/compiler_rt/floatuntitf.zig
@@ -1,5 +1,7 @@
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
+const std = @import("std");
+const maxInt = std.math.maxInt;
 
 const LDBL_MANT_DIG = 113;
 
@@ -30,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 {
                 const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
                 const shift_amt_u7 = @intCast(u7, shift_amt);
                 a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) |
-                    @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
+                    @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0);
             },
         }
         // finish
std/special/builtin.zig
@@ -1,14 +1,16 @@
 // These functions are provided when not linking against libc because LLVM
 // sometimes generates code that calls them.
 
+const std = @import("std");
 const builtin = @import("builtin");
+const maxInt = std.math.maxInt;
 
 // Avoid dragging in the runtime safety mechanisms into this .o file,
 // unless we're trying to test this file.
 pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
     if (builtin.is_test) {
         @setCold(true);
-        @import("std").debug.panic("{}", msg);
+        std.debug.panic("{}", msg);
     } else {
         unreachable;
     }
@@ -190,7 +192,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
         }) {}
         ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1));
     } else {
-        ux &= @maxValue(uint) >> exp_bits;
+        ux &= maxInt(uint) >> exp_bits;
         ux |= 1 << digits;
     }
     if (ey == 0) {
@@ -201,7 +203,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
         }) {}
         uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1));
     } else {
-        uy &= @maxValue(uint) >> exp_bits;
+        uy &= maxInt(uint) >> exp_bits;
         uy |= 1 << digits;
     }
 
@@ -247,7 +249,7 @@ fn isNan(comptime T: type, bits: T) bool {
     } else if (T == u32) {
         return (bits & 0x7fffffff) > 0x7f800000;
     } else if (T == u64) {
-        return (bits & (@maxValue(u64) >> 1)) > (u64(0x7ff) << 52);
+        return (bits & (maxInt(u64) >> 1)) > (u64(0x7ff) << 52);
     } else {
         unreachable;
     }
std/zig/parser_test.zig
@@ -1868,6 +1868,7 @@ const std = @import("std");
 const mem = std.mem;
 const warn = std.debug.warn;
 const io = std.io;
+const maxInt = std.math.maxInt;
 
 var fixed_buffer_mem: [100 * 1024]u8 = undefined;
 
@@ -1916,7 +1917,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
     const needed_alloc_count = x: {
         // Try it once with unlimited memory, make sure it works
         var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
-        var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));
+        var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));
         var anything_changed: bool = undefined;
         const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
         if (!mem.eql(u8, result_source, expected_source)) {
std/dynamic_library.zig
@@ -10,6 +10,7 @@ const elf = std.elf;
 const linux = os.linux;
 const windows = os.windows;
 const win_util = @import("os/windows/util.zig");
+const maxInt = std.math.maxInt;
 
 pub const DynLib = switch (builtin.os) {
     Os.linux => LinuxDynLib,
@@ -80,7 +81,7 @@ pub const ElfLib = struct.{
         const elf_addr = @ptrToInt(bytes.ptr);
         var ph_addr: usize = elf_addr + eh.e_phoff;
 
-        var base: usize = @maxValue(usize);
+        var base: usize = maxInt(usize);
         var maybe_dynv: ?[*]usize = null;
         {
             var i: usize = 0;
@@ -97,7 +98,7 @@ pub const ElfLib = struct.{
             }
         }
         const dynv = maybe_dynv orelse return error.MissingDynamicLinkingInformation;
-        if (base == @maxValue(usize)) return error.BaseNotFound;
+        if (base == maxInt(usize)) return error.BaseNotFound;
 
         var maybe_strings: ?[*]u8 = null;
         var maybe_syms: ?[*]elf.Sym = null;
std/heap.zig
@@ -6,6 +6,7 @@ const os = std.os;
 const builtin = @import("builtin");
 const Os = builtin.Os;
 const c = std.c;
+const maxInt = std.math.maxInt;
 
 const Allocator = mem.Allocator;
 
@@ -567,7 +568,7 @@ fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !voi
 fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
     //Maybe a platform's page_size is actually the same as or
     //  very near usize?
-    if (os.page_size << 2 > @maxValue(usize)) return;
+    if (os.page_size << 2 > maxInt(usize)) return;
 
     const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
     const large_align = u29(os.page_size << 2);
std/json.zig
@@ -5,6 +5,7 @@
 const std = @import("index.zig");
 const debug = std.debug;
 const mem = std.mem;
+const maxInt = std.math.maxInt;
 
 // A single token slice into the parent string.
 //
@@ -107,7 +108,7 @@ pub const StreamingParser = struct.{
 
     const object_bit = 0;
     const array_bit = 1;
-    const max_stack_size = @maxValue(u8);
+    const max_stack_size = maxInt(u8);
 
     pub fn init() StreamingParser {
         var p: StreamingParser = undefined;
test/cases/alignof.zig
@@ -1,5 +1,7 @@
-const assert = @import("std").debug.assert;
+const std = @import("std");
+const assert = std.debug.assert;
 const builtin = @import("builtin");
+const maxInt = std.math.maxInt;
 
 const Foo = struct.{
     x: u32,
@@ -8,7 +10,7 @@ const Foo = struct.{
 };
 
 test "@alignOf(T) before referencing T" {
-    comptime assert(@alignOf(Foo) != @maxValue(usize));
+    comptime assert(@alignOf(Foo) != maxInt(usize));
     if (builtin.arch == builtin.Arch.x86_64) {
         comptime assert(@alignOf(Foo) == 4);
     }
test/cases/bitcast.zig
@@ -1,4 +1,6 @@
-const assert = @import("std").debug.assert;
+const std = @import("std");
+const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
 
 test "@bitCast i32 -> u32" {
     testBitCast_i32_u32();
@@ -6,8 +8,8 @@ test "@bitCast i32 -> u32" {
 }
 
 fn testBitCast_i32_u32() void {
-    assert(conv(-1) == @maxValue(u32));
-    assert(conv2(@maxValue(u32)) == -1);
+    assert(conv(-1) == maxInt(u32));
+    assert(conv2(maxInt(u32)) == -1);
 }
 
 fn conv(x: i32) u32 {
test/cases/cast.zig
@@ -1,6 +1,7 @@
 const std = @import("std");
 const assert = std.debug.assert;
 const mem = std.mem;
+const maxInt = std.math.maxInt;
 
 test "int to ptr cast" {
     const x = usize(13);
@@ -368,7 +369,7 @@ test "@bytesToSlice keeps pointer alignment" {
 }
 
 test "@intCast i32 to u7" {
-    var x: u128 = @maxValue(u128);
+    var x: u128 = maxInt(u128);
     var y: i32 = 120;
     var z = x >> @intCast(u7, y);
     assert(z == 0xff);
@@ -435,11 +436,11 @@ test "compile time int to ptr of function" {
     foobar(FUNCTION_CONSTANT);
 }
 
-pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, @maxValue(usize));
+pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
 pub const PFN_void = extern fn (*c_void) void;
 
 fn foobar(func: PFN_void) void {
-    std.debug.assert(@ptrToInt(func) == @maxValue(usize));
+    std.debug.assert(@ptrToInt(func) == maxInt(usize));
 }
 
 test "implicit ptr to *c_void" {
test/cases/math.zig
@@ -1,4 +1,7 @@
-const assert = @import("std").debug.assert;
+const std = @import("std");
+const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
+const minInt = std.math.minInt;
 
 test "division" {
     testDivision();
@@ -179,30 +182,30 @@ test "const number literal" {
 const ten = 10;
 
 test "unsigned wrapping" {
-    testUnsignedWrappingEval(@maxValue(u32));
-    comptime testUnsignedWrappingEval(@maxValue(u32));
+    testUnsignedWrappingEval(maxInt(u32));
+    comptime testUnsignedWrappingEval(maxInt(u32));
 }
 fn testUnsignedWrappingEval(x: u32) void {
     const zero = x +% 1;
     assert(zero == 0);
     const orig = zero -% 1;
-    assert(orig == @maxValue(u32));
+    assert(orig == maxInt(u32));
 }
 
 test "signed wrapping" {
-    testSignedWrappingEval(@maxValue(i32));
-    comptime testSignedWrappingEval(@maxValue(i32));
+    testSignedWrappingEval(maxInt(i32));
+    comptime testSignedWrappingEval(maxInt(i32));
 }
 fn testSignedWrappingEval(x: i32) void {
     const min_val = x +% 1;
-    assert(min_val == @minValue(i32));
+    assert(min_val == minInt(i32));
     const max_val = min_val -% 1;
-    assert(max_val == @maxValue(i32));
+    assert(max_val == maxInt(i32));
 }
 
 test "negation wrapping" {
-    testNegationWrappingEval(@minValue(i16));
-    comptime testNegationWrappingEval(@minValue(i16));
+    testNegationWrappingEval(minInt(i16));
+    comptime testNegationWrappingEval(minInt(i16));
 }
 fn testNegationWrappingEval(x: i16) void {
     assert(x == -32768);
@@ -311,8 +314,8 @@ test "hex float literal within range" {
 }
 
 test "truncating shift left" {
-    testShlTrunc(@maxValue(u16));
-    comptime testShlTrunc(@maxValue(u16));
+    testShlTrunc(maxInt(u16));
+    comptime testShlTrunc(maxInt(u16));
 }
 fn testShlTrunc(x: u16) void {
     const shifted = x << 1;
@@ -320,8 +323,8 @@ fn testShlTrunc(x: u16) void {
 }
 
 test "truncating shift right" {
-    testShrTrunc(@maxValue(u16));
-    comptime testShrTrunc(@maxValue(u16));
+    testShrTrunc(maxInt(u16));
+    comptime testShrTrunc(maxInt(u16));
 }
 fn testShrTrunc(x: u16) void {
     const shifted = x >> 1;
test/cases/misc.zig
@@ -1,7 +1,9 @@
-const assert = @import("std").debug.assert;
-const mem = @import("std").mem;
-const cstr = @import("std").cstr;
+const std = @import("std");
+const assert = std.debug.assert;
+const mem = std.mem;
+const cstr = std.cstr;
 const builtin = @import("builtin");
+const maxInt = std.math.maxInt;
 
 // normal comment
 
@@ -58,43 +60,6 @@ test "floating point primitive bit counts" {
     assert(f64.bit_count == 64);
 }
 
-test "@minValue and @maxValue" {
-    assert(@maxValue(u1) == 1);
-    assert(@maxValue(u8) == 255);
-    assert(@maxValue(u16) == 65535);
-    assert(@maxValue(u32) == 4294967295);
-    assert(@maxValue(u64) == 18446744073709551615);
-
-    assert(@maxValue(i1) == 0);
-    assert(@maxValue(i8) == 127);
-    assert(@maxValue(i16) == 32767);
-    assert(@maxValue(i32) == 2147483647);
-    assert(@maxValue(i63) == 4611686018427387903);
-    assert(@maxValue(i64) == 9223372036854775807);
-
-    assert(@minValue(u1) == 0);
-    assert(@minValue(u8) == 0);
-    assert(@minValue(u16) == 0);
-    assert(@minValue(u32) == 0);
-    assert(@minValue(u63) == 0);
-    assert(@minValue(u64) == 0);
-
-    assert(@minValue(i1) == -1);
-    assert(@minValue(i8) == -128);
-    assert(@minValue(i16) == -32768);
-    assert(@minValue(i32) == -2147483648);
-    assert(@minValue(i63) == -4611686018427387904);
-    assert(@minValue(i64) == -9223372036854775808);
-}
-
-test "max value type" {
-    // If the type of @maxValue(i32) was i32 then this implicit cast to
-    // u32 would not work. But since the value is a number literal,
-    // it works fine.
-    const x: u32 = @maxValue(i32);
-    assert(x == 2147483647);
-}
-
 test "short circuit" {
     testShortCircuit(false, true);
     comptime testShortCircuit(false, true);
@@ -428,10 +393,10 @@ test "cast slice to u8 slice" {
     const big_thing_again = @bytesToSlice(i32, bytes);
     assert(big_thing_again[2] == 3);
     big_thing_again[2] = -1;
-    assert(bytes[8] == @maxValue(u8));
-    assert(bytes[9] == @maxValue(u8));
-    assert(bytes[10] == @maxValue(u8));
-    assert(bytes[11] == @maxValue(u8));
+    assert(bytes[8] == maxInt(u8));
+    assert(bytes[9] == maxInt(u8));
+    assert(bytes[10] == maxInt(u8));
+    assert(bytes[11] == maxInt(u8));
 }
 
 test "pointer to void return type" {
test/cases/struct.zig
@@ -1,5 +1,7 @@
-const assert = @import("std").debug.assert;
+const std = @import("std");
+const assert = std.debug.assert;
 const builtin = @import("builtin");
+const maxInt = std.math.maxInt;
 
 const StructWithNoFields = struct.{
     fn add(a: i32, b: i32) i32 {
@@ -307,29 +309,29 @@ test "packed array 24bits" {
     assert(ptr.b[1].field == 0);
     assert(ptr.c == 0);
 
-    ptr.a = @maxValue(u16);
-    assert(ptr.a == @maxValue(u16));
+    ptr.a = maxInt(u16);
+    assert(ptr.a == maxInt(u16));
     assert(ptr.b[0].field == 0);
     assert(ptr.b[1].field == 0);
     assert(ptr.c == 0);
 
-    ptr.b[0].field = @maxValue(u24);
-    assert(ptr.a == @maxValue(u16));
-    assert(ptr.b[0].field == @maxValue(u24));
+    ptr.b[0].field = maxInt(u24);
+    assert(ptr.a == maxInt(u16));
+    assert(ptr.b[0].field == maxInt(u24));
     assert(ptr.b[1].field == 0);
     assert(ptr.c == 0);
 
-    ptr.b[1].field = @maxValue(u24);
-    assert(ptr.a == @maxValue(u16));
-    assert(ptr.b[0].field == @maxValue(u24));
-    assert(ptr.b[1].field == @maxValue(u24));
+    ptr.b[1].field = maxInt(u24);
+    assert(ptr.a == maxInt(u16));
+    assert(ptr.b[0].field == maxInt(u24));
+    assert(ptr.b[1].field == maxInt(u24));
     assert(ptr.c == 0);
 
-    ptr.c = @maxValue(u16);
-    assert(ptr.a == @maxValue(u16));
-    assert(ptr.b[0].field == @maxValue(u24));
-    assert(ptr.b[1].field == @maxValue(u24));
-    assert(ptr.c == @maxValue(u16));
+    ptr.c = maxInt(u16);
+    assert(ptr.a == maxInt(u16));
+    assert(ptr.b[0].field == maxInt(u24));
+    assert(ptr.b[1].field == maxInt(u24));
+    assert(ptr.c == maxInt(u16));
 
     assert(bytes[bytes.len - 1] == 0xaa);
 }
test/standalone/brace_expansion/main.zig
@@ -5,6 +5,7 @@ const debug = std.debug;
 const assert = debug.assert;
 const Buffer = std.Buffer;
 const ArrayList = std.ArrayList;
+const maxInt = std.math.maxInt;
 
 const Token = union(enum).{
     Word: []const u8,
@@ -192,7 +193,7 @@ pub fn main() !void {
     defer stdin_buf.deinit();
 
     var stdin_adapter = stdin_file.inStream();
-    try stdin_adapter.stream.readAllBuffer(&stdin_buf, @maxValue(usize));
+    try stdin_adapter.stream.readAllBuffer(&stdin_buf, maxInt(usize));
 
     var result_buf = try Buffer.initSize(global_allocator, 0);
     defer result_buf.deinit();
test/compile_errors.zig
@@ -535,12 +535,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
     );
 
     cases.add(
-        "optional pointer to void in extern struct",
+        "bit count of @IntType too large",
         \\comptime {
-        \\    _ = @IntType(false, @maxValue(u32) + 1);
+        \\    _ = @IntType(false, @import("std").math.maxInt(u32) + 1);
         \\}
     ,
-        ".tmp_source.zig:2:40: error: integer value 4294967296 cannot be implicitly casted to type 'u32'",
+        ".tmp_source.zig:2:57: error: integer value 4294967296 cannot be implicitly casted to type 'u32'",
     );
 
     cases.add(