Skip to content

Commit

Permalink
std: minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 26, 2025
1 parent e479a87 commit 663116e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 47 deletions.
62 changes: 16 additions & 46 deletions std/jule/types/limits.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,29 @@
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

// Maximum positive value of 32-bit floating-points.
// Floating-point limit values.
// Max is the largest finite value representable by the type.
// SmallestNonzero is the smallest positive, non-zero value representable by the type.
const MaxF32 = 0x1p127 * (1 + (1 - 0x1p-23))

// Maximum negative value of 32-bit floating-points.
const MinF32 = -0x1p127 * (1 + (1 - 0x1p-23))

// The smallest positive non-zero value representable by the 32-bit floating-points.
const SmallestNonZeroF32 = 0x1p-126 * 0x1p-23

// Maximum positive value of 64-bit floating-points.
const MaxF64 = 0x1p1023 * (1 + (1 - 0x1p-52))

// Maximum negative value of 64-bit floating-points.
const MinF64 = -0x1p1023 * (1 + (1 - 0x1p-52))

// The smallest positive non-zero value representable by the 64-bit floating-points.
const SmallestNonZeroF64 = 0x1p-1022 * 0x1p-52

// Maximum positive value of 8-bit signed integers.
const MaxI8 = 127

// Maximum negative value of 8-bit signed integers.
const MinI8 = -128

// Maximum positive value of 16-bit signed integers.
const MaxI16 = 32767

// Maximum negative value of 16-bit signed integers.
const MinI16 = -32768

// Maximum positive value of 32-bit signed integers.
const MaxI32 = 2147483647

// Maximum negative value of 32-bit signed integers.
const MinI32 = -2147483648

// Maximum positive value of 64-bit signed integers.
const MaxI64 = 9223372036854775807

// Maximum negative value of 64-bit signed integers.
const MinI64 = -9223372036854775808

// Maximum value of 8-bit unsigned integers.
const MaxU8 = 255

// Maximum value of 16-bit unsigned integers.
const MaxU16 = 65535

// Maximum value of 32-bit unsigned integers.
const MaxU32 = 4294967295

// Maximum value of 64-bit unsigned integers.
const MaxU64 = 18446744073709551615
// Integer limit values.
const MaxI8 = 1<<7 - 1 // 127
const MinI8 = -1 << 7 // -128
const MaxI16 = 1<<15 - 1 // 32767
const MinI16 = -1 << 15 // -32768
const MaxI32 = 1<<31 - 1 // 2147483647
const MinI32 = -1 << 31 // -2147483648
const MaxI64 = 1<<63 - 1 // 9223372036854775807
const MinI64 = -1 << 63 // -9223372036854775808
const MaxU8 = 1<<8 - 1 // 255
const MaxU16 = 1<<16 - 1 // 65535
const MaxU32 = 1<<32 - 1 // 4294967295
const MaxU64 = 1<<64 - 1 // 18446744073709551615

// Returns minimum value of signed integer kinds.
// Returns 0 if kind iss invalid.
Expand Down
2 changes: 1 addition & 1 deletion std/math/bits/bits.jule
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn OnesCount64(mut x: u64): int {
// Per "Hacker's Delight", the first line can be simplified
// more, but it saves at best one instruction, so we leave
// it alone for clarity.
const m = 18446744073709551615 // 1<<64 - 1
const m = 1<<64 - 1
x = x>>1&(m0&m) + x&(m0&m)
x = x>>2&(m1&m) + x&(m1&m)
x = (x>>4 + x) & (m2 & m)
Expand Down

0 comments on commit 663116e

Please sign in to comment.