前提
BigIntを使用した計算がしたいのですが、別の型と認識されて計算がうまくいきません。
どうすれば、型をそろえる事ができるでしょうか?
発生している問題・エラーメッセージ
エラーメッセージ
/workspace/Main.c:29
int = (s[3n] = (s[3n] ^ (s[3n] >> 19n)) ^ (t ^ (t > 8n)));
^
TypeError: Cannot mix BigInt and other types, use explicit conversions
該当のソースコード
javascript
1//seed値を入力した時だけ初期化する 2function XorShift(){} 3 4XorShift.prototype.initRandom = function(s) { 5 let int = 0; 6 s = String(s); 7 for(i = 0; i < s.length; i++) { 8 if(i == 0) { 9 int += s.charCodeAt(i); 10 } else { 11 int += s.charCodeAt(i) * 31 ** i; 12 } 13 } 14 15 if(int > 2 ** 31) { 16 let max = Math.floor(int / 2 ** 31); 17 let min = int - max; 18 int = max + min; 19 } 20 int = BigInt(int); 21 this._s = new Array(123456789n, 362436069n, 521288629n, 88675123n); 22 for(let i = 0n; i < 4n; i++) this._s[i] = int = 1812433253n * (int ^ (int >> 30n)) + i; 23}; 24 25XorShift.prototype.XorShift = function() { 26 let s = this._s; 27 let t = (s[0n] ^ (s[0n] << 11n)); 28 s[0n] = s[1n]; s[1n] = s[2n]; s[2n] = s[3n]; 29 int = (s[3n] = (s[3n] ^ (s[3n] >> 19n)) ^ (t ^ (t > 8n))); 30 int = Math.abs(int); 31 return parseFloat("0." + int); 32}; 33 34let rand = new XorShift(); 35rand.initRandom("あああ"); 36for(j = 0; j < 10; j++) console.log(rand.XorShift()); 37 38
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2023/01/19 22:54