# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ XXX copied definition from tests/numbers.updoc ? def like(v) :any { return def conformer { to __conformTo(_) :any { return v }}} # value: and ? [0 & 0, 0 & 1, 1 & 0, 1 & 1] # value: [0, 0, 0, 1] ? 3 & 10 # value: 2 ? -1 & 1415926 # value: 1415926 ? -1 & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF # value: 340282366920938463463374607431768211455 ? -16 & 0xFF # value: 240 ? 3 & like(10) # value: 2 or ? [0 | 0, 0 | 1, 1 | 0, 1 | 1] # value: [0, 1, 1, 1] ? 3 | 10 # value: 11 ? -1 | 1415926 # value: -1 left shift ? for x in [-2, -1, 0, 1, 2, 3, 4, 5, 2**32, 2**64] { > for y in [-2, -1, 0, 1, 2, 3, 4, 5, 32, 64] { > interp.pushTestStep(`$x << $y`, [["value", E.toQuote((x * 2 ** y).floor())]]) }} right shift ? for x in [-2, -1, 0, 1, 2, 3, 4, 5, 2**32, 2**64] { > for y in [-2, -1, 0, 1, 2, 3, 4, 5, 32, 64] { > interp.pushTestStep(`$x >> $y`, [["value", E.toQuote((x / 2 ** y).floor())]]) }} toOctetsUnsigned (produce list of integers representing the nonnegative input integer in base 256) ? 0.toOctetsUnsigned() # value: [0] ? 10.toOctetsUnsigned() # value: [10] ? (-10).toOctetsUnsigned() # problem: (-10).toOctetsUnsigned(): nonnegative numbers only ? 10000001.toOctetsUnsigned() # value: [152, 150, 129] ? 10000002.toOctetsUnsigned() # value: [152, 150, 130] ? 10000003.toOctetsUnsigned() # value: [152, 150, 131] ? 10000004.toOctetsUnsigned() # value: [152, 150, 132] ? 10000005.toOctetsUnsigned() # value: [152, 150, 133] ? (2 ** 6).toOctetsUnsigned() # value: [64] ? (2 ** 7).toOctetsUnsigned() # value: [128] ? (2 ** 8).toOctetsUnsigned() # value: [1, 0] ? (2 ** 14).toOctetsUnsigned() # value: [64, 0] ? (2 ** 15).toOctetsUnsigned() # value: [128, 0] ? (2 ** 16).toOctetsUnsigned() # value: [1, 0, 0] bitLength (two's complement, not including sign bit) ? for i in -5..5 { print(i.bitLength(), " ") } # stdout: 3 2 2 1 0 0 1 2 2 3 3 cryptoHash (Unsigned integer interpretation of the SHA-1 hash of the smallest possible octet array holding the big-endian two's complement representation of the integer.) ? 0.cryptoHash() # value: 523292266480032572263097387253846278739400489039 ? 10.cryptoHash() # value: 992120700831975926627035735038122334788054782716 ? (-10).cryptoHash() # value: 885393120089404236135066985154081015618261946226 ? 10000001.cryptoHash() # value: 382064925828890872342377433413917253333972024416 ? 10000002.cryptoHash() # value: 1033912670282953026478972818820010722176128073325 ? 10000003.cryptoHash() # value: 47255196895205160731987244561159478631887357377 ? 10000004.cryptoHash() # value: 412897248500657771667886264468852369692723684603 ? 10000005.cryptoHash() # value: 82190111274176756684133692948252028599388244870 ? 10000001.cryptoHash().cryptoHash() # value: 199755468581798012116980059031327772311432990918 ? 10000002.cryptoHash().cryptoHash() # value: 491334967455811024286718200948232903314371083067 ? 10000003.cryptoHash().cryptoHash() # value: 419347780577914302219745114857990865255466720450 ? 10000004.cryptoHash().cryptoHash() # value: 663509581037334598795999104000070023073973418364 ? (2 ** 6).cryptoHash() # value: 881863549714837967690767385920353582608496796920 ? (2 ** 7).cryptoHash() # value: 1073030966911870318295978990948578847662666698388 ? (2 ** 8).cryptoHash() # value: 81117187455401937957276750042111964595127455290 ? (2 ** 14).cryptoHash() # value: 1062234139915614777785861401976703160164837074038 ? (2 ** 15).cryptoHash() # value: 993476404410663933716582440343802929274263197432 ? (2 ** 16).cryptoHash() # value: 850838329774993908800802690288778964578933554047 ? (-2 ** 6).cryptoHash() # value: 881863549714837967690767385920353582608496796920 ? (-2 ** 7).cryptoHash() # value: 1139272354028755330155064661926150981428725793061 ? (-2 ** 8).cryptoHash() # value: 81117187455401937957276750042111964595127455290 ? (-2 ** 14).cryptoHash() # value: 1062234139915614777785861401976703160164837074038 ? (-2 ** 15).cryptoHash() # value: 560989116163612029648017223023735572962370198302 ? (-2 ** 16).cryptoHash() # value: 850838329774993908800802690288778964578933554047