lambdaway
::
bigint
6
|
list
|
login
|
load
|
|
_h1 bigint | [[curzon_numbers]] _p [[BigInt|https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt]] est un objet natif qui permet de représenter des nombres entiers supérieurs à 2^53 (la plus grande valeur entière qui puisse être représentée par le type primitif Number). BigInt peut être utilisé afin de représenter de grands entiers de n'importe quelle taille. {prewrap '{pow 2 128} -> {pow 2 128} '{BigInt {pow 2 128}} -> {BigInt {pow 2 128}} '{BI.** 2 128} -> {BI.** 2 128} '{BI.+ {BigInt 340282366920938463463374607431768211456} {BigInt 2}} -> {BI.+ {BigInt 340282366920938463463374607431768211456} {BigInt 2}} '{BI.- {BigInt 340282366920938463463374607431768211456} {BigInt 2}} -> {BI.- {BigInt 340282366920938463463374607431768211456} {BigInt 2}} '{BI.* {BigInt 340282366920938463463374607431768211456} {BigInt 2}} -> {BI.* {BigInt 340282366920938463463374607431768211456} {BigInt 2}} '{BI./ {BigInt 340282366920938463463374607431768211456} {BigInt 2}} -> {BI./ {BigInt 340282366920938463463374607431768211456} {BigInt 2}} '{BI.** {BigInt 340282366920938463463374607431768211456} {BigInt 2}} -> {BI.** {BigInt 340282366920938463463374607431768211456} {BigInt 2}} '{floor {/ 123456789 2}} -> {floor {/ 123456789 2}} '{% 123456789 2} -> {% 123456789 2} '{BI./ {BigInt 123456789} {BigInt 2}} -> {BI./ {BigInt 123456789} {BigInt 2}} '{BI.% {BigInt 123456789} {BigInt 2}} -> {BI.% {BigInt 123456789} {BigInt 2}} '{* {pow 2 64} {pow 2 64}} -> {* {pow 2 64} {pow 2 64}} '{long_mult {long_mult {pow 2 32} {pow 2 32}} {long_mult {pow 2 32} {pow 2 32}}} -> {long_mult {long_mult {pow 2 32} {pow 2 32}} {long_mult {pow 2 32} {pow 2 32}}} '{BI.* {pow 2 64} {pow 2 64}} -> {BI.* {pow 2 64} {pow 2 64}} '{def fac {lambda {:a :b} {if {< :b 1} then :a else {fac {BI.* :a :b} {- :b 1}}}}} -> {def fac {lambda {:a :b} {if {< :b 1} then :a else {fac {BI.* :a :b} {- :b 1}}}}} '{fac 1 100} -> {fac 1 100} '{bigfac 100} -> {bigfac 100} '{nthPrime 1000} -> {nthPrime 1000} } _h2 computing N = {sup 5 {sup 4 {sup 3 {sup 2}}}} {pre '{def N {BI.** 5 {BI.** 4 {BI.** 3 2}}}} -> {def N {BI.** 5 {BI.** 4 {BI.** 3 2}}}} length: '{def L {W.length {N}}} -> {def L {W.length {N}}} = {L} 20 first digits: '{W.slice 0 20 {N}} -> {W.slice 0 20 {N}} 20 last digits: '{W.slice -20 {L} {N}} -> {W.slice -20 {L} {N}} } _p {i alain marty 2022/03/28} {script LAMBDATALK.DICT['BigInt'] = function() { var args = arguments[0].trim(); return BigInt( Number(args) ) }; LAMBDATALK.DICT['BI.+'] = function() { var args = arguments[0].trim().split(' '); return BigInt( args[0] ) + BigInt( args[1] ) }; LAMBDATALK.DICT['BI.-'] = function() { var args = arguments[0].trim().split(' '); return BigInt( args[0] ) - BigInt( args[1] ) }; LAMBDATALK.DICT['BI.*'] = function() { var args = arguments[0].trim().split(' '); return BigInt( args[0] ) * BigInt( args[1] ) }; LAMBDATALK.DICT['BI./'] = function() { var args = arguments[0].trim().split(' '); return BigInt( args[0] ) / BigInt( args[1] ) }; LAMBDATALK.DICT['BI.%'] = function() { var args = arguments[0].trim().split(' '); return BigInt( args[0] ) % BigInt( args[1] ) }; LAMBDATALK.DICT['BI.**'] = function() { var args = arguments[0].trim().split(' '); return BigInt( args[0] ) ** BigInt( args[1] ) }; // more LAMBDATALK.DICT['bigfac'] = function() { var args = arguments[0].trim(); var fac = function(n) { return (n===0n)? 1n : n*fac(n-1n) }; return fac( BigInt( args ) ) }; LAMBDATALK.DICT['nthPrime'] = function() { var isPrime = function(p) { for (let i = 2n; i * i <= p; i++) { if (p % i === 0n) return false; } return true; }; // Takes a BigInt as an argument and returns a BigInt var nthPrime = function(nth) { let maybePrime = 2n; let prime = 0n; while (nth >= 0n) { if (isPrime(maybePrime)) { nth -= 1n; prime = maybePrime; } maybePrime += 1n; } return prime; }; //nthPrime(20n) // ↪ 73n var args = arguments[0].trim(); return nthPrime( BigInt( args ) ) }; }
lambdaway v.20211111