/*---------------------------------------------------------------------------
  Copyright 2012-2023, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/

// 64-bit signed integers.
//
// Using 64-bit signed two's complement representation
// with wrapping on overflow, e.g. `max-int64 + 1.int64 == min-int64`
module std/num/int64std/num/int64

import std/core/undivstd/core/undiv

extern import
  c  file "int64-inline.c"

// The maximal integer value before overflow happens
pub val max-int64std/num/int64/max-int64: int64 : int64std/core/types/int64: V =  0x7FFF_FFFF_FFFF_FFFFliteral: int
dec = 9223372036854775807
hex64= 0x7FFFFFFFFFFFFFFF
bit64= 0b0111111111111111111111111111111111111111111111111111111111111111
.int64std/num/int64/int64: (i : int) -> int64
// The minimal integer value before underflow happens pub val min-int64std/num/int64/min-int64: int64 : int64std/core/types/int64: V = -0x8000_0000_0000_0000literal: int
dec = -9223372036854775808
.int64std/num/int64/int64: (i : int) -> int64
// The number of bits in an `:int64` (always 64) pub val bits-int64std/num/int64/bits-int64: int64 : int64std/core/types/int64: V = 64literal: int
dec = 64
hex8 = 0x40
bit8 = 0b01000000
.int64std/num/int64/int64: (i : int) -> int64
// Convert an `:int64` to a string pub fun showstd/num/int64/show: (i : int64) -> string( ii: int64 : int64std/core/types/int64: V )result: -> total string : stringstd/core/types/string: V showstd/core/int/show: (i : int) -> string(ii: int64.intstd/num/int64/int: (i : int64) -> int) // clamp an `:int` to fit in an `:int64_t`. pub fip extern int64std/num/int64/int64: (i : int) -> int64( ii: int : intstd/core/types/int: V) : int64std/core/types/int64: V c "kk_integer_clamp64" cs "Primitive.IntToInt64" js "$std_core_types._int_clamp64" // Convert an `:int64_t` to an `:int`. pub inline fip extern intstd/num/int64/int: (i : int64) -> int( i : int64std/core/types/int64: V ) : intstd/core/types/int: V c "kk_integer_from_int64" cs inline "(new BigInteger(#1))" js "$std_core_types._int_from_int64" // Convenient shorthand to `int64`, e.g. `1234.i64` pub inline fip fun i64std/num/int64/i64: (i : int) -> int64( ii: int : intstd/core/types/int: V )result: -> total int64 : int64std/core/types/int64: V ii: int.int64std/num/int64/int64: (i : int) -> int64 // Convert an `:int64` to a boolean. pub fun boolstd/num/int64/bool: (i : int64) -> bool( ii: int64 : int64std/core/types/int64: V )result: -> total bool : boolstd/core/types/bool: V (ii: int64!=std/num/int64/(!=): (x : int64, y : int64) -> boolzerostd/num/int64/zero: int64) // Convert a boolean to an `:int64`. pub fip fun bool/int64std/num/int64/bool/int64: (b : bool) -> int64( bb: bool : boolstd/core/types/bool: V )result: -> total int64 : int64std/core/types/int64: V if bb: bool then onestd/num/int64/one: int64 else zerostd/num/int64/zero: int64 // Convert an `:int32` to an `:int64` (using sign extension). pub inline fip extern int32/int64std/num/int64/int32/int64: (i : int32) -> int64( i : int32std/core/types/int32: V ) : int64std/core/types/int64: V c inline "(int64_t)(#1)" js "$std_core_types._int64_from_int32" // Convert an `:int32` to an `:int64` interpreting the `:int32` as unsigned. pub inline fip extern uint64std/num/int64/uint64: (i : int32) -> int64( i : int32std/core/types/int32: V ) : int64std/core/types/int64: V c inline "(int64_t)((uint32_t)(#1))" js "$std_core_types._int64_from_uint32" // Clamp an `:int64` to an `:int32` // `-1.int64.int32 == -1.int32` // `0x8000_0000.int64.int32 == 0x7FFF_FFFF.int32` (clamped) pub inline fip extern int32std/num/int64/int32: (i : int64) -> int32( i : int64std/core/types/int64: V ) : int32std/core/types/int32: V c "kk_int64_clamp_int32" js "$std_core_types._int64_clamp_int32" // Clamp an `:int64` to an `:int32` but interpreting the `:int32` as unsigned // (and thus clamp between 0 and 0xFFFFFFFF). // `-1.int64.uint32 == 0.int32` (clamped) // `0xFFFFFFFF.int64.uint32 == -1.int32` pub inline fip extern uint32std/num/int64/uint32: (i : int64) -> int32( i : int64std/core/types/int64: V ) : int32std/core/types/int32: V c "kk_int64_clamp_uint32" js "$std_core_types._int64_clamp_uint32" // Create an `:int64` `i` from the bits of `lo` and `hi` such // that `i.int = hi.int * 0x1_0000_0000 + lo.uint`. pub inline fip extern hilo32/int64std/num/int64/hilo32/int64: (hi : int32, lo : int32) -> int64( hi : int32std/core/types/int32: V, lo : int32std/core/types/int32: V ) : int64std/core/types/int64: V c inline "kk_int64_hi_lo(#1,#2)" js "$std_core_types._int64_hi_lo" // Return the top 32-bits of an `:int64`. // Preserves the sign. pub fip fun histd/num/int64/hi: (i : int64) -> int64( ii: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V sar64std/num/int64/sar64: (int64, int64) -> int64(ii: int64,32literal: int
dec = 32
hex8 = 0x20
bit8 = 0b00100000
.int64std/num/int64/int64: (i : int) -> int64
) // Return the low 32-bits of an `:int64`. pub fip fun lostd/num/int64/lo: (i : int64) -> int64( ii: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V andstd/num/int64/and: (int64, int64) -> int64(ii: int64,0xFFFFFFFFliteral: int
dec = 4294967295
hex64= 0x00000000FFFFFFFF
bit64= 0b0000000000000000000000000000000011111111111111111111111111111111
.int64std/num/int64/int64: (i : int) -> int64
) // Create an `:int64` from the given `hi` and `lo` numbers lowest 32-bits. // Preserves the sign of `hi`. pub fip fun hilo/int64std/num/int64/hilo/int64: (hi : int64, lo : int64) -> int64( hihi: int64 : int64std/core/types/int64: V, lolo: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V orstd/num/int64/or: (int64, int64) -> int64( shl64std/num/int64/shl64: (int64, int64) -> int64(hihi: int64,32literal: int
dec = 32
hex8 = 0x20
bit8 = 0b00100000
.int64std/num/int64/int64: (i : int) -> int64), andstd/num/int64/and: (int64, int64) -> int64(lolo: int64,0xFFFF_FFFFliteral: int
dec = 4294967295
hex64= 0x00000000FFFFFFFF
bit64= 0b0000000000000000000000000000000011111111111111111111111111111111
.int64std/num/int64/int64: (i : int) -> int64)
) // Convert an `:int` to `:int64` but interpret the `int` as an unsigned 64-bit value. // `i` is clamped between `0` and `0xFFFF_FFFF_FFFF_FFFF`.\ // `0x7FFF_FFFF_FFFF_FFFF.uint64 == 0x7FFF_FFFF_FFFF_FFFF.int64 == max-int64`\ // `0x8000_0000_0000_0000.uint64 == -0x8000_0000_0000_0000.int64 == min-int64`\ // `0xFFFF_FFFF_FFFF_FFFF.uint64 == -1.int64`\ pub fun int/uint64std/num/int64/int/uint64: (i : int) -> int64( ii: int : intstd/core/types/int: V )result: -> total int64 : int64std/core/types/int64: V if ii: int >std/core/int/(>): (x : int, y : int) -> bool max-int64std/num/int64/max-int64: int64.intstd/num/int64/int: (i : int64) -> int then (ii: int -std/core/int/(-): (x : int, y : int) -> int 0x1_0000_0000_0000_0000literal: int
dec = 18446744073709551616
).int64std/num/int64/int64: (i : int) -> int64 else ii: int.int64std/num/int64/int64: (i : int) -> int64
// Convert an `:int64` to an `:int` but interpret the `:int64` as a 64-bit unsigned value. pub fip fun int64/uintstd/num/int64/int64/uint: (i : int64) -> int( ii: int64 : int64std/core/types/int64: V )result: -> total int : intstd/core/types/int: V if ii: int64.is-negstd/num/int64/is-neg: (i : int64) -> bool then 0x1_0000_0000_0000_0000literal: int
dec = 18446744073709551616
+std/core/int/(+): (x : int, y : int) -> int ii: int64.intstd/num/int64/int: (i : int64) -> int else ii: int64.intstd/num/int64/int: (i : int64) -> int
// Show an `:int64` in hexadecimal notation // The `width` parameter specifies how wide the hex value is where `'0'` is used to align.\ // The `use-capitals` parameter (= `True`) determines if captical letters should be used to display the hexadecimal digits.\ // The `pre` (=`"0x"`) is an optional prefix for the number (goes between the sign and the number). pub fun show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string( ii: int64 : int64std/core/types/int64: V, widthwidth: ? int : intstd/core/types/int: V = 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
, use-capitalsuse-capitals: ? bool : boolstd/core/types/bool: V = Truestd/core/types/True: bool, prepre: ? string : stringstd/core/types/string: V = "0x"literal: string
count= 2
)result: -> total string : stringstd/core/types/string: V std/core/show/show-hexstd/core/show/show-hex: (i : int, width : ? int, use-capitals : ? bool, pre : ? string) -> string(ii: int64.intstd/num/int64/int: (i : int64) -> int,widthwidth: int,use-capitalsuse-capitals: bool,prepre: string
) // Show an `:int64` in hexadecimal notation interpreted as an unsigned 64-bit value. // The `width` parameter specifies how wide the hex value is where `'0'` is used to align.\ // The `use-capitals` parameter (= `True`) determines if captical letters should be used to display the hexadecimal digits.\ // The `pre` (=`"0x"`) is an optional prefix for the number. pub fun show-hex64std/num/int64/show-hex64: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string( ii: int64 : int64std/core/types/int64: V, widthwidth: ? int : intstd/core/types/int: V = 16literal: int
dec = 16
hex8 = 0x10
bit8 = 0b00010000
, use-capitalsuse-capitals: ? bool : boolstd/core/types/bool: V = Truestd/core/types/True: bool, prepre: ? string : stringstd/core/types/string: V = "0x"literal: string
count= 2
)result: -> total string : stringstd/core/types/string: V std/core/show/show-hexstd/core/show/show-hex: (i : int, width : ? int, use-capitals : ? bool, pre : ? string) -> string(ii: int64.uintstd/num/int64/int64/uint: (i : int64) -> int,widthwidth: int,use-capitalsuse-capitals: bool,prepre: string
) // Are two 64-bit integers equal? pub inline fip extern (==)std/num/int64/(==): (x : int64, y : int64) -> bool(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : boolstd/core/types/bool: V inline "(#1 == #2)" js inline "(#1 === #2)" // Are two 64-bit integers not equal? pub inline fip extern (!=)std/num/int64/(!=): (x : int64, y : int64) -> bool(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : boolstd/core/types/bool: V inline "(#1 != #2)" js inline "(#1 !== #2)" // Is the first 64-bit integer smaller or equal to the second? pub inline fip extern (<=)std/num/int64/(<=): (x : int64, y : int64) -> bool(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : boolstd/core/types/bool: V inline "(#1 <= #2)" // Is the first 64-bit integer larger or equal to the second? pub inline fip extern (>=)std/num/int64/(>=): (x : int64, y : int64) -> bool(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : boolstd/core/types/bool: V inline "(#1 >= #2)" // Is the first 64-bit integer smaller than the second? pub inline fip extern (<)std/num/int64/(<): (x : int64, y : int64) -> bool(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : boolstd/core/types/bool: V inline "(#1 < #2)" // Is the first 64-bit integer larger than the second? pub inline fip extern (>)std/num/int64/(>): (x : int64, y : int64) -> bool(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : boolstd/core/types/bool: V inline "(#1 > #2)" // Add two 64-bit integers. pub inline fip extern (+)std/num/int64/(+): (x : int64, y : int64) -> int64(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : int64std/core/types/int64: V c inline "(int64_t)((uint64_t)#1 + (uint64_t)#2)" // avoid UB js inline "BigInt.asIntN(64,#1 + #2)" // Subtract two 64-bit integers. pub inline fip extern (-)std/num/int64/(-): (x : int64, y : int64) -> int64(x : int64std/core/types/int64: V, y : int64std/core/types/int64: V) : int64std/core/types/int64: V c inline "(int64_t)((uint64_t)#1 - (uint64_t)#2)" // avoid UB js inline "BigInt.asIntN(64,#1 - #2)" // Is the 64-bit integer negative? pub inline fip extern is-negstd/num/int64/is-neg: (i : int64) -> bool( i : int64std/core/types/int64: V ) : boolstd/core/types/bool: V inline "0 > #1" js inline "0n > #1" // Is the 64-bit integer positive? (i.e. larger than zero) pub inline fip extern is-posstd/num/int64/is-pos: (i : int64) -> bool( i : int64std/core/types/int64: V ) : boolstd/core/types/bool: V inline "0 < #1" js inline "0n < #1" // Is the 64-bit integer zero? pub inline fip extern is-zerostd/num/int64/is-zero: (i : int64) -> bool( i : int64std/core/types/int64: V ) : boolstd/core/types/bool: V inline "0 == #1" js inline "0n === #1" // The 64-bit integer for zero. pub val zerostd/num/int64/zero: int64 = 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64
// The 64-bit integer for 1. pub val onestd/num/int64/one: int64 = 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
.int64std/num/int64/int64: (i : int) -> int64
// Compare a 64-integer to zero. pub fip fun signstd/num/int64/sign: (i : int64) -> order( ii: int64 : int64std/core/types/int64: V )result: -> total order : orderstd/core/types/order: V if ii: int64.is-posstd/num/int64/is-pos: (i : int64) -> bool then Gtstd/core/types/Gt: order elif ii: int64.is-negstd/num/int64/is-neg: (i : int64) -> bool then Ltstd/core/types/Lt: order else Eqstd/core/types/Eq: order // Returns `true` if the integer `i` is an odd number. pub fip fun is-oddstd/num/int64/is-odd: (i : int64) -> bool( ii: int64 : int64std/core/types/int64: V )result: -> total bool : boolstd/core/types/bool: V andstd/num/int64/and: (int64, int64) -> int64(ii: int64,onestd/num/int64/one: int64)==std/num/int64/(==): (x : int64, y : int64) -> boolonestd/num/int64/one: int64 // Returns `true` if the integer `i` is an even number. pub fip fun is-evenstd/num/int64/is-even: (i : int64) -> bool( ii: int64 : int64std/core/types/int64: V )result: -> total bool : boolstd/core/types/bool: V andstd/num/int64/and: (int64, int64) -> int64(ii: int64,onestd/num/int64/one: int64)==std/num/int64/(==): (x : int64, y : int64) -> boolzerostd/num/int64/zero: int64 // Increment a 64-bit integer. pub fip fun incstd/num/int64/inc: (i : int64) -> int64( ii: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V ii: int64 +std/num/int64/(+): (x : int64, y : int64) -> int64 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
.int64std/num/int64/int64: (i : int) -> int64
// Decrement a 64-bit integer. pub fip fun decstd/num/int64/dec: (i : int64) -> int64( ii: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V ii: int64 -std/num/int64/(-): (x : int64, y : int64) -> int64 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
.int64std/num/int64/int64: (i : int) -> int64
// Multiply two 64-bit integers. pub inline fip extern (*)std/num/int64/(*): (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V c inline "(int64_t)((uint64_t)#1 * (uint64_t)#2)"; // avoid UB js inline "BigInt.asIntN(64,#1 * #2)" pub fip fun cmpstd/num/int64/cmp: (x : int64, y : int64) -> order( xx: int64 : int64std/core/types/int64: V, yy: int64 : int64std/core/types/int64: V)result: -> total order : orderstd/core/types/order: V if xx: int64 <std/num/int64/(<): (x : int64, y : int64) -> bool yy: int64 then Ltstd/core/types/Lt: order elif xx: int64 >std/num/int64/(>): (x : int64, y : int64) -> bool yy: int64 then Gtstd/core/types/Gt: order else Eqstd/core/types/Eq: order // Return the absolute value of an integer. // Raises an exception if the `:int64` is `min-int64` // (since the negation of `min-int64` equals itself and is still negative) pub fun absstd/num/int64/abs: (i : int64) -> exn int64( ii: int64 : int64std/core/types/int64: V )result: -> exn int64 : exnstd/core/exn/exn: (E, V) -> V int64std/core/types/int64: V if !std/core/types/bool/(!): (b : bool) -> exn boolii: int64.is-negstd/num/int64/is-neg: (i : int64) -> exn bool then ii: int64 elif ii: int64 >std/num/int64/(>): (x : int64, y : int64) -> exn bool min-int64std/num/int64/min-int64: int64 then negatestd/num/int64/negate: (i : int64) -> exn int64(ii: int64) else throwstd/core/exn/throw: (message : string, info : ? exception-info) -> exn int64( "std/num/int64/abs: cannot make min-int64 into a positive int64 without overflow"literal: string
count= 79
) // Return the absolute value of an integer. // Returns 0 if the `:int64` is `min-int64` // (since the negation of `min-int64` equals itself and is still negative) pub fip fun abs0std/num/int64/abs0: (i : int64) -> int64( ii: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V if !std/core/types/bool/(!): (b : bool) -> boolii: int64.is-negstd/num/int64/is-neg: (i : int64) -> bool then ii: int64 elif ii: int64 >std/num/int64/(>): (x : int64, y : int64) -> bool min-int64std/num/int64/min-int64: int64 then negatestd/num/int64/negate: (i : int64) -> int64(ii: int64) else 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64
// Take the bitwise _and_ of two `:int64`s pub inline fip extern andstd/num/int64/and: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V inline "#1 & #2" // Take the bitwise _or_ of two `:int64`s pub inline fip extern orstd/num/int64/or: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V inline "#1 | #2" // Take the bitwise _xor_ of two `:int64`s pub inline fip extern xorstd/num/int64/xor: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V inline "#1 ^ #2"; // Take the bitwise _xor_ of two `:int64`s pub fip fun (^)std/num/int64/(^): (x : int64, y : int64) -> int64( xx: int64 : int64std/core/types/int64: V, yy: int64 : int64std/core/types/int64: V)result: -> total int64 : int64std/core/types/int64: V xorstd/num/int64/xor: (int64, int64) -> int64(xx: int64,yy: int64) // Bitwise _not_ of an `:int64`, i.e. flips all bits. pub inline fip extern notstd/num/int64/not: (i : int64) -> int64 : ( i : int64std/core/types/int64: V ) -> int64std/core/types/int64: V inline "~#1" js inline "BigInt.asIntN(64, ~#1)" // Shift an `:int64` `i` to the left by `n % 64` bits. inline fip extern shl64std/num/int64/shl64: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V c inline "kk_shl64(#1,#2)" js "$std_core_types._int64_shl" // Shift an `:int64` `i` to the left by `n % 64` bits. pub fip fun shlstd/num/int64/shl: (i : int64, shift : int) -> int64( ii: int64 : int64std/core/types/int64: V, shiftshift: int : intstd/core/types/int: V)result: -> total int64 : int64std/core/types/int64: V shl64std/num/int64/shl64: (int64, int64) -> int64(ii: int64,shiftshift: int.int64std/num/int64/int64: (i : int) -> int64) // Logical shift an `:int64` to the right by `n % 64` bits. Shift in zeros from the left. inline fip extern shr64std/num/int64/shr64: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V c inline "(int64_t)kk_shr64(#1,#2)" cs inline "(int64)(((Uint64)#1)>>#2)" js "$std_core_types._int64_shr" // Logical shift an `:int64` to the right by `n % 64` bits. Shift in zeros from the left. pub fip fun shrstd/num/int64/shr: (i : int64, shift : int) -> int64( ii: int64 : int64std/core/types/int64: V, shiftshift: int : intstd/core/types/int: V)result: -> total int64 : int64std/core/types/int64: V shr64std/num/int64/shr64: (int64, int64) -> int64(ii: int64,shiftshift: int.int64std/num/int64/int64: (i : int) -> int64) // Arithmetic shift an `:int64` to the right by `n % 64` bits. Preserves the sign bit. inline fip extern sar64std/num/int64/sar64: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V c inline "kk_sar64(#1,#2)" js "$std_core_types._int64_sar" // Arithmetic shift an `:int64` to the right by `n % 64` bits. Shift in the sign bit from the left. pub fip fun sarstd/num/int64/sar: (i : int64, shift : int) -> int64( ii: int64 : int64std/core/types/int64: V, shiftshift: int : intstd/core/types/int: V)result: -> total int64 : int64std/core/types/int64: V sar64std/num/int64/sar64: (int64, int64) -> int64(ii: int64,shiftshift: int.int64std/num/int64/int64: (i : int) -> int64) // Bitwise rotate an `:int64` `n % 64` bits to the left. inline fip extern rotl64std/num/int64/rotl64: (i : int64, n : int64) -> int64( i : int64std/core/types/int64: V, n : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "(int64_t)kk_bits_rotl64(#1,(int)#2)" js "$std_core_types._int64_rotl" // Bitwise rotate an `:int64` `n % 64` bits to the left. pub fun rotlstd/num/int64/rotl: (i : int64, shift : int) -> int64( ii: int64 : int64std/core/types/int64: V, shiftshift: int : intstd/core/types/int: V)result: -> total int64 : int64std/core/types/int64: V rotl64std/num/int64/rotl64: (i : int64, n : int64) -> int64(ii: int64,shiftshift: int.int64std/num/int64/int64: (i : int) -> int64) // Bitwise rotate an `:int64` `n % 64` bits to the right. inline fip extern rotr64std/num/int64/rotr64: (i : int64, n : int64) -> int64( i : int64std/core/types/int64: V, n : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "(int64_t)kk_bits_rotr64(#1,(int)#2)" js "$std_core_types._int64_rotr" // Bitwise rotate an `:int64` `n % 64` bits to the right. pub fip fun rotrstd/num/int64/rotr: (i : int64, shift : int) -> int64( ii: int64 : int64std/core/types/int64: V, shiftshift: int : intstd/core/types/int: V)result: -> total int64 : int64std/core/types/int64: V rotr64std/num/int64/rotr64: (i : int64, n : int64) -> int64(ii: int64,shiftshift: int.int64std/num/int64/int64: (i : int) -> int64) // Count trailing zero bits. Returns 64 if `i` is zero. pub inline fip extern ctzstd/num/int64/ctz: (i : int64) -> int( i : int64std/core/types/int64: V ) : intstd/core/types/int: V c inline "kk_integer_from_small(kk_bits_ctz64(#1))" js "$std_core_types._int64_ctz" // Count leading zero bits. Returns 64 if `i` is zero. pub inline fip extern clzstd/num/int64/clz: (i : int64) -> int( i : int64std/core/types/int64: V ) : intstd/core/types/int: V c inline "kk_integer_from_small(kk_bits_clz64(#1))" js "$std_core_types._int64_clz" // Count leading redundant sign bits (i.e. the number of bits // following the most significant bit that are identical to it). pub inline fip extern clrsbstd/num/int64/clrsb: (i : int64) -> int( i : int64std/core/types/int64: V ) : intstd/core/types/int: V c inline "kk_integer_from_small(kk_bits_clrsb64(#1))" js "$std_core_types._int64_clrsb" // Count number of 1-bits. inline fip extern popcount64std/num/int64/popcount64: (i : int64) -> int64( i : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "(int64_t)kk_bits_popcount64(#1)" js "$std_core_types._int64_popcount" // Count number of 1-bits. pub fip fun popcountstd/num/int64/popcount: (i : int64) -> int( ii: int64 : int64std/core/types/int64: V )result: -> total int : intstd/core/types/int: V popcount64std/num/int64/popcount64: (i : int64) -> int64(ii: int64).intstd/num/int64/int: (i : int64) -> int // Is the `popcount` even? pub inline fip extern paritystd/num/int64/parity: (i : int64) -> bool( i : int64std/core/types/int64: V ) : boolstd/core/types/bool: V c inline "kk_bits_parity64(#1)" js "$std_core_types._int64_parity" // Reverse the bytes in an `:int64`. pub inline fip extern byte-reversestd/num/int64/byte-reverse: (i : int64) -> int64( i : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "kk_bits_bswap64(#1)" js "$std_core_types._int64_bswap" // Reverse the bits in an `:int64`. pub inline fip extern bit-reversestd/num/int64/bit-reverse: (i : int64) -> int64( i : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "kk_bits_reverse64(#1)" js "$std_core_types._int64_breverse" // Bit gather (also known as _pext_ or parallel bit extract). // For each 1-bit in mask `m`, extract the corresponding bit from `i` and write it // into contiguous lower bits in the result. The remaining bits in the result are zero. // // `bit-gather(0x1234.int64, 0x0F0F.int64).show-hex == "0x24"` pub inline fip extern bit-gatherstd/num/int64/bit-gather: (i : int64, m : int64) -> int64( i : int64std/core/types/int64: V, m : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "kk_bits_gather64(#1,#2)" // Bit scatter (also known as _pdep_ or parallel bit deposit). // For each 1-bit in mask `m`, set the corresponding bit in the result from the // contiguous lower bits of `i`. Any bits not set according to the mask are set to zero. // // `bit-scatter(0x1234.int64, 0x0F0F.int64).show-hex == "0x304"` pub inline fip extern bit-scatterstd/num/int64/bit-scatter: (i : int64, m : int64) -> int64( i : int64std/core/types/int64: V, m : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "kk_bits_scatter64(#1,#2)" // Interleave the hi 32-bits with the lo 32-bits of the argument `i` such // that the hi bits are spread over the odd bits and the lo bits over the even bits // of the result (starting at bit 0). // `bit-zip(x.and(0xFFFF_FFFF.int64)) == bit-scatter(x,0x5555_5555_5555_5555.int64)` pub inline fip extern bit-zipstd/num/int64/bit-zip: (i : int64) -> int64( i : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "kk_bits_zip64(#1)" // De-interleave the bits in `i` such that the odd bits are gathered in the // hi 32-bits of the result, and the even bits (starting at bit 0) // end up in the lo 32-bits of the result. // `bit-unzip(x).and(0xFFFF_FFFF.int64) == bit-gather(x,0x5555_5555_5555_5555.int64)` pub inline fip extern bit-unzipstd/num/int64/bit-unzip: (i : int64) -> int64( i : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "kk_bits_unzip64(#1)" // Or-combine: for every byte `b` in the argument `i`, the corresponding // byte in the result becomes 0 if `b==0`, and `0xFF` otherwise. pub inline fip extern orcstd/num/int64/orc: (i : int64) -> int64( i : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "kk_bits_orc64(#1)" // Carry-less multiplication (or _xor_ multiplication). // See also <https://en.wikipedia.org/wiki/Carry-less_product> // Interesting cases: // - `clmul(x,x)` : _bit spread_, where a zero bit is put in between each input bit. // `clmul(x,x) == bit-scatter(x,0x5555_5555_5555_5555.int64) == bit-zip(and(x,0xFFFF_FFFF.int64))` // - `clmul(x,-1.int32)`: _prefix xor_, where each bit is the parity of the corresponding input bit // and all input bits before it (the _xor sum_). // `clmul(x,-1.int64).shr(63).bool == x.parity` pub inline fip extern clmulstd/num/int64/clmul: (x : int64, y : int64) -> int64( x : int64std/core/types/int64: V, y : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "(int64_t)kk_clmul64((uint64_t)#1,(uint64_t)#2)" // Wide carry-less multiplication (or _xor_ multiplication) to `(hi,lo)`, // where `(hi,lo).int == hi.int * 0x1_0000_0000_0000_0000 + lo.uint`. // See also <https://en.wikipedia.org/wiki/Carry-less_product>. pub fip extern clmul-widestd/num/int64/clmul-wide: (x : int64, y : int64) -> (int64, int64)( xx: int64 : int64std/core/types/int64: V, yy: int64 : int64std/core/types/int64: V ) : (std/core/types/tuple2: (V, V) -> Vint64std/core/types/int64: V,int64std/core/types/int64: V) c "kk_clmul64x_wide" // Reverse carry-less multiplication. // Defined as `clmulr(x,y) == clmul(x.bit-reverse,y.bitreverse).bitreverse` // Interesting cases: // - `clmulr(x,x) == zip(x.and(0xFFFF_FFFF_0000_0000.int64)`, and // - `zip(x) == clmul(x,x) | clmulr(x,x)`. pub inline fip extern clmulrstd/num/int64/clmulr: (x : int64, y : int64) -> int64( x : int64std/core/types/int64: V, y : int64std/core/types/int64: V ) : int64std/core/types/int64: V c inline "(int64_t)kk_clmulr64((uint64_t)#1,(uint64_t)#2)" // Return the minimum of two integers pub fip fun minstd/num/int64/min: (i : int64, j : int64) -> int64( ii: int64 : int64std/core/types/int64: V, jj: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V if ii: int64 <=std/num/int64/(<=): (x : int64, y : int64) -> bool jj: int64 then ii: int64 else jj: int64 // Return the maximum of two integers pub fip fun maxstd/num/int64/max: (i : int64, j : int64) -> int64( ii: int64 : int64std/core/types/int64: V, jj: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V if ii: int64 >=std/num/int64/(>=): (x : int64, y : int64) -> bool jj: int64 then ii: int64 else jj: int64 // Full 64x64 to 128-bit unsigned multiply to `(hi,lo)`. // where `umul(x,y).uint == x.uint * y.uint` pub fip extern umulstd/num/int64/umul: (i : int64, j : int64) -> (int64, int64)( ii: int64 : int64std/core/types/int64: V, jj: int64 : int64std/core/types/int64: V ) : (std/core/types/tuple2: (V, V) -> Vint64std/core/types/int64: V,int64std/core/types/int64: V) c "kk_umul64x_wide" js "$std_core_types._int64_umul" // Full 64x64 to 128-bit signed multiply to `(hi,lo)`. // where `imul(x,y).int == x.int * y.int` pub fip extern imulstd/num/int64/imul: (i : int64, j : int64) -> (int64, int64)( ii: int64 : int64std/core/types/int64: V, jj: int64 : int64std/core/types/int64: V ) : (std/core/types/tuple2: (V, V) -> Vint64std/core/types/int64: V,int64std/core/types/int64: V) c "kk_imul64x_wide" js "$std_core_types._int64_imul" // Convert a pair `(hi,lo)` to an signed integer, // where `(hi,lo).int == hi.int * 0x1_0000_0000_0000_0000 + lo.uint` pub fun hilo/intstd/num/int64/hilo/int: ((int64, int64)) -> int( (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)hihi: int64,lolo: int64)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) : (std/core/types/tuple2: (V, V) -> Vint64std/core/types/int64: V,int64std/core/types/int64: V) )result: -> total int : intstd/core/types/int: V hihi: int64.intstd/num/int64/int: (i : int64) -> int *std/core/int/(*): (int, int) -> int 0x1_0000_0000_0000_0000literal: int
dec = 18446744073709551616
+std/core/int/(+): (x : int, y : int) -> int lolo: int64.uintstd/num/int64/int64/uint: (i : int64) -> int
// Convert a pair `(hi,lo)` to an unsigned integer, // where `(hi,lo).uint == hi.uint * 0x1_0000_0000_0000_0000 + lo.uint` pub fun hilo/uintstd/num/int64/hilo/uint: ((int64, int64)) -> int( (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)hihi: int64,lolo: int64)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) : (std/core/types/tuple2: (V, V) -> Vint64std/core/types/int64: V,int64std/core/types/int64: V) )result: -> total int : intstd/core/types/int: V hihi: int64.uintstd/num/int64/int64/uint: (i : int64) -> int *std/core/int/(*): (int, int) -> int 0x1_0000_0000_0000_0000literal: int
dec = 18446744073709551616
+std/core/int/(+): (x : int, y : int) -> int lolo: int64.uintstd/num/int64/int64/uint: (i : int64) -> int
// Truncated division (as in C). See also `(/):(x : int64, y : int64) -> int64`. pub fun cdivstd/num/int64/cdiv: (i : int64, j : int64) -> exn int64(ii: int64:int64std/core/types/int64: V, jj: int64:int64std/core/types/int64: V)result: -> exn int64 : exnstd/core/exn/exn: (E, V) -> V int64std/core/types/int64: V if jj: int64.is-zerostd/num/int64/is-zero: (i : int64) -> exn bool then throwstd/core/exn/throw: (message : string, info : ? exception-info) -> exn int64("std/num/int64/cdiv: division by zero"literal: string
count= 36
) elif jj: int64 ==std/num/int64/(==): (x : int64, y : int64) -> exn bool -1literal: int
dec = -1
hex8 = 0xFF
bit8 = 0b11111111
.int64std/num/int64/int64: (i : int) -> exn int64 &&std/core/types/(&&): (x : bool, y : bool) -> exn bool ii: int64==std/num/int64/(==): (x : int64, y : int64) -> exn boolmin-int64std/num/int64/min-int64: int64 then throwstd/core/exn/throw: (message : string, info : ? exception-info) -> exn int64("std/num/int64/cdiv: division overflow in cdiv(min-int64, -1.int64)"literal: string
count= 66
) else unsafe-cdivstd/num/int64/unsafe-cdiv: (int64, int64) -> exn int64(ii: int64,jj: int64
) // Truncated modulus (as in C). See also `(%):(x : int64, y : int64) -> int64`. pub fun cmodstd/num/int64/cmod: (i : int64, j : int64) -> exn int64(ii: int64:int64std/core/types/int64: V, jj: int64:int64std/core/types/int64: V)result: -> exn int64 : exnstd/core/exn/exn: (E, V) -> V int64std/core/types/int64: V if jj: int64.is-zerostd/num/int64/is-zero: (i : int64) -> exn bool then throwstd/core/exn/throw: (message : string, info : ? exception-info) -> exn int64("std/num/int64/cmod: modulus by zero"literal: string
count= 35
) elif jj: int64 ==std/num/int64/(==): (x : int64, y : int64) -> exn bool -1literal: int
dec = -1
hex8 = 0xFF
bit8 = 0b11111111
.int64std/num/int64/int64: (i : int) -> exn int64 &&std/core/types/(&&): (x : bool, y : bool) -> exn bool ii: int64==std/num/int64/(==): (x : int64, y : int64) -> exn boolmin-int64std/num/int64/min-int64: int64 then throwstd/core/exn/throw: (message : string, info : ? exception-info) -> exn int64("std/num/int64/cmod: modulus overflow in cmod(min-int64, -1.int64)"literal: string
count= 65
) else unsafe-cmodstd/num/int64/unsafe-cmod: (int64, int64) -> exn int64(ii: int64,jj: int64
) // Truncated division (as in C). See also `(/):(x : int64, y : int64) -> int64`. inline fip extern unsafe-cdivstd/num/int64/unsafe-cdiv: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V inline "#1 / #2" // Truncated modulus (as in C). See also `(%):(x : int64, y : int64) -> int64`. inline fip extern unsafe-cmodstd/num/int64/unsafe-cmod: (int64, int64) -> int64 : (int64std/core/types/int64: V,int64std/core/types/int64: V) -> int64std/core/types/int64: V inline "#1 % #2" // Negate a 64-bit integer pub fip fun negatestd/num/int64/negate: (i : int64) -> int64( ii: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 -std/num/int64/(-): (x : int64, y : int64) -> int64
ii: int64 // Negate an 64-bit integer pub fip fun (~)std/num/int64/(~): (i : int64) -> int64(ii: int64 : int64std/core/types/int64: V)result: -> total int64 : totalstd/core/types/total: E int64std/core/types/int64: V 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 -std/num/int64/(-): (x : int64, y : int64) -> int64
ii: int64 /* Euclidean-0 division. Euclidean division is defined as: For any `D` and `d` where `d!=0` , we have: 1. `D == d*(D/d) + (D%d)` 2. `D%d` is always positive where `0 <= D%d < abs(d)` Moreover, Euclidean-0 is a total function, for the case where `d==0` we have that `D%0 == D` and `D/0 == 0` . So property (1) still holds, but not property (2). Useful laws that hold for Euclidean-0 division: * `D/(-d) == -(D/d)` * `D%(-d) == D%d` * `D/(2^n) == sar(D,n) ` (with `0 <= n <= 63`) * `D%(2^n) == D & ((2^n) - 1) ` (with `0 <= n <= 63`) Note that an interesting edge case is `min-int64 / -1` which equals `min-int64` since in modulo 64-bit arithmetic `min-int64 == -1 * min-int64 == -1 * (min-int64 / -1) + (min-int64 % -1)` satisfying property (1). Of course `(min-int64 + 1) / -1` is again positive (namely `max-int64`). See also _Division and modulus for computer scientists, Daan Leijen, 2001_ [pdf](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf) . */ pub fip fun (/)std/num/int64/(/): (x : int64, y : int64) -> int64( xx: int64 : int64std/core/types/int64: V, yy: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V if yy: int64 ==std/num/int64/(==): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 returnreturn: int64 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 if yy: int64 ==std/num/int64/(==): (x : int64, y : int64) -> bool -1literal: int
dec = -1
hex8 = 0xFF
bit8 = 0b11111111
.int64std/num/int64/int64: (i : int) -> int64 &&std/core/types/(&&): (x : bool, y : bool) -> bool xx: int64==std/num/int64/(==): (x : int64, y : int64) -> boolmin-int64std/num/int64/min-int64: int64 returnreturn: int64 xx: int64 val qq: int64 = unsafe-cdivstd/num/int64/unsafe-cdiv: (int64, int64) -> int64(xx: int64,yy: int64) val rr: int64 = unsafe-cmodstd/num/int64/unsafe-cmod: (int64, int64) -> int64(xx: int64,yy: int64) if rr: int64 >=std/num/int64/(>=): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 then qq: int64 elif yy: int64 >std/num/int64/(>): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 then qq: int64.decstd/num/int64/dec: (i : int64) -> int64 else qq: int64.incstd/num/int64/inc: (i : int64) -> int64
// Euclidean-0 modulus. See `(/):(x : int64, y : int64) -> int64` division for more information. pub fip fun (%)std/num/int64/(%): (x : int64, y : int64) -> int64( xx: int64 : int64std/core/types/int64: V, yy: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V if yy: int64 ==std/num/int64/(==): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 returnreturn: int64 xx: int64 if yy: int64 ==std/num/int64/(==): (x : int64, y : int64) -> bool -1literal: int
dec = -1
hex8 = 0xFF
bit8 = 0b11111111
.int64std/num/int64/int64: (i : int) -> int64 &&std/core/types/(&&): (x : bool, y : bool) -> bool xx: int64==std/num/int64/(==): (x : int64, y : int64) -> boolmin-int64std/num/int64/min-int64: int64 returnreturn: int64 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 val rr: int64 = unsafe-cmodstd/num/int64/unsafe-cmod: (int64, int64) -> int64(xx: int64,yy: int64) if rr: int64 >=std/num/int64/(>=): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 then rr: int64 elif yy: int64 >std/num/int64/(>): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 then rr: int64 +std/num/int64/(+): (x : int64, y : int64) -> int64 yy: int64 else rr: int64 -std/num/int64/(-): (x : int64, y : int64) -> int64
yy: int64 pub fip fun divmodstd/num/int64/divmod: (x : int64, y : int64) -> (int64, int64)( xx: int64 :int64std/core/types/int64: V, yy: int64 :int64std/core/types/int64: V )result: -> total (int64, int64) : (std/core/types/tuple2: (V, V) -> Vint64std/core/types/int64: V,int64std/core/types/int64: V) if yy: int64.is-zerostd/num/int64/is-zero: (i : int64) -> bool returnreturn: (int64, int64) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)zerostd/num/int64/zero: int64,xx: int64)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) if yy: int64 ==std/num/int64/(==): (x : int64, y : int64) -> bool -1literal: int
dec = -1
hex8 = 0xFF
bit8 = 0b11111111
.int64std/num/int64/int64: (i : int) -> int64 &&std/core/types/(&&): (x : bool, y : bool) -> bool xx: int64==std/num/int64/(==): (x : int64, y : int64) -> boolmin-int64std/num/int64/min-int64: int64 returnreturn: (int64, int64) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xx: int64,0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) val qq: int64 = unsafe-cdivstd/num/int64/unsafe-cdiv: (int64, int64) -> int64(xx: int64,yy: int64) val rr: int64 = unsafe-cmodstd/num/int64/unsafe-cmod: (int64, int64) -> int64(xx: int64,yy: int64) if rr: int64 >=std/num/int64/(>=): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 then (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)qq: int64, rr: int64)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) elif yy: int64 >std/num/int64/(>): (x : int64, y : int64) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64 then (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)qq: int64.decstd/num/int64/dec: (i : int64) -> int64, rr: int64 +std/num/int64/(+): (x : int64, y : int64) -> int64 yy: int64)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) else (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)qq: int64.incstd/num/int64/inc: (i : int64) -> int64, rr: int64 -std/num/int64/(-): (x : int64, y : int64) -> int64 yy: int64
)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) pub fun range/fold-int64std/num/int64/range/fold-int64: forall<a,e> (start : int64, end : int64, init : a, f : (int64, a) -> e a) -> e a( startstart: int64 : int64std/core/types/int64: V, endend: int64 : int64std/core/types/int64: V, initinit: $1798 : aa: V, ff: (int64, $1798) -> $1799 $1798 : (int64std/core/types/int64: V,aa: V) -> ee: E aa: V )result: -> 1852 1851 : ee: E aa: V if startstart: int64 >std/num/int64/(>): (x : int64, y : int64) -> $1799 bool endend: int64 then initinit: $1798 else val xx: $1798 = ff: (int64, $1798) -> $1799 $1798(startstart: int64,initinit: $1798) range/fold-int64std/num/int64/range/fold-int64: (start : int64, end : int64, init : $1798, f : (int64, $1798) -> $1799 $1798) -> $1799 $1798(pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int64) -> $1799 int64(startstart: int64.incstd/num/int64/inc: (i : int64) -> $1799 int64), endend: int64, xx: $1798, ff: (int64, $1798) -> $1799 $1798) pub fun fold-int64std/num/int64/fold-int64: forall<a,e> (n : int64, init : a, f : (int64, a) -> e a) -> e a( nn: int64 : int64std/core/types/int64: V, initinit: $1771 : aa: V, ff: (int64, $1771) -> $1772 $1771 : (int64std/core/types/int64: V,aa: V) -> ee: E aa: V )result: -> 1797 1796 : ee: E aa: V range/fold-int64std/num/int64/range/fold-int64: (start : int64, end : int64, init : $1771, f : (int64, $1771) -> $1772 $1771) -> $1772 $1771(zerostd/num/int64/zero: int64,nn: int64.decstd/num/int64/dec: (i : int64) -> $1772 int64,initinit: $1771,ff: (int64, $1771) -> $1772 $1771) // Executes `action` for each integer between `start` upto `end` (including both `start` and `end` ). // If `start > end` the function returns without any call to `action` . // If `action` returns `Just`, the iteration is stopped and the result returned pub fun range/for-while64std/num/int64/range/for-while64: forall<a,e> (start : int64, end : int64, action : (int64) -> e maybe<a>) -> e maybe<a>( startstart: int64: int64std/core/types/int64: V, endend: int64 : int64std/core/types/int64: V, ^actionaction: (int64) -> $1870 maybe<$1869> : (int64std/core/types/int64: V) -> ee: E maybestd/core/types/maybe: V -> V<aa: V> )result: -> 1932 maybe<1931> : ee: E maybestd/core/types/maybe: V -> V<aa: V> fun reprep: (i : int64) -> $1870 maybe<$1869>( ii: int64 : int64std/core/types/int64: V )result: -> $1870 maybe<$1869> if ii: int64 <=std/num/int64/(<=): (x : int64, y : int64) -> $1870 bool endend: int64 then match actionaction: (int64) -> $1870 maybe<$1869>(ii: int64) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> reprep: (i : int64) -> $1870 maybe<$1869>(pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int64) -> $1870 int64(ii: int64.incstd/num/int64/inc: (i : int64) -> $1870 int64)) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1869) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1869) else Nothingstd/core/types/Nothing: forall<a> maybe<a> reprep: (i : int64) -> $1870 maybe<$1869>(startstart: int64) pub fun for-while64std/num/int64/for-while64: forall<a,e> (n : int64, action : (int64) -> e maybe<a>) -> e maybe<a>( nn: int64 : int64std/core/types/int64: V, ^actionaction: (int64) -> $1940 maybe<$1939> : (int64std/core/types/int64: V) -> ee: E maybestd/core/types/maybe: V -> V<aa: V> )result: -> 1964 maybe<1963> : ee: E maybestd/core/types/maybe: V -> V<aa: V> range/for-while64std/num/int64/range/for-while64: (start : int64, end : int64, action : (int64) -> $1940 maybe<$1939>) -> $1940 maybe<$1939>(zerostd/num/int64/zero: int64,nn: int64.decstd/num/int64/dec: (i : int64) -> $1940 int64,actionaction: (int64) -> $1940 maybe<$1939>) pub fun list64std/num/int64/list64: (lo : int64, hi : int64) -> list<int64>( lolo: int64: int64std/core/types/int64: V, hihi: int64: int64std/core/types/int64: V )result: -> total list<int64> : totalstd/core/types/total: E liststd/core/types/list: V -> V<int64std/core/types/int64: V> if lolo: int64 <=std/num/int64/(<=): (x : int64, y : int64) -> bool hihi: int64 then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( lolo: int64, list64std/num/int64/list64: (lo : int64, hi : int64) -> list<int64>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int64) -> int64(lolo: int64.incstd/num/int64/inc: (i : int64) -> int64), hihi: int64 ) ) else Nilstd/core/types/Nil: forall<a> list<a> pub fun sum64std/num/int64/sum64: (xs : list<int64>) -> int64( xsxs: list<int64> : liststd/core/types/list: V -> V<int64std/core/types/int64: V> )result: -> total int64 : int64std/core/types/int64: V // xs.foldl( 0.int64, fn(x,y) x + y ) sumacc64std/num/int64/sumacc64: (xs : list<int64>, acc : int64) -> int64(xsxs: list<int64>,0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
.int64std/num/int64/int64: (i : int) -> int64
) fun sumacc64std/num/int64/sumacc64: (xs : list<int64>, acc : int64) -> int64( xsxs: list<int64> : liststd/core/types/list: V -> V<int64std/core/types/int64: V>, accacc: int64 : int64std/core/types/int64: V )result: -> total int64 : int64std/core/types/int64: V match xsxs: list<int64> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: int64,xxxx: list<int64>) -> sumacc64std/num/int64/sumacc64: (xs : list<int64>, acc : int64) -> int64(xxxx: list<int64>,accacc: int64+std/num/int64/(+): (x : int64, y : int64) -> int64xx: int64) Nilstd/core/types/Nil: forall<a> list<a> -> accacc: int64 // carry-less multiply by -1 gives the _prefix sum_ fun test-prefix-sumstd/num/int64/test-prefix-sum: () -> string()result: -> total string val xx: int64 = 0x050Fliteral: int
dec = 1295
hex16= 0x050F
bit16= 0b0000010100001111
.int64std/num/int64/int64: (i : int) -> int64 // = 0b0000010100001111 clmulstd/num/int64/clmul: (x : int64, y : int64) -> int64(xx: int64, -1literal: int
dec = -1
hex8 = 0xFF
bit8 = 0b11111111
.int64std/num/int64/int64: (i : int) -> int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string
// = 0x305 // carry-less multiply of x by x spreads the bits fun test-bit-spread1std/num/int64/test-bit-spread1: () -> string()result: -> total string val xx: int64 = 0x05FFliteral: int
dec = 1535
hex16= 0x05FF
bit16= 0b0000010111111111
.int64std/num/int64/int64: (i : int) -> int64 // = 0b0000010111111111 clmulstd/num/int64/clmul: (x : int64, y : int64) -> int64(xx: int64,xx: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string
// = 0x115555 = 0b00000000000100010101010101010101 fun test-bit-spread2std/num/int64/test-bit-spread2: () -> string()result: -> total string val xx: int64 = 0x05FBliteral: int
dec = 1531
hex16= 0x05FB
bit16= 0b0000010111111011
.int64std/num/int64/int64: (i : int) -> int64 // = 0b0000010111111011 clmulstd/num/int64/clmul: (x : int64, y : int64) -> int64(xx: int64,xx: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string
// = 0x115545 = 0b00000000000100010101010101000101 fun zip-clmulstd/num/int64/zip-clmul: (x : int64) -> int64(xx: int64 : int64std/core/types/int64: V)result: -> total int64 : int64std/core/types/int64: V orstd/num/int64/or: (int64, int64) -> int64(clmulstd/num/int64/clmul: (x : int64, y : int64) -> int64(xx: int64,xx: int64),clmulrstd/num/int64/clmulr: (x : int64, y : int64) -> int64(xx: int64,xx: int64)) fun test-clmulr1std/num/int64/test-clmulr1: () -> string()result: -> total string val xx: int64 = 0x33literal: int
dec = 51
hex8 = 0x33
bit8 = 0b00110011
.int64std/num/int64/int64: (i : int) -> int64 bit-zipstd/num/int64/bit-zip: (i : int64) -> int64(xx: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string ++std/core/types/(++): (x : string, y : string) -> string " == "literal: string
count= 4
++std/core/types/(++): (x : string, y : string) -> string zip-clmulstd/num/int64/zip-clmul: (x : int64) -> int64(xx: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string
// 0x505 fun test-clmulr2std/num/int64/test-clmulr2: () -> string()result: -> total string val xx: int64 = 0x12346789ABCDEF0literal: int
dec = 81986702028889840
hex64= 0x012346789ABCDEF0
bit64= 0b0000000100100011010001100111100010011010101111001101111011110000
.int64std/num/int64/int64: (i : int) -> int64 bit-zipstd/num/int64/bit-zip: (i : int64) -> int64(xx: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string ++std/core/types/(++): (x : string, y : string) -> string " == "literal: string
count= 4
++std/core/types/(++): (x : string, y : string) -> string zip-clmulstd/num/int64/zip-clmul: (x : int64) -> int64(xx: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string
// 0x41464D5A717C7F80 fun clmulrevstd/num/int64/clmulrev: (x : int64, y : int64) -> int64(xx: int64 : int64std/core/types/int64: V, yy: int64 : int64std/core/types/int64: V)result: -> total int64 : int64std/core/types/int64: V clmulstd/num/int64/clmul: (x : int64, y : int64) -> int64(xx: int64.bit-reversestd/num/int64/bit-reverse: (i : int64) -> int64, yy: int64.bit-reversestd/num/int64/bit-reverse: (i : int64) -> int64).bit-reversestd/num/int64/bit-reverse: (i : int64) -> int64 fun test-clmulrev1std/num/int64/test-clmulrev1: () -> string()result: -> total string val xx: int64 = 0x12345678literal: int
dec = 305419896
hex32= 0x12345678
bit32= 0b00010010001101000101011001111000
.int64std/num/int64/int64: (i : int) -> int64 val yy: int64 = 0x89ABCDEFliteral: int
dec = 2309737967
hex64= 0x0000000089ABCDEF
bit64= 0b0000000000000000000000000000000010001001101010111100110111101111
.int64std/num/int64/int64: (i : int) -> int64.byte-reversestd/num/int64/byte-reverse: (i : int64) -> int64 clmulrstd/num/int64/clmulr: (x : int64, y : int64) -> int64(xx: int64,yy: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string ++std/core/types/(++): (x : string, y : string) -> string " == "literal: string
count= 4
++std/core/types/(++): (x : string, y : string) -> string clmulrevstd/num/int64/clmulrev: (x : int64, y : int64) -> int64(xx: int64,yy: int64).show-hexstd/num/int64/show-hex: (i : int64, width : ? int, use-capitals : ? bool, pre : ? string) -> string