diff options
Diffstat (limited to 'src/library.js')
-rw-r--r-- | src/library.js | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/library.js b/src/library.js index 4c0f790f..d9e1942f 100644 --- a/src/library.js +++ b/src/library.js @@ -1642,6 +1642,7 @@ LibraryManager.library = { next = get(); {{{ makeSetValue('argPtr++', 0, 'next', 'i8') }}}; } + if (next === 0) return fields-1; // we failed to read this field formatIndex += nextC - formatIndex + 1; continue; } @@ -3447,13 +3448,25 @@ LibraryManager.library = { return limit; }, - // Use browser's Math.random(). We can't set a seed, though. - srand: function(seed) {}, // XXX ignored - rand: function() { - return Math.floor(Math.random()*0x80000000); + __rand_seed: 'allocate([0x0273459b, 0, 0, 0], "i32", ALLOC_STATIC)', + srand__deps: ['__rand_seed'], + srand: function(seed) { + {{{ makeSetValue('___rand_seed', 0, 'seed', 'i32') }}} + }, + rand_r__sig: 'ii', + rand_r__asm: true, + rand_r: function(seedp) { + seedp = seedp|0; + var val = 0; + val = ((Math_imul({{{ makeGetValueAsm('seedp', 0, 'i32') }}}, 31010991)|0) + 0x676e6177 ) & {{{ cDefine('RAND_MAX') }}}; + {{{ makeSetValueAsm('seedp', 0, 'val', 'i32') }}}; + return val|0; }, - rand_r: function(seed) { // XXX ignores the seed - return Math.floor(Math.random()*0x80000000); + rand__sig: 'i', + rand__asm: true, + rand__deps: ['rand_r', '__rand_seed'], + rand: function() { + return _rand_r(___rand_seed)|0; }, drand48: function() { |