1
|
{"version":3,"sources":["../../../src/php/math/fmod.js"],"names":["module","exports","fmod","x","y","tmp","tmp2","p","pY","l","l2","toExponential","match","parseInt","length","Math","round","log","pow","toFixed","parseFloat"],"mappings":";;AAAAA,OAAOC,OAAP,GAAiB,SAASC,IAAT,CAAeC,CAAf,EAAkBC,CAAlB,EAAqB;AACpC;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAIC,GAAJ;AACA,MAAIC,IAAJ;AACA,MAAIC,IAAI,CAAR;AACA,MAAIC,KAAK,CAAT;AACA,MAAIC,IAAI,GAAR;AACA,MAAIC,KAAK,GAAT;;AAEAL,QAAMF,EAAEQ,aAAF,GAAkBC,KAAlB,CAAwB,iBAAxB,CAAN;AACAL,MAAIM,SAASR,IAAI,CAAJ,CAAT,EAAiB,EAAjB,IAAuB,CAACA,IAAI,CAAJ,IAAS,EAAV,EAAcS,MAAzC;AACAT,QAAMD,EAAEO,aAAF,GAAkBC,KAAlB,CAAwB,iBAAxB,CAAN;AACAJ,OAAKK,SAASR,IAAI,CAAJ,CAAT,EAAiB,EAAjB,IAAuB,CAACA,IAAI,CAAJ,IAAS,EAAV,EAAcS,MAA1C;;AAEA,MAAIN,KAAKD,CAAT,EAAY;AACVA,QAAIC,EAAJ;AACD;;AAEDF,SAAQH,IAAIC,CAAZ;;AAEA,MAAIG,IAAI,CAAC,GAAL,IAAYA,IAAI,EAApB,EAAwB;AACtB;AACAE,QAAIM,KAAKC,KAAL,CAAWD,KAAKE,GAAL,CAASX,IAAT,IAAiBS,KAAKE,GAAL,CAAS,EAAT,CAA5B,CAAJ;AACAP,SAAKK,KAAKG,GAAL,CAAS,EAAT,EAAaT,CAAb,CAAL;;AAEA,WAAO,CAACH,OAAOI,EAAR,EAAYS,OAAZ,CAAoBV,IAAIF,CAAxB,IAA6BG,EAApC;AACD,GAND,MAMO;AACL,WAAOU,WAAWd,KAAKa,OAAL,CAAa,CAACZ,CAAd,CAAX,CAAP;AACD;AACF,CAnCD","file":"fmod.js","sourcesContent":["module.exports = function fmod (x, y) {\n // discuss at: http://locutus.io/php/fmod/\n // original by: Onno Marsman (https://twitter.com/onnomarsman)\n // input by: Brett Zamir (http://brett-zamir.me)\n // bugfixed by: Kevin van Zonneveld (http://kvz.io)\n // example 1: fmod(5.7, 1.3)\n // returns 1: 0.5\n\n var tmp\n var tmp2\n var p = 0\n var pY = 0\n var l = 0.0\n var l2 = 0.0\n\n tmp = x.toExponential().match(/^.\\.?(.*)e(.+)$/)\n p = parseInt(tmp[2], 10) - (tmp[1] + '').length\n tmp = y.toExponential().match(/^.\\.?(.*)e(.+)$/)\n pY = parseInt(tmp[2], 10) - (tmp[1] + '').length\n\n if (pY > p) {\n p = pY\n }\n\n tmp2 = (x % y)\n\n if (p < -100 || p > 20) {\n // toFixed will give an out of bound error so we fix it like this:\n l = Math.round(Math.log(tmp2) / Math.log(10))\n l2 = Math.pow(10, l)\n\n return (tmp2 / l2).toFixed(l - p) * l2\n } else {\n return parseFloat(tmp2.toFixed(-p))\n }\n}\n"]}
|