Dorian 0d073fa89e Add comprehensive installation and setup documentation
- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
2026-01-27 17:18:21 +00:00

1 line
288 KiB
Plaintext

{"version":3,"sources":["~lib/rt/common.ts","~lib/shared/typeinfo.ts","~lib/rt/pure.ts","~lib/rt/tlsf.ts","~lib/gc.ts","assembly/index.ts","~lib/arraybuffer.ts","~lib/util/error.ts","~lib/memory.ts","~lib/util/memory.ts","~lib/util/number.ts","~lib/util/math.ts","~lib/util/string.ts","~lib/typedarray.ts"],"names":[],"mappings":"o9BG0RE,AAAI,AALO,AAFK,KAEO,KAKZ,MAET,AAAK,AAAM,EAAQ,KADd,GAKL,AAAK,AAAO,EAAS,AADhB,EAAM,AAAW,MACI,IAAa,KACvC,EAAM,MAMR,AAAW,OACX,AAAI,AAFO,SAED,EAAY,MACtB,AAAI,IAAM,EAAY,MAGtB,AAAI,EAAS,AApIX,EAA2B,AAAC,AAAkB,EAAjB,EAAM,IAAyB,UAqI5D,AA5HA,EAA2B,AAAC,AAAkB,EAAjB,EAAM,IAAyB,IAC5D,KA8HA,AAAI,AAAC,KAEH,AApJF,EAA2B,EAAM,IACjC,AAXF,AACE,EAA2B,EAAM,OA6JN,AAAE,EAAK,YAGhC,AAAI,AAAC,KAAO,OAAc,AAAE,EAAK,mBAxGrC,AAAgB,OAOhB,AAAI,AAHY,AADJ,qBAII,KAEd,AAAI,AADU,AAAC,EAAY,GAAc,GAAkB,EAAY,MACzD,SACZ,AAAY,EAAM,IAClB,EAAe,AAAY,AAA0B,EAAzB,EAAY,SAE5B,AADJ,AArHa,EAA2B,GAAkB,KAAe,aA4HrF,AAAI,EAAY,KAKd,AAAI,AADU,AAAC,AAFA,AADJ,AAnIM,EAA2B,aAsIlB,GAAc,GAAkB,EAAY,MACxD,SACZ,AAAY,EAAM,IAClB,EAAc,AAAY,AAAyB,EAAxB,EAAW,SAC9B,MAKZ,EAAe,EAAY,MAS3B,AAAa,EAA2B,GAAiB,KA/EzD,AACE,EAA2B,AAAC,AAAC,AAkF/B,AAAI,AATO,EAAY,KASZ,MAET,AAAK,AAAM,EAAQ,KADd,GAKL,AAAK,AAAO,EAAS,AADhB,EAAM,AAAW,MACI,IAAa,KACvC,EAAM,MAzF6B,GAAW,GAAc,SA+F9D,EAAa,KACb,EAFW,KAGX,AAAI,IAAM,EAAY,MACtB,AAzFE,EAA2B,AAAC,AAAkB,EAAjB,EAAM,IAAyB,IAC5D,KA2FF,OAAe,EAAK,OACpB,AAhHE,EAA2B,EAAM,IACjC,AA+Gc,AAzHd,EAA2B,EAAM,OAyHA,EAAK,YA8IxC,AAAI,AADO,IAjBX,AAAI,AAFO,AA7MT,UAmNA,AAAI,AAA0B,EAA1B,EAAQ,MAEV,AAAW,OADX,EAAS,oBAoBb,EAAc,AAAmB,EAAW,GAA9B,AAFC,EAAQ,GAEE,OACzB,EAAY,KACZ,EAAY,KAIZ,AADO,AAAkB,EAAQ,GAAO,KAC1B,KACd,AAtOE,EACA,MAuOF,AAAY,EAAM,UAmClB,AAAI,AAAC,AADM,OAKT,AAAI,AADc,EACA,AAFA,OAEe,AAAY,EAAc,KAAe,SAAG,EAE7E,AADO,KACM,KACb,GAAc,OACU,EAAK,KAC3B,SAAgB,KACX,AAAc,MAAG,EAAK,KACzB,eAAsB,KADY,AAAE,WAFF,AAAE,WAM9B,GAAM,GAA+C,EAAiB,KAChF,AAAO,WAtBT,AAAI,EAAQ,SAA+B,cACzB,AAAC,EAAO,GAAW,mBAnHrC,AAAK,AAFO,EAjBZ,AAAI,EAAO,MAET,AAAK,AAAM,EAAQ,KADd,GAMa,EAAO,SACrB,EAAQ,EAAM,EAAW,AAAW,MAAU,MAGlD,AAAK,AAAO,EAAgB,AADvB,EAAM,AAHO,MAIe,IAAa,KAC9C,EAAM,aAKuB,EAAM,QAc5B,AA1LP,EAA2B,AAAC,AAAkB,AA0LZ,GA1LL,EAAM,IAAyB,QAiL5D,AAAK,AADO,KAAc,EAAO,EAAK,SAO7B,EAAkB,AA3M7B,AACE,EAA2B,AAuMpB,AAAW,KAvMe,sBAqMxB,SAqGX,AAAI,AAAY,AAJhB,AAAkB,IAElB,AAAkB,AAAO,AAAC,AAR1B,AAAI,EAAO,SAET,EAAQ,AAAC,EAAM,EAAW,AAAW,KAAU,QAKzC,EAAkB,AAAqD,AAjQ7E,MAiQ8B,AAAC,EAAsB,GAAM,MAC5B,KAAU,KAAa,aAEzB,KAC7B,AAAI,AAAY,IAAe,KAAG,GAG1B,EAAM,EAAsB,GAAI,EAAqB,UAnF/D,AAAI,AADY,AAAC,AAJD,OAIa,GAAc,UAEzC,EAAe,EAAQ,EAAY,OAGnC,AADY,AAA8D,EAA5C,EAA2B,MAC1C,AAAC,EAAY,GAAkB,MAC9C,AAAY,EAAM,KAIlB,EAAe,EAAY,MAC3B,AAtRuB,EAA2B,GAAkB,KAAe,IAsRnF,iBAA0B,YAkH5B,AAAI,AAAC,AADO,AAAY,EAAM,AADZ,AAAY,aAI1B,AAAyB,IAEzB,AAAyB,IAEpB,AADG,AAAY,EAAM,SAExB,AAAW,EAAM,IACqB,EAAM,UAUnC,KACf,EAAa,KACb,EAAe,KACf,AAAY,EAAM,IAClB,AAAa,EAAM,EAAc,SAkEjC,AAAO,AACS,EAAmB,EAAM,IACrC,QDxTJ,AAAI,EAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,YAwKlB,AAAI,EAAM,MAAa,AAAU,AAAkB,EAAM,YMjQvD,ECsLA,AAAI,ADtLW,KCuLf,AAAU,EAAM,KAChB,AAAU,EAAO,GAAI,GAAG,KACxB,AAAI,EAAK,KAET,AAAU,EAAO,GAAG,KACpB,AAAU,EAAO,GAAG,KACpB,AAAU,EAAO,KAAI,GAAG,KACxB,AAAU,EAAW,GAAG,KACxB,AAAI,EAAK,KACT,AAAU,EAAO,GAAG,KACpB,AAAU,EAAO,GAAI,GAAG,KACxB,AAAI,EAAK,KAKT,EAAK,AAFU,EAAC,GAAO,QAQvB,AAAW,AAPX,EAAQ,KAOS,KACjB,AAAW,EAAO,AANlB,EAAK,MAMiB,GAAG,KACzB,AAAI,EAAK,KACT,AAAW,EAAO,GAAG,KACrB,AAAW,EAAO,GAAG,KACrB,AAAW,EAAO,KAAI,GAAI,KAC1B,AAAW,EAAW,GAAG,KACzB,AAAI,EAAK,KACT,AAAW,EAAO,GAAI,KACtB,AAAW,EAAO,GAAI,KACtB,AAAW,EAAO,GAAI,KACtB,AAAW,EAAO,GAAI,KACtB,AAAW,EAAO,KAAI,GAAI,KAC1B,AAAW,EAAW,GAAI,KAC1B,AAAW,EAAW,GAAI,KAC1B,AAAW,EAAW,GAAI,KAI1B,EAAQ,AADJ,AAAM,EAAO,GAAb,QAEJ,EAAK,OAIL,AAAO,EAAK,KACV,AAAW,EAAM,KACjB,AAAW,EAAO,GAAG,KACrB,AAAW,EAAO,GAAI,KACtB,AAAW,EAAO,GAAI,KACtB,EAAK,KACL,EAAQ,gBHzOV,AAAI,EAAc,MAAuB,MAAgC,cAEzE,AAAY,AADC,AAAQ,AAAS,EAAU,KAAW,MAC5B,SJsPzB,AAAI,QAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,6BIpFF,cJqPhB,AAAI,EAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,YIpFhB,OACA,EAAiB,KACjB,EAAkB,YJmPpB,AAAI,QAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,SWi6BV,GAAQ,OR//BhB,AAAO,EAAK,AAAS,UAMrB,AAAS,WACT,AAAO,AAAC,AAAQ,AAPT,EAAK,AAAS,KAOO,KAAO,KACjC,EAAK,EAAK,gBQ2IV,AAAI,EAAc,AAAK,QAAsC,eAC7D,AAAU,AAAiB,EAAjB,MAA+B,QAZzC,AAAI,EAAc,AAAK,QAAsC,eAC7C,AAAiB,EAAjB,sBXsHlB,AAAI,SAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,0GG6BhB,EAAe,MACf,EAAe,MHmIjB,AAAI,QAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,SWiCV,EAAQ,aRFd,OACA,EAAmB,KACnB,EAAY,AAAC,EAAK,IAAgB,MAClC,EAAkB,YAlCpB,AAAI,AAAC,KAvEA,AAAQ,MAAG,EAAI,eAGc,oDAC3B,AAAQ,MAAG,EAAI,KAAc,MATzB,AAHX,EAAS,KAGQ,AAUe,oDADO,WAGrC,AQ2/BW,KAAkB,EAAgB,IAAiB,KRlgCvC,WAUzB,AAAQ,EAAY,WACf,AAAQ,MAAG,EAAI,UAEU,AADjB,AAAC,GAAW,OA7BzB,AAAS,EA8ByB,cA7BlC,AAAO,AAAC,AAAQ,AAPT,EAAK,AAAS,KAOO,KAAO,KACjC,EAAK,EAAK,WA4BV,AQq/BW,KAAkB,EAAgB,IAAiB,ARr/BtC,EAAwB,MAFzB,WA8DvB,AAAqB,KAGvB,EAAQ,KACR,EAAU,KAzCL,AAAQ,MAAG,EAAI,QAClB,KAAS,IADwB,WAGnC,EAAW,KACX,EAAS,KACT,EAAU,KACV,EAAW,KAfX,AAAU,AAiBE,KAjBO,SACnB,AQsGY,AAAiB,ARtGV,KQsGP,ARtGF,SQsGiC,KRrG3C,OQ09BE,AAAiB,KAAkB,EAAgB,WRz9BrD,EAAS,AAAC,KAAS,GAAK,SARxB,EAAW,AQi+BT,AAAiB,KAAkB,ARn+BpB,AADJ,OACc,IQm+B0B,ORj+BzC,AAAC,EAAU,GAAK,cHkN5B,AAAI,OAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,0BAiKlB,AAAI,EAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,qQAiKlB,AAAI,EAAM,MAAa,AAjKvB,AAiKiC,AAAkB,EAAM,KAjK9C,AAFA,KAEO,WGwChB,AAAU,IACV,OACA,AAAU,SAGJ,EAnEH,AAAQ,MAAG,EAAI,KAClB,AAAQ,AAAS,AAAM,EAAN,sBQgFjB,AAAU,AAAiB,KAAjB,SAA+B,YAq3BzC,AAAiB,KAAkB,EAAgB,gCAAnD,AAAiB,KAAkB,WAAgB,oBRj8BnD,aACA,aACA,AAAK,KAAW,QAAc,AAAC,KAAW,gBAAkB,KAAW,SACrE,EAAgB,QAChB,EAAiB,QACjB,EAA0B,QAvBzB,AAAQ,MAAG,EAAI,QAClB,KAAS,IADwB,WAGnC,EAAW,KACX,EAAS,KACT,EAAU,KACV,EAAW,KAfX,AAAU,AAiBE,KAjBO,SACnB,AQsGY,AAAiB,ARtGV,KQsGP,ARtGF,SQsGiC,KRrG3C,OQ09BE,AAAiB,KAAkB,EAAgB,WRz9BrD,EAAS,AAAC,KAAS,GAAK,SARxB,EAAW,AQi+BT,AAAiB,KAAkB,ARn+BpB,AADJ,OACc,IQm+B0B,ORj+BzC,AAAC,EAAU,GAAK,OAwCjB,EAAI,MAbU,WAiBlB,KAkDa,KAGhB,EAAO,KACP,AAAO,EAAP,KACQ,SAER,AQugBS,KAAkB,EAAgB,IRvgBf,kCHvChC,AAAI,AAHK,AADE,OACK,SAGN,KACR,AAAgB,EAAuB,KCsbzC,EAAe,AADC,KACW,MAC3B,AAAY,EAAM,KD1ahB,AACE,EAAW,AAA2B,EAAK,GAA/B,EAAO,mDAvEnB,EAAM,MACV,AAEY,AAAkB,EAAM","sourceRoot":"./rabin.wasm","sourcesContent":["// Alignment guarantees\n\n// @ts-ignore: decorator\n@inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128\n// @ts-ignore: decorator\n@inline export const AL_SIZE: usize = 1 << <usize>AL_BITS;\n// @ts-ignore: decorator\n@inline export const AL_MASK: usize = AL_SIZE - 1;\n\n// Extra debugging\n\n// @ts-ignore: decorator\n@inline export const DEBUG = true;\n\n// ╒════════════════ Common block layout (32-bit) ═════════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │ MM info │ -16\n// ├───────────────────────────────────────────────────────────────┤\n// │ GC info │ -12\n// ├───────────────────────────────────────────────────────────────┤\n// │ runtime id │ -8\n// ├───────────────────────────────────────────────────────────────┤\n// │ runtime size │ -4\n// ╞═══════════════════════════════════════════════════════════════╡\n// │ ... │ ref\n@unmanaged export class BLOCK {\n /** Memory manager info. */\n mmInfo: usize; // WASM64 needs adaption\n /** Garbage collector info. */\n gcInfo: u32;\n /** Runtime class id. */\n rtId: u32;\n /** Runtime object size. */\n rtSize: u32;\n}\n\n// @ts-ignore: decorator\n@inline export const BLOCK_OVERHEAD: usize = (offsetof<BLOCK>() + AL_MASK) & ~AL_MASK;\n\n// @ts-ignore: decorator\n@inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;\n","// This file is shared with the compiler and must remain portable\n\n// ╒═══════════════════ Typeinfo interpretation ═══════════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ◄─ __rtti_base\n// │ count │\n// ╞═══════════════════════════════════════════════════════════════╡ ┐\n// │ Typeinfo#flags [id=0] │ id < count\n// ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤\n// │ Typeinfo#base [id=0] │\n// ├───────────────────────────────────────────────────────────────┤\n// │ ... │\n\n/** Runtime type information data structure. */\n@unmanaged\nexport class Typeinfo {\n /** Flags describing the shape of this class type. */\n flags: TypeinfoFlags;\n /** Base class id or `0` if none. */\n base: u32;\n}\n\n/** Runtime type information flags. */\nexport const enum TypeinfoFlags {\n /** No specific flags. */\n NONE = 0,\n /** Type is an `ArrayBufferView`. */\n ARRAYBUFFERVIEW = 1 << 0,\n /** Type is an `Array`. */\n ARRAY = 1 << 1,\n /** Type is a `Set`. */\n SET = 1 << 2,\n /** Type is a `Map`. */\n MAP = 1 << 3,\n /** Type is inherently acyclic. */\n ACYCLIC = 1 << 4,\n /** Value alignment of 1 byte. */\n VALUE_ALIGN_0 = 1 << 5,\n /** Value alignment of 2 bytes. */\n VALUE_ALIGN_1 = 1 << 6,\n /** Value alignment of 4 bytes. */\n VALUE_ALIGN_2 = 1 << 7,\n /** Value alignment of 8 bytes. */\n VALUE_ALIGN_3 = 1 << 8,\n /** Value alignment of 16 bytes. */\n VALUE_ALIGN_4 = 1 << 9,\n /** Value is a signed type. */\n VALUE_SIGNED = 1 << 10,\n /** Value is a float type. */\n VALUE_FLOAT = 1 << 11,\n /** Value type is nullable. */\n VALUE_NULLABLE = 1 << 12,\n /** Value type is managed. */\n VALUE_MANAGED = 1 << 13,\n /** Key alignment of 1 byte. */\n KEY_ALIGN_0 = 1 << 14,\n /** Key alignment of 2 bytes. */\n KEY_ALIGN_1 = 1 << 15,\n /** Key alignment of 4 bytes. */\n KEY_ALIGN_2 = 1 << 16,\n /** Key alignment of 8 bytes. */\n KEY_ALIGN_3 = 1 << 17,\n /** Key alignment of 16 bytes. */\n KEY_ALIGN_4 = 1 << 18,\n /** Key is a signed type. */\n KEY_SIGNED = 1 << 19,\n /** Key is a float type. */\n KEY_FLOAT = 1 << 20,\n /** Key type is nullable. */\n KEY_NULLABLE = 1 << 21,\n /** Key type is managed. */\n KEY_MANAGED = 1 << 22\n}\n","import { DEBUG, BLOCK_OVERHEAD } from \"rt/common\";\nimport { Block, freeBlock, ROOT } from \"rt/tlsf\";\nimport { TypeinfoFlags } from \"shared/typeinfo\";\nimport { onincrement, ondecrement, onfree, onalloc } from \"./rtrace\";\n\n/////////////////////////// A Pure Reference Counting Garbage Collector ///////////////////////////\n// see: https://researcher.watson.ibm.com/researcher/files/us-bacon/Bacon03Pure.pdf\n\n// ╒══════════════════════ GC Info structure ══════════════════════╕\n// │ 3 2 1 │\n// │1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0│\n// ├─┼─┴─┴─┼─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │B│color│ refCount │\n// └─┴─────┴───────────────────────────────────────────────────────┘\n// B: buffered\n\n// @ts-ignore: decorator\n@inline const BUFFERED_MASK: u32 = 1 << ((sizeof<u32>() * 8) - 1);\n// @ts-ignore: decorator\n@inline const COLOR_BITS = 3;\n// @ts-ignore: decorator\n@inline const COLOR_SHIFT: u32 = ctz(BUFFERED_MASK) - COLOR_BITS;\n// @ts-ignore: decorator\n@inline const COLOR_MASK: u32 = ((1 << COLOR_BITS) - 1) << COLOR_SHIFT;\n// @ts-ignore: decorator\n@inline export const REFCOUNT_MASK: u32 = (1 << COLOR_SHIFT) - 1;\n\n// ╒════════╤═══════════════════ Colors ═══════════════════════════╕\n// │ Color │ Meaning │\n// ├────────┼──────────────────────────────────────────────────────┤\n// │ BLACK │ In use or free │\n// │ GRAY │ Possible member of cycle │\n// │ WHITE │ Member of garbage cycle │\n// │ PURPLE │ Possible root of cycle │\n// │ RED │ Candidate cycle undergoing Σ-computation *concurrent │\n// │ ORANGE │ Candidate cycle awaiting epoch boundary *concurrent │\n// └────────┴──────────────────────────────────────────────────────┘\n// Acyclic detection has been decoupled, hence no GREEN.\n\n// @ts-ignore: decorator\n@inline const COLOR_BLACK: u32 = 0 << COLOR_SHIFT;\n// @ts-ignore: decorator\n@inline const COLOR_GRAY: u32 = 1 << COLOR_SHIFT;\n// @ts-ignore: decorator\n@inline const COLOR_WHITE: u32 = 2 << COLOR_SHIFT;\n// @ts-ignore: decorator\n@inline const COLOR_PURPLE: u32 = 3 << COLOR_SHIFT;\n// @ts-ignore: decorator\n// @inline const COLOR_RED: u32 = 4 << COLOR_SHIFT;\n// @ts-ignore: decorator\n// @inline const COLOR_ORANGE: u32 = 5 << COLOR_SHIFT;\n\n// @ts-ignore: decorator\n@inline const VISIT_DECREMENT = 1; // guard 0\n// @ts-ignore: decorator\n@inline const VISIT_MARKGRAY = 2;\n// @ts-ignore: decorator\n@inline const VISIT_SCAN = 3;\n// @ts-ignore: decorator\n@inline const VISIT_SCANBLACK = 4;\n// @ts-ignore: decorator\n@inline const VISIT_COLLECTWHITE = 5;\n\n// @ts-ignore: decorator\n@global @unsafe @lazy\nfunction __visit(ref: usize, cookie: i32): void {\n if (ref < __heap_base) return;\n if (isDefined(__GC_ALL_ACYCLIC)) {\n if (DEBUG) assert(cookie == VISIT_DECREMENT);\n decrement(changetype<Block>(ref - BLOCK_OVERHEAD));\n } else {\n let s = changetype<Block>(ref - BLOCK_OVERHEAD);\n switch (cookie) {\n case VISIT_DECREMENT: {\n decrement(s);\n break;\n }\n case VISIT_MARKGRAY: {\n if (DEBUG) assert((s.gcInfo & REFCOUNT_MASK) > 0);\n s.gcInfo = s.gcInfo - 1;\n markGray(s);\n break;\n }\n case VISIT_SCAN: {\n scan(s);\n break;\n }\n case VISIT_SCANBLACK: {\n let info = s.gcInfo;\n assert((info & ~REFCOUNT_MASK) == ((info + 1) & ~REFCOUNT_MASK)); // overflow\n s.gcInfo = info + 1;\n if ((info & COLOR_MASK) != COLOR_BLACK) {\n scanBlack(s);\n }\n break;\n }\n case VISIT_COLLECTWHITE: {\n collectWhite(s);\n break;\n }\n default: if (DEBUG) assert(false);\n }\n }\n}\n\n/** Increments the reference count of the specified block by one.*/\nfunction increment(s: Block): void {\n var info = s.gcInfo;\n assert((info & ~REFCOUNT_MASK) == ((info + 1) & ~REFCOUNT_MASK)); // overflow\n s.gcInfo = info + 1;\n if (isDefined(ASC_RTRACE)) onincrement(s);\n if (DEBUG) assert(!(s.mmInfo & 1)); // used\n}\n\n/** Decrements the reference count of the specified block by one, possibly freeing it. */\n// @ts-ignore: decorator\n@lazy\nfunction decrement(s: Block): void {\n var info = s.gcInfo;\n var rc = info & REFCOUNT_MASK;\n if (isDefined(ASC_RTRACE)) ondecrement(s);\n if (DEBUG) assert(!(s.mmInfo & 1)); // used\n if (rc == 1) {\n __visit_members(changetype<usize>(s) + BLOCK_OVERHEAD, VISIT_DECREMENT);\n if (isDefined(__GC_ALL_ACYCLIC)) {\n if (DEBUG) assert(!(info & BUFFERED_MASK));\n freeBlock(ROOT, s);\n } else {\n if (!(info & BUFFERED_MASK)) {\n freeBlock(ROOT, s);\n } else {\n s.gcInfo = BUFFERED_MASK | COLOR_BLACK | 0;\n }\n }\n } else {\n if (DEBUG) assert(rc > 0);\n if (isDefined(__GC_ALL_ACYCLIC)) {\n s.gcInfo = (info & ~REFCOUNT_MASK) | (rc - 1);\n } else {\n if (!(__typeinfo(s.rtId) & TypeinfoFlags.ACYCLIC)) {\n s.gcInfo = BUFFERED_MASK | COLOR_PURPLE | (rc - 1);\n if (!(info & BUFFERED_MASK)) {\n appendRoot(s);\n }\n } else {\n s.gcInfo = (info & ~REFCOUNT_MASK) | (rc - 1);\n }\n }\n }\n}\n\n/** Buffer of possible roots. */\n// @ts-ignore: decorator\n@lazy var ROOTS: usize;\n/** Current absolute offset into the `ROOTS` buffer. */\n// @ts-ignore: decorator\n@lazy var CUR: usize = 0;\n/** Current absolute end offset into the `ROOTS` buffer. */\n// @ts-ignore: decorator\n@lazy var END: usize = 0;\n\n/** Appends a block to possible roots. */\nfunction appendRoot(s: Block): void {\n var cur = CUR;\n if (cur >= END) {\n growRoots(); // TBD: either that or pick a default and force collection on overflow\n cur = CUR;\n }\n store<Block>(cur, s);\n CUR = cur + sizeof<usize>();\n}\n\n/** Grows the roots buffer if it ran full. */\nfunction growRoots(): void {\n var oldRoots = ROOTS;\n var oldSize = CUR - oldRoots;\n var newSize = max(oldSize * 2, 64 << alignof<usize>());\n var newRoots = __alloc(newSize, 0);\n if (isDefined(ASC_RTRACE)) onfree(changetype<Block>(newRoots - BLOCK_OVERHEAD)); // neglect unmanaged\n memory.copy(newRoots, oldRoots, oldSize);\n if (oldRoots) {\n if (isDefined(ASC_RTRACE)) onalloc(changetype<Block>(oldRoots - BLOCK_OVERHEAD)); // neglect unmanaged\n __free(oldRoots);\n }\n ROOTS = newRoots;\n CUR = newRoots + oldSize;\n END = newRoots + newSize;\n}\n\n/** Collects cyclic garbage. */\n// @ts-ignore: decorator\n@global @unsafe @lazy\nexport function __collect(): void {\n if (isDefined(__GC_ALL_ACYCLIC)) return;\n\n // markRoots\n var roots = ROOTS;\n var cur = roots;\n for (let pos = cur, end = CUR; pos < end; pos += sizeof<usize>()) {\n let s = load<Block>(pos);\n let info = s.gcInfo;\n if ((info & COLOR_MASK) == COLOR_PURPLE && (info & REFCOUNT_MASK) > 0) {\n markGray(s);\n store<Block>(cur, s);\n cur += sizeof<usize>();\n } else {\n if ((info & COLOR_MASK) == COLOR_BLACK && !(info & REFCOUNT_MASK)) {\n freeBlock(ROOT, s);\n } else {\n s.gcInfo = info & ~BUFFERED_MASK;\n }\n }\n }\n CUR = cur;\n\n // scanRoots\n for (let pos = roots; pos < cur; pos += sizeof<usize>()) {\n scan(load<Block>(pos));\n }\n\n // collectRoots\n for (let pos = roots; pos < cur; pos += sizeof<usize>()) {\n let s = load<Block>(pos);\n s.gcInfo = s.gcInfo & ~BUFFERED_MASK;\n collectWhite(s);\n }\n CUR = roots;\n}\n\n/** Marks a block as gray (possible member of cycle) during the collection phase. */\nfunction markGray(s: Block): void {\n var info = s.gcInfo;\n if ((info & COLOR_MASK) != COLOR_GRAY) {\n s.gcInfo = (info & ~COLOR_MASK) | COLOR_GRAY;\n __visit_members(changetype<usize>(s) + BLOCK_OVERHEAD, VISIT_MARKGRAY);\n }\n}\n\n/** Scans a block during the collection phase, determining whether it is garbage or not. */\nfunction scan(s: Block): void {\n var info = s.gcInfo;\n if ((info & COLOR_MASK) == COLOR_GRAY) {\n if ((info & REFCOUNT_MASK) > 0) {\n scanBlack(s);\n } else {\n s.gcInfo = (info & ~COLOR_MASK) | COLOR_WHITE;\n __visit_members(changetype<usize>(s) + BLOCK_OVERHEAD, VISIT_SCAN);\n }\n }\n}\n\n/** Marks a block as black (in use) if it was found to be reachable during the collection phase. */\nfunction scanBlack(s: Block): void {\n s.gcInfo = (s.gcInfo & ~COLOR_MASK) | COLOR_BLACK;\n __visit_members(changetype<usize>(s) + BLOCK_OVERHEAD, VISIT_SCANBLACK);\n}\n\n/** Collects all white (member of a garbage cycle) nodes when completing the collection phase. */\nfunction collectWhite(s: Block): void {\n var info = s.gcInfo;\n if ((info & COLOR_MASK) == COLOR_WHITE && !(info & BUFFERED_MASK)) {\n s.gcInfo = (info & ~COLOR_MASK) | COLOR_BLACK;\n __visit_members(changetype<usize>(s) + BLOCK_OVERHEAD, VISIT_COLLECTWHITE);\n freeBlock(ROOT, s);\n }\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __retain(ptr: usize): usize {\n if (ptr > __heap_base) increment(changetype<Block>(ptr - BLOCK_OVERHEAD));\n return ptr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __release(ptr: usize): void {\n if (ptr > __heap_base) decrement(changetype<Block>(ptr - BLOCK_OVERHEAD));\n}\n","import { AL_BITS, AL_MASK, DEBUG, BLOCK, BLOCK_OVERHEAD, BLOCK_MAXSIZE } from \"rt/common\";\nimport { onfree, onalloc, onrealloc } from \"./rtrace\";\nimport { REFCOUNT_MASK } from \"./pure\";\n\n/////////////////////// The TLSF (Two-Level Segregate Fit) memory allocator ///////////////////////\n// see: http://www.gii.upv.es/tlsf/\n\n// - `ffs(x)` is equivalent to `ctz(x)` with x != 0\n// - `fls(x)` is equivalent to `sizeof(x) * 8 - clz(x) - 1`\n\n// ╒══════════════ Block size interpretation (32-bit) ═════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┴─┴─┴─╫─┴─┴─┴─┤\n// │ | FL │ SB = SL + AL │ ◄─ usize\n// └───────────────────────────────────────────────┴───────╨───────┘\n// FL: first level, SL: second level, AL: alignment, SB: small block\n\n// @ts-ignore: decorator\n@inline const SL_BITS: u32 = 4;\n// @ts-ignore: decorator\n@inline const SL_SIZE: u32 = 1 << SL_BITS;\n\n// @ts-ignore: decorator\n@inline const SB_BITS: u32 = SL_BITS + AL_BITS;\n// @ts-ignore: decorator\n@inline const SB_SIZE: u32 = 1 << SB_BITS;\n\n// @ts-ignore: decorator\n@inline const FL_BITS: u32 = 31 - SB_BITS;\n\n// [00]: < 256B (SB) [12]: < 1M\n// [01]: < 512B [13]: < 2M\n// [02]: < 1K [14]: < 4M\n// [03]: < 2K [15]: < 8M\n// [04]: < 4K [16]: < 16M\n// [05]: < 8K [17]: < 32M\n// [06]: < 16K [18]: < 64M\n// [07]: < 32K [19]: < 128M\n// [08]: < 64K [20]: < 256M\n// [09]: < 128K [21]: < 512M\n// [10]: < 256K [22]: <= 1G - OVERHEAD\n// [11]: < 512K\n// VMs limit to 2GB total (currently), making one 1G block max (or three 512M etc.) due to block overhead\n\n// Tags stored in otherwise unused alignment bits\n\n// @ts-ignore: decorator\n@inline const FREE: usize = 1 << 0;\n// @ts-ignore: decorator\n@inline const LEFTFREE: usize = 1 << 1;\n// @ts-ignore: decorator\n@inline const TAGS_MASK: usize = FREE | LEFTFREE; // <= AL_MASK\n\n// ╒════════════════════ Block layout (32-bit) ════════════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┼─┼─┤ overhead ┐\n// │ size │0│L│F│ ◄─┐ info\n// ├─────────────────────────────────────────────────────────┴─┴─┴─┤ │\n// │ │ │\n// │ ... additional runtime overhead ... │ │\n// │ │ │\n// ╞═══════════════════════════════════════════════════════════════╡ │ ┐ ┘\n// │ if free: ◄ prev │ ◄─┤ usize\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: next ► │ ◄─┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ │ = 0\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: back ▲ │ ◄─┘\n// └───────────────────────────────────────────────────────────────┘ payload ┘ >= MIN SIZE\n// F: FREE, L: LEFTFREE\n@unmanaged export class Block extends BLOCK {\n\n /** Previous free block, if any. Only valid if free, otherwise part of payload. */\n prev: Block | null;\n /** Next free block, if any. Only valid if free, otherwise part of payload. */\n next: Block | null;\n\n // If the block is free, there is a 'back'reference at its end pointing at its start.\n}\n\n// Block constants. A block must have a minimum size of three pointers so it can hold `prev`,\n// `next` and `back` if free.\n\n// @ts-ignore: decorator\n@inline const BLOCK_MINSIZE: usize = (3 * sizeof<usize>() + AL_MASK) & ~AL_MASK; // prev + next + back\n// @ts-ignore: decorator\n// @inline const BLOCK_MAXSIZE: usize = 1 << (FL_BITS + SB_BITS - 1); // exclusive, lives in common.ts\n\n/** Gets the left block of a block. Only valid if the left block is free. */\n// @ts-ignore: decorator\n@inline function GETFREELEFT(block: Block): Block {\n return load<Block>(changetype<usize>(block) - sizeof<usize>());\n}\n\n/** Gets the right block of of a block by advancing to the right by its size. */\n// @ts-ignore: decorator\n@inline function GETRIGHT(block: Block): Block {\n return changetype<Block>(changetype<usize>(block) + BLOCK_OVERHEAD + (block.mmInfo & ~TAGS_MASK));\n}\n\n// ╒═════════════════════ Root layout (32-bit) ════════════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ┐\n// │ 0 | flMap S│ ◄────┐\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ slMap[0] S │ ◄─┐ │\n// ├───────────────────────────────────────────────────────────────┤ │ │\n// │ slMap[1] │ ◄─┤ │\n// ├───────────────────────────────────────────────────────────────┤ u32 │\n// │ slMap[22] │ ◄─┘ │\n// ╞═══════════════════════════════════════════════════════════════╡ usize\n// │ head[0] │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ head[367] │ ◄────┤\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ tail │ ◄────┘\n// └───────────────────────────────────────────────────────────────┘ SIZE ┘\n// S: Small blocks map\n@unmanaged class Root {\n /** First level bitmap. */\n flMap: usize;\n}\n\n// Root constants. Where stuff is stored inside of the root structure.\n\n// @ts-ignore: decorator\n@inline const SL_START: usize = sizeof<usize>();\n// @ts-ignore: decorator\n@inline const SL_END: usize = SL_START + (FL_BITS << alignof<u32>());\n// @ts-ignore: decorator\n@inline const HL_START: usize = (SL_END + AL_MASK) & ~AL_MASK;\n// @ts-ignore: decorator\n@inline const HL_END: usize = HL_START + FL_BITS * SL_SIZE * sizeof<usize>();\n// @ts-ignore: decorator\n@inline const ROOT_SIZE: usize = HL_END + sizeof<usize>();\n\n// @ts-ignore: decorator\n@lazy export var ROOT: Root;\n\n/** Gets the second level map of the specified first level. */\n// @ts-ignore: decorator\n@inline function GETSL(root: Root, fl: usize): u32 {\n return load<u32>(\n changetype<usize>(root) + (fl << alignof<u32>()),\n SL_START\n );\n}\n\n/** Sets the second level map of the specified first level. */\n// @ts-ignore: decorator\n@inline function SETSL(root: Root, fl: usize, slMap: u32): void {\n store<u32>(\n changetype<usize>(root) + (fl << alignof<u32>()),\n slMap,\n SL_START\n );\n}\n\n/** Gets the head of the free list for the specified combination of first and second level. */\n// @ts-ignore: decorator\n@inline function GETHEAD(root: Root, fl: usize, sl: u32): Block | null {\n return load<Block>(\n changetype<usize>(root) + (((fl << SL_BITS) + <usize>sl) << alignof<usize>()),\n HL_START\n );\n}\n\n/** Sets the head of the free list for the specified combination of first and second level. */\n// @ts-ignore: decorator\n@inline function SETHEAD(root: Root, fl: usize, sl: u32, head: Block | null): void {\n store<Block>(\n changetype<usize>(root) + (((fl << SL_BITS) + <usize>sl) << alignof<usize>()),\n head,\n HL_START\n );\n}\n\n/** Gets the tail block.. */\n// @ts-ignore: decorator\n@inline function GETTAIL(root: Root): Block {\n return load<Block>(\n changetype<usize>(root),\n HL_END\n );\n}\n\n/** Sets the tail block. */\n// @ts-ignore: decorator\n@inline function SETTAIL(root: Root, tail: Block): void {\n store<Block>(\n changetype<usize>(root),\n tail,\n HL_END\n );\n}\n\n/** Inserts a previously used block back into the free list. */\nfunction insertBlock(root: Root, block: Block): void {\n if (DEBUG) assert(block); // cannot be null\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(blockInfo & FREE); // must be free\n\n var right = GETRIGHT(block);\n var rightInfo = right.mmInfo;\n\n // merge with right block if also free\n if (rightInfo & FREE) {\n let newSize = (blockInfo & ~TAGS_MASK) + BLOCK_OVERHEAD + (rightInfo & ~TAGS_MASK);\n if (newSize < BLOCK_MAXSIZE) {\n removeBlock(root, right);\n block.mmInfo = blockInfo = (blockInfo & TAGS_MASK) | newSize;\n right = GETRIGHT(block);\n rightInfo = right.mmInfo;\n // 'back' is set below\n }\n }\n\n // merge with left block if also free\n if (blockInfo & LEFTFREE) {\n let left = GETFREELEFT(block);\n let leftInfo = left.mmInfo;\n if (DEBUG) assert(leftInfo & FREE); // must be free according to right tags\n let newSize = (leftInfo & ~TAGS_MASK) + BLOCK_OVERHEAD + (blockInfo & ~TAGS_MASK);\n if (newSize < BLOCK_MAXSIZE) {\n removeBlock(root, left);\n left.mmInfo = blockInfo = (leftInfo & TAGS_MASK) | newSize;\n block = left;\n // 'back' is set below\n }\n }\n\n right.mmInfo = rightInfo | LEFTFREE;\n // right is no longer used now, hence rightInfo is not synced\n\n // we now know the size of the block\n var size = blockInfo & ~TAGS_MASK;\n if (DEBUG) assert(size >= BLOCK_MINSIZE && size < BLOCK_MAXSIZE); // must be a valid size\n if (DEBUG) assert(changetype<usize>(block) + BLOCK_OVERHEAD + size == changetype<usize>(right)); // must match\n\n // set 'back' to itself at the end of block\n store<Block>(changetype<usize>(right) - sizeof<usize>(), block);\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = <u32>(size >> AL_BITS);\n } else {\n const inv: usize = sizeof<usize>() * 8 - 1;\n fl = inv - clz<usize>(size);\n sl = <u32>((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\n\n // perform insertion\n var head = GETHEAD(root, fl, sl);\n block.prev = null;\n block.next = head;\n if (head) head.prev = block;\n SETHEAD(root, fl, sl, block);\n\n // update first and second level maps\n root.flMap |= (1 << fl);\n SETSL(root, fl, GETSL(root, fl) | (1 << sl));\n}\n\n/** Removes a free block from internal lists. */\nfunction removeBlock(root: Root, block: Block): void {\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(blockInfo & FREE); // must be free\n var size = blockInfo & ~TAGS_MASK;\n if (DEBUG) assert(size >= BLOCK_MINSIZE && size < BLOCK_MAXSIZE); // must be valid\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = <u32>(size >> AL_BITS);\n } else {\n const inv: usize = sizeof<usize>() * 8 - 1;\n fl = inv - clz<usize>(size);\n sl = <u32>((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\n\n // link previous and next free block\n var prev = block.prev;\n var next = block.next;\n if (prev) prev.next = next;\n if (next) next.prev = prev;\n\n // update head if we are removing it\n if (block == GETHEAD(root, fl, sl)) {\n SETHEAD(root, fl, sl, next);\n\n // clear second level map if head is empty now\n if (!next) {\n let slMap = GETSL(root, fl);\n SETSL(root, fl, slMap &= ~(1 << sl));\n\n // clear first level map if second level is empty now\n if (!slMap) root.flMap &= ~(1 << fl);\n }\n }\n // note: does not alter left/back because it is likely that splitting\n // is performed afterwards, invalidating those changes. so, the caller\n // must perform those updates.\n}\n\n/** Searches for a free block of at least the specified size. */\nfunction searchBlock(root: Root, size: usize): Block | null {\n // size was already asserted by caller\n\n // mapping_search\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = <u32>(size >> AL_BITS);\n } else {\n const halfMaxSize = BLOCK_MAXSIZE >> 1; // don't round last fl\n const inv: usize = sizeof<usize>() * 8 - 1;\n const invRound = inv - SL_BITS;\n let requestSize = size < halfMaxSize\n ? size + (1 << (invRound - clz<usize>(size))) - 1\n : size;\n fl = inv - clz<usize>(requestSize);\n sl = <u32>((requestSize >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\n\n // search second level\n var slMap = GETSL(root, fl) & (~0 << sl);\n var head: Block | null = null;\n if (!slMap) {\n // search next larger first level\n let flMap = root.flMap & (~0 << (fl + 1));\n if (!flMap) {\n head = null;\n } else {\n fl = ctz<usize>(flMap);\n slMap = GETSL(root, fl);\n if (DEBUG) assert(slMap); // can't be zero if fl points here\n head = GETHEAD(root, fl, ctz<u32>(slMap));\n }\n } else {\n head = GETHEAD(root, fl, ctz<u32>(slMap));\n }\n return head;\n}\n\n/** Prepares the specified block before (re-)use, possibly splitting it. */\nfunction prepareBlock(root: Root, block: Block, size: usize): void {\n // size was already asserted by caller\n\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(!(size & AL_MASK)); // size must be aligned so the new block is\n\n // split if the block can hold another MINSIZE block incl. overhead\n var remaining = (blockInfo & ~TAGS_MASK) - size;\n if (remaining >= BLOCK_OVERHEAD + BLOCK_MINSIZE) {\n block.mmInfo = size | (blockInfo & LEFTFREE); // also discards FREE\n\n let spare = changetype<Block>(changetype<usize>(block) + BLOCK_OVERHEAD + size);\n spare.mmInfo = (remaining - BLOCK_OVERHEAD) | FREE; // not LEFTFREE\n insertBlock(root, spare); // also sets 'back'\n\n // otherwise tag block as no longer FREE and right as no longer LEFTFREE\n } else {\n block.mmInfo = blockInfo & ~FREE;\n GETRIGHT(block).mmInfo &= ~LEFTFREE;\n }\n}\n\n/** Adds more memory to the pool. */\nfunction addMemory(root: Root, start: usize, end: usize): bool {\n if (DEBUG) {\n assert(\n start <= end && // must be valid\n !(start & AL_MASK) && // must be aligned\n !(end & AL_MASK) // must be aligned\n );\n }\n\n var tail = GETTAIL(root);\n var tailInfo: usize = 0;\n if (tail) { // more memory\n if (DEBUG) assert(start >= changetype<usize>(tail) + BLOCK_OVERHEAD);\n\n // merge with current tail if adjacent\n if (start - BLOCK_OVERHEAD == changetype<usize>(tail)) {\n start -= BLOCK_OVERHEAD;\n tailInfo = tail.mmInfo;\n } else {\n // We don't do this, but a user might `memory.grow` manually\n // leading to non-adjacent pages managed by TLSF.\n }\n\n } else if (DEBUG) { // first memory\n assert(start >= changetype<usize>(root) + ROOT_SIZE); // starts after root\n }\n\n // check if size is large enough for a free block and the tail block\n var size = end - start;\n if (size < BLOCK_OVERHEAD + BLOCK_MINSIZE + BLOCK_OVERHEAD) {\n return false;\n }\n\n // left size is total minus its own and the zero-length tail's header\n var leftSize = size - (BLOCK_OVERHEAD << 1);\n var left = changetype<Block>(start);\n left.mmInfo = leftSize | FREE | (tailInfo & LEFTFREE);\n left.prev = null;\n left.next = null;\n\n // tail is a zero-length used block\n tail = changetype<Block>(start + size - BLOCK_OVERHEAD);\n tail.mmInfo = 0 | LEFTFREE;\n SETTAIL(root, tail);\n\n insertBlock(root, left); // also merges with free left before tail / sets 'back'\n\n return true;\n}\n\n/** Grows memory to fit at least another block of the specified size. */\nfunction growMemory(root: Root, size: usize): void {\n // Here, both rounding performed in searchBlock ...\n const halfMaxSize = BLOCK_MAXSIZE >> 1;\n if (size < halfMaxSize) { // don't round last fl\n const invRound = (sizeof<usize>() * 8 - 1) - SL_BITS;\n size += (1 << (invRound - clz<usize>(size))) - 1;\n }\n // and additional BLOCK_OVERHEAD must be taken into account. If we are going\n // to merge with the tail block, that's one time, otherwise it's two times.\n var pagesBefore = memory.size();\n size += BLOCK_OVERHEAD << usize((<usize>pagesBefore << 16) - BLOCK_OVERHEAD != changetype<usize>(GETTAIL(root)));\n var pagesNeeded = <i32>(((size + 0xffff) & ~0xffff) >>> 16);\n var pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) unreachable();\n }\n var pagesAfter = memory.size();\n addMemory(root, <usize>pagesBefore << 16, <usize>pagesAfter << 16);\n}\n\n/** Prepares and checks an allocation size. */\nfunction prepareSize(size: usize): usize {\n if (size >= BLOCK_MAXSIZE) throw new Error(\"allocation too large\");\n return max<usize>((size + AL_MASK) & ~AL_MASK, BLOCK_MINSIZE); // align and ensure min size\n}\n\n/** Initilizes the root structure. */\nexport function maybeInitialize(): Root {\n var root = ROOT;\n if (!root) {\n const rootOffset = (__heap_base + AL_MASK) & ~AL_MASK;\n let pagesBefore = memory.size();\n let pagesNeeded = <i32>((((rootOffset + ROOT_SIZE) + 0xffff) & ~0xffff) >>> 16);\n if (pagesNeeded > pagesBefore && memory.grow(pagesNeeded - pagesBefore) < 0) unreachable();\n root = changetype<Root>(rootOffset);\n root.flMap = 0;\n SETTAIL(root, changetype<Block>(0));\n for (let fl: usize = 0; fl < FL_BITS; ++fl) {\n SETSL(root, fl, 0);\n for (let sl: u32 = 0; sl < SL_SIZE; ++sl) {\n SETHEAD(root, fl, sl, null);\n }\n }\n addMemory(root, (rootOffset + ROOT_SIZE + AL_MASK) & ~AL_MASK, memory.size() << 16);\n ROOT = root;\n }\n return root;\n}\n\n// @ts-ignore: decorator\n@lazy\nvar collectLock: bool = false;\n\n/** Allocates a block of the specified size. */\nexport function allocateBlock(root: Root, size: usize, id: u32): Block {\n if (DEBUG) assert(!collectLock); // must not allocate while collecting\n var payloadSize = prepareSize(size);\n var block = searchBlock(root, payloadSize);\n if (!block) {\n if (gc.auto) {\n if (DEBUG) collectLock = true;\n __collect();\n if (DEBUG) collectLock = false;\n block = searchBlock(root, payloadSize);\n if (!block) {\n growMemory(root, payloadSize);\n block = changetype<Block>(searchBlock(root, payloadSize));\n if (DEBUG) assert(block); // must be found now\n }\n } else {\n growMemory(root, payloadSize);\n block = changetype<Block>(searchBlock(root, payloadSize));\n if (DEBUG) assert(block); // must be found now\n }\n }\n if (DEBUG) assert((block.mmInfo & ~TAGS_MASK) >= payloadSize); // must fit\n block.gcInfo = 0; // RC=0\n block.rtId = id;\n block.rtSize = <u32>size;\n removeBlock(root, <Block>block);\n prepareBlock(root, <Block>block, payloadSize);\n if (isDefined(ASC_RTRACE)) onalloc(<Block>block);\n return <Block>block;\n}\n\n/** Reallocates a block to the specified size. */\nexport function reallocateBlock(root: Root, block: Block, size: usize): Block {\n var payloadSize = prepareSize(size);\n var blockInfo = block.mmInfo;\n\n // possibly split and update runtime size if it still fits\n if (payloadSize <= (blockInfo & ~TAGS_MASK)) {\n prepareBlock(root, block, payloadSize);\n block.rtSize = <u32>size;\n return block;\n }\n\n // merge with right free block if merger is large enough\n var right = GETRIGHT(block);\n var rightInfo = right.mmInfo;\n if (rightInfo & FREE) {\n let mergeSize = (blockInfo & ~TAGS_MASK) + BLOCK_OVERHEAD + (rightInfo & ~TAGS_MASK);\n if (mergeSize >= payloadSize) {\n removeBlock(root, right);\n // TODO: this can yield an intermediate block larger than BLOCK_MAXSIZE, which\n // is immediately split though. does this trigger any assertions / issues?\n block.mmInfo = (blockInfo & TAGS_MASK) | mergeSize;\n block.rtSize = <u32>size;\n prepareBlock(root, block, payloadSize);\n return block;\n }\n }\n\n // otherwise move the block\n var newBlock = allocateBlock(root, size, block.rtId); // may invalidate cached blockInfo\n newBlock.gcInfo = block.gcInfo; // keep RC\n memory.copy(changetype<usize>(newBlock) + BLOCK_OVERHEAD, changetype<usize>(block) + BLOCK_OVERHEAD, size);\n if (changetype<usize>(block) >= __heap_base) {\n if (isDefined(ASC_RTRACE)) onrealloc(block, newBlock);\n freeBlock(root, block);\n }\n return newBlock;\n}\n\n/** Frees a block. */\nexport function freeBlock(root: Root, block: Block): void {\n var blockInfo = block.mmInfo;\n block.mmInfo = blockInfo | FREE;\n insertBlock(root, block);\n if (isDefined(ASC_RTRACE)) onfree(block);\n}\n\n/** Checks that a used block is valid to be freed or reallocated. */\nfunction checkUsedBlock(ref: usize): Block {\n var block = changetype<Block>(ref - BLOCK_OVERHEAD);\n assert(\n ref != 0 && !(ref & AL_MASK) && // must exist and be aligned\n !(block.mmInfo & FREE) && // must be used\n !(block.gcInfo & ~REFCOUNT_MASK) // not buffered or != BLACK\n );\n return block;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __alloc(size: usize, id: u32): usize {\n return changetype<usize>(\n allocateBlock(maybeInitialize(), size, id)\n ) + BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __realloc(ref: usize, size: usize): usize {\n return changetype<usize>(\n reallocateBlock(maybeInitialize(), checkUsedBlock(ref), size)\n ) + BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __free(ref: usize): void {\n freeBlock(maybeInitialize(), checkUsedBlock(ref));\n}\n","/// <reference path=\"./rt/index.d.ts\" />\n\n/** Garbage collector interface. */\nexport namespace gc {\n\n /** Can be set to `false` to disable automatic collection. Defaults to `true`. */\n export var auto: bool = true;\n\n /** Performs a full garbage collection cycle. */\n export function collect(): void {\n __collect();\n }\n}\n","/// <reference path=\"../node_modules/@as-pect/assembly/types/as-pect.d.ts\" />\nexport const Int32Array_ID = idof<Int32Array>();\nexport const Uint8Array_ID = idof<Uint8Array>();\n\nconst POLYNOMIAL_DEGREE = 53;\nconst POLYNOMIAL_SHIFT = POLYNOMIAL_DEGREE - 8;\n\nlet tables_initialized = false;\n\nconst modTable = new Uint64Array(256);\nconst outTable = new Uint64Array(256);\n\n\n@inline\nexport function degree(polynom: u64): i32 {\n return 63 - <i32>clz(polynom);\n}\n\n@inline\nexport function mod(x: u64, p: u64): u64 {\n let shift: i32;\n let dp = degree(p);\n while ((shift = degree(x) - dp) >= 0) {\n x ^= p << shift;\n }\n return x;\n}\n\n@inline\nfunction append_byte(hash: u64, b: u8, pol: u64): u64 {\n hash <<= 8;\n hash |= <u64>b;\n\n return mod(hash, pol);\n}\n\n@inline\nfunction calc_tables(h: Rabin): void {\n for (let b = 0; b < 256; b++) {\n let hash: u64 = 0;\n\n hash = append_byte(hash, <u8>b, h.polynomial);\n for (let i = 0; i < h.window_size-1; i++) {\n hash = append_byte(hash, 0, h.polynomial);\n }\n unchecked(outTable[b] = hash);\n }\n\n let k = <u64>degree(h.polynomial);\n for (let b = 0; b < 256; b++) {\n const bk = (<u64>b) << k;\n unchecked(modTable[b] = mod(bk, h.polynomial) | bk);\n }\n}\n\n@inline\nfunction rabin_append(h: Rabin, b: u8): void {\n let digest = h.digest;\n let index = i32(digest >> POLYNOMIAL_SHIFT);\n\n h.digest = ((digest << 8) | <u64>b) ^ unchecked(modTable[index]);\n}\n\n@inline\nfunction rabin_slide(h: Rabin, b: u8): void {\n let out = h.window[h.wpos];\n unchecked(h.window[h.wpos] = b);\n h.digest ^= unchecked(outTable[out]);\n h.wpos = (h.wpos + 1) % h.window_size;\n rabin_append(h, b);\n}\n\n@inline\nfunction rabin_reset(h: Rabin): void {\n for (let i = 0; i < h.window_size; i++) {\n h.window[i] = 0;\n }\n h.digest = 0;\n h.wpos = 0;\n h.count = 0;\n h.digest = 0;\n\n rabin_slide(h, 1);\n}\n\n@inline\nfunction rabin_next_chunk(h: Rabin, buf: usize, len: i32): i32 {\n for (let i = 0; i < len; i++) {\n let b = load<u8>(buf + i);\n\n rabin_slide(h, b);\n\n h.count++;\n h.pos++;\n if ((h.count >= h.minsize && ((h.digest & h.mask) == 0)) || h.count >= h.maxsize) {\n h.chunk_start = h.start;\n h.chunk_length = h.count;\n h.chunk_cut_fingerprint = h.digest;\n\n rabin_reset(h);\n return i + 1;\n }\n }\n\n return -1;\n}\n\n@inline\nfunction rabin_init(h: Rabin): Rabin {\n if (!tables_initialized) {\n calc_tables(h);\n tables_initialized = true;\n }\n\n h.pos = 0;\n h.start = 0;\n rabin_reset(h);\n\n return h;\n}\n\nexport class Rabin {\n window: Uint8Array\n window_size: i32\n wpos: i32\n count: u64\n pos: u64\n start: u64\n digest: u64\n chunk_start: u64\n chunk_length: u64\n chunk_cut_fingerprint: u64\n polynomial: u64\n minsize: u64\n maxsize: u64\n mask: u64\n\n constructor(average_bits: u32, minsize: u32, maxsize: u32, window_size: i32) {\n this.minsize = <u64>minsize;\n this.maxsize = <u64>maxsize;\n this.window = new Uint8Array(window_size);\n this.window_size = window_size;\n this.mask = (1 << average_bits) - 1;\n this.polynomial = 0x3DA3358B4DC173;\n\n rabin_init(this);\n }\n\n fingerprint(buf: Uint8Array, lengths: Int32Array): Int32Array {\n let idx = 0;\n let len = buf.length;\n let ptr = buf.dataStart;\n while (true) {\n let remaining = rabin_next_chunk(this, ptr, len);\n if (remaining < 0) {\n break;\n }\n len -= remaining;\n ptr += remaining;\n let c = idx++;\n // lengths.push(<i32>this.chunk_length)\n unchecked(lengths[c] = <i32>this.chunk_length);\n }\n return lengths;\n }\n}\n","/// <reference path=\"./rt/index.d.ts\" />\n\nimport { BLOCK, BLOCK_MAXSIZE, BLOCK_OVERHEAD } from \"./rt/common\";\nimport { idof } from \"./builtins\";\nimport { E_INVALIDLENGTH } from \"./util/error\";\n\nexport abstract class ArrayBufferView {\n\n readonly buffer: ArrayBuffer;\n @unsafe readonly dataStart: usize;\n readonly byteLength: i32;\n\n get byteOffset(): i32 {\n return <i32>(this.dataStart - changetype<usize>(this.buffer));\n }\n\n get length(): i32 {\n ERROR(\"missing implementation: subclasses must implement ArrayBufferView#length\");\n return unreachable();\n }\n\n protected constructor(length: i32, alignLog2: i32) {\n if (<u32>length > <u32>BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);\n var buffer = __alloc(length = length << alignLog2, idof<ArrayBuffer>());\n memory.fill(buffer, 0, <usize>length);\n this.buffer = changetype<ArrayBuffer>(buffer); // retains\n this.dataStart = buffer;\n this.byteLength = length;\n }\n}\n\n@sealed export class ArrayBuffer {\n\n static isView<T>(value: T): bool {\n if (isNullable<T>()) {\n if (value === null) return false;\n }\n if (value instanceof Int8Array) return true;\n if (value instanceof Uint8Array) return true;\n if (value instanceof Uint8ClampedArray) return true;\n if (value instanceof Int16Array) return true;\n if (value instanceof Uint16Array) return true;\n if (value instanceof Int32Array) return true;\n if (value instanceof Uint32Array) return true;\n if (value instanceof Int64Array) return true;\n if (value instanceof Uint64Array) return true;\n if (value instanceof Float32Array) return true;\n if (value instanceof Float64Array) return true;\n if (value instanceof DataView) return true;\n return false;\n }\n\n constructor(length: i32) {\n if (<u32>length > <u32>BLOCK_MAXSIZE) throw new RangeError(E_INVALIDLENGTH);\n var buffer = __alloc(<usize>length, idof<ArrayBuffer>());\n memory.fill(buffer, 0, <usize>length);\n return changetype<ArrayBuffer>(buffer); // retains\n }\n\n get byteLength(): i32 {\n return changetype<BLOCK>(changetype<usize>(this) - BLOCK_OVERHEAD).rtSize;\n }\n\n slice(begin: i32 = 0, end: i32 = BLOCK_MAXSIZE): ArrayBuffer {\n var length = this.byteLength;\n begin = begin < 0 ? max(length + begin, 0) : min(begin, length);\n end = end < 0 ? max(length + end , 0) : min(end , length);\n var outSize = <usize>max(end - begin, 0);\n var out = __alloc(outSize, idof<ArrayBuffer>());\n memory.copy(out, changetype<usize>(this) + <usize>begin, outSize);\n return changetype<ArrayBuffer>(out); // retains\n }\n\n toString(): string {\n return \"[object ArrayBuffer]\";\n }\n}\n","// Common error messages for use accross the standard library. Keeping error messages compact\n// and reusing them where possible ensures minimal static data in binaries.\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INDEXOUTOFRANGE: string = \"Index out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDLENGTH: string = \"Invalid length\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_EMPTYARRAY: string = \"Array is empty\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_HOLEYARRAY: string = \"Element type must be nullable if array is holey\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOTIMPLEMENTED: string = \"Not implemented\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_KEYNOTFOUND: string = \"Key does not exist\";\n","import { memcmp, memmove, memset } from \"./util/memory\";\nimport { E_NOTIMPLEMENTED } from \"./util/error\";\n\n/** Memory manager interface. */\nexport namespace memory {\n\n /** Gets the size of the memory in pages. */\n // @ts-ignore: decorator\n @builtin\n export declare function size(): i32;\n\n /** Grows the memory by the given size in pages and returns the previous size in pages. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export declare function grow(pages: i32): i32;\n\n /** Fills a section in memory with the specified byte value. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export function fill(dst: usize, c: u8, n: usize): void {\n memset(dst, c, n); // fallback if \"bulk-memory\" isn't enabled\n }\n\n /** Copies a section of memory to another. Has move semantics. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export function copy(dst: usize, src: usize, n: usize): void {\n memmove(dst, src, n); // fallback if \"bulk-memory\" isn't enabled\n }\n\n /** Initializes a memory segment. */\n // @ts-ignore: decorator\n @unsafe\n export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void {\n throw new Error(E_NOTIMPLEMENTED);\n }\n\n /** Drops a memory segment. */\n // @ts-ignore: decorator\n @unsafe\n export function drop(segmentIndex: u32): void {\n throw new Error(E_NOTIMPLEMENTED);\n }\n\n /** Repeats a section of memory at a specific address. */\n // @ts-ignore: decorator\n @unsafe\n export function repeat(dst: usize, src: usize, srcLength: usize, count: usize): void {\n var index: usize = 0;\n var total = srcLength * count;\n while (index < total) {\n memory.copy(dst + index, src, srcLength);\n index += srcLength;\n }\n }\n\n /** Compares a section of memory to another. */\n // @ts-ignore: decorator\n @inline\n export function compare(vl: usize, vr: usize, n: usize): i32 {\n return memcmp(vl, vr, n);\n }\n}\n","export function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memcpy.c\n var w: u32, x: u32;\n\n // copy 1 byte each until src is aligned to 4 bytes\n while (n && (src & 3)) {\n store<u8>(dest++, load<u8>(src++));\n n--;\n }\n\n // if dst is aligned to 4 bytes as well, copy 4 bytes each\n if ((dest & 3) == 0) {\n while (n >= 16) {\n store<u32>(dest , load<u32>(src ));\n store<u32>(dest + 4, load<u32>(src + 4));\n store<u32>(dest + 8, load<u32>(src + 8));\n store<u32>(dest + 12, load<u32>(src + 12));\n src += 16; dest += 16; n -= 16;\n }\n if (n & 8) {\n store<u32>(dest , load<u32>(src ));\n store<u32>(dest + 4, load<u32>(src + 4));\n dest += 8; src += 8;\n }\n if (n & 4) {\n store<u32>(dest, load<u32>(src));\n dest += 4; src += 4;\n }\n if (n & 2) { // drop to 2 bytes each\n store<u16>(dest, load<u16>(src));\n dest += 2; src += 2;\n }\n if (n & 1) { // drop to 1 byte\n store<u8>(dest++, load<u8>(src++));\n }\n return;\n }\n\n // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each\n // doing shifts if faster when copying enough bytes (here: 32 or more)\n if (n >= 32) {\n switch (<u32>dest & 3) {\n // known to be != 0\n case 1: {\n w = load<u32>(src);\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n n -= 3;\n while (n >= 17) {\n x = load<u32>(src + 1);\n store<u32>(dest, w >> 24 | x << 8);\n w = load<u32>(src + 5);\n store<u32>(dest + 4, x >> 24 | w << 8);\n x = load<u32>(src + 9);\n store<u32>(dest + 8, w >> 24 | x << 8);\n w = load<u32>(src + 13);\n store<u32>(dest + 12, x >> 24 | w << 8);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 2: {\n w = load<u32>(src);\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n n -= 2;\n while (n >= 18) {\n x = load<u32>(src + 2);\n store<u32>(dest, w >> 16 | x << 16);\n w = load<u32>(src + 6);\n store<u32>(dest + 4, x >> 16 | w << 16);\n x = load<u32>(src + 10);\n store<u32>(dest + 8, w >> 16 | x << 16);\n w = load<u32>(src + 14);\n store<u32>(dest + 12, x >> 16 | w << 16);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 3: {\n w = load<u32>(src);\n store<u8>(dest++, load<u8>(src++));\n n -= 1;\n while (n >= 19) {\n x = load<u32>(src + 3);\n store<u32>(dest, w >> 8 | x << 24);\n w = load<u32>(src + 7);\n store<u32>(dest + 4, x >> 8 | w << 24);\n x = load<u32>(src + 11);\n store<u32>(dest + 8, w >> 8 | x << 24);\n w = load<u32>(src + 15);\n store<u32>(dest + 12, x >> 8 | w << 24);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n }\n }\n\n // copy remaining bytes one by one\n if (n & 16) {\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n }\n if (n & 8) {\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n }\n if (n & 4) {\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n }\n if (n & 2) {\n store<u8>(dest++, load<u8>(src++));\n store<u8>(dest++, load<u8>(src++));\n }\n if (n & 1) {\n store<u8>(dest++, load<u8>(src++));\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c\n if (dest === src) return;\n if (ASC_SHRINK_LEVEL < 1) {\n if (src + n <= dest || dest + n <= src) {\n memcpy(dest, src, n);\n return;\n }\n }\n if (dest < src) {\n if (ASC_SHRINK_LEVEL < 2) {\n if ((src & 7) == (dest & 7)) {\n while (dest & 7) {\n if (!n) return;\n --n;\n store<u8>(dest++, load<u8>(src++));\n }\n while (n >= 8) {\n store<u64>(dest, load<u64>(src));\n n -= 8;\n dest += 8;\n src += 8;\n }\n }\n }\n while (n) {\n store<u8>(dest++, load<u8>(src++));\n --n;\n }\n } else {\n if (ASC_SHRINK_LEVEL < 2) {\n if ((src & 7) == (dest & 7)) {\n while ((dest + n) & 7) {\n if (!n) return;\n store<u8>(dest + --n, load<u8>(src + n));\n }\n while (n >= 8) {\n n -= 8;\n store<u64>(dest + n, load<u64>(src + n));\n }\n }\n }\n while (n) {\n store<u8>(dest + --n, load<u8>(src + n));\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset\n if (ASC_SHRINK_LEVEL > 1) {\n while (n) {\n store<u8>(dest++, c);\n --n;\n }\n } else {\n // fill head and tail with minimal branching\n if (!n) return;\n store<u8>(dest, c);\n store<u8>(dest + n - 1, c);\n if (n <= 2) return;\n\n store<u8>(dest + 1, c);\n store<u8>(dest + 2, c);\n store<u8>(dest + n - 2, c);\n store<u8>(dest + n - 3, c);\n if (n <= 6) return;\n store<u8>(dest + 3, c);\n store<u8>(dest + n - 4, c);\n if (n <= 8) return;\n\n // advance pointer to align it at 4-byte boundary\n let k: usize = -dest & 3;\n dest += k;\n n -= k;\n n &= -4;\n\n let c32: u32 = <u32>-1 / 255 * c;\n\n // fill head/tail up to 28 bytes each in preparation\n store<u32>(dest, c32);\n store<u32>(dest + n - 4, c32);\n if (n <= 8) return;\n store<u32>(dest + 4, c32);\n store<u32>(dest + 8, c32);\n store<u32>(dest + n - 12, c32);\n store<u32>(dest + n - 8, c32);\n if (n <= 24) return;\n store<u32>(dest + 12, c32);\n store<u32>(dest + 16, c32);\n store<u32>(dest + 20, c32);\n store<u32>(dest + 24, c32);\n store<u32>(dest + n - 28, c32);\n store<u32>(dest + n - 24, c32);\n store<u32>(dest + n - 20, c32);\n store<u32>(dest + n - 16, c32);\n\n // align to a multiple of 8\n k = 24 + (dest & 4);\n dest += k;\n n -= k;\n\n // copy 32 bytes each\n let c64: u64 = <u64>c32 | (<u64>c32 << 32);\n while (n >= 32) {\n store<u64>(dest, c64);\n store<u64>(dest + 8, c64);\n store<u64>(dest + 16, c64);\n store<u64>(dest + 24, c64);\n n -= 32;\n dest += 32;\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memcmp(vl: usize, vr: usize, n: usize): i32 {\n if (vl == vr) return 0;\n if (ASC_SHRINK_LEVEL < 2) {\n if ((vl & 7) == (vr & 7)) {\n while (vl & 7) {\n if (!n) return 0;\n let a = <i32>load<u8>(vl);\n let b = <i32>load<u8>(vr);\n if (a != b) return a - b;\n n--; vl++; vr++;\n }\n while (n >= 8) {\n if (load<u64>(vl) != load<u64>(vr)) break;\n vl += 8;\n vr += 8;\n n -= 8;\n }\n }\n }\n while (n--) {\n let a = <i32>load<u8>(vl);\n let b = <i32>load<u8>(vr);\n if (a != b) return a - b;\n vl++; vr++;\n }\n return 0;\n}\n","/// <reference path=\"../rt/index.d.ts\" />\n\nimport { idof } from \"../builtins\";\nimport { CharCode } from \"./string\";\n\n// @ts-ignore: decorator\n@inline\nexport const MAX_DOUBLE_LENGTH = 28;\n\n// @ts-ignore: decorator\n@lazy @inline\nconst POWERS10: StaticArray<u32> = [\n 1,\n 10,\n 100,\n 1000,\n 10000,\n 100000,\n 1000000,\n 10000000,\n 100000000,\n 1000000000\n];\n\n/*\n Lookup table for pairwise char codes in range [0-99]\n\n \"00\", \"01\", \"02\", \"03\", \"04\", \"05\", \"06\", \"07\", \"08\", \"09\",\n \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\",\n \"20\", \"21\", \"22\", \"23\", \"24\", \"25\", \"26\", \"27\", \"28\", \"29\",\n \"30\", \"31\", \"32\", \"33\", \"34\", \"35\", \"36\", \"37\", \"38\", \"39\",\n \"40\", \"41\", \"42\", \"43\", \"44\", \"45\", \"46\", \"47\", \"48\", \"49\",\n \"50\", \"51\", \"52\", \"53\", \"54\", \"55\", \"56\", \"57\", \"58\", \"59\",\n \"60\", \"61\", \"62\", \"63\", \"64\", \"65\", \"66\", \"67\", \"68\", \"69\",\n \"70\", \"71\", \"72\", \"73\", \"74\", \"75\", \"76\", \"77\", \"78\", \"79\",\n \"80\", \"81\", \"82\", \"83\", \"84\", \"85\", \"86\", \"87\", \"88\", \"89\",\n \"90\", \"91\", \"92\", \"93\", \"94\", \"95\", \"96\", \"97\", \"98\", \"99\"\n*/\n// @ts-ignore: decorator\n@lazy @inline\nconst DIGITS: StaticArray<u32> = [\n 0x00300030, 0x00310030, 0x00320030, 0x00330030, 0x00340030,\n 0x00350030, 0x00360030, 0x00370030, 0x00380030, 0x00390030,\n 0x00300031, 0x00310031, 0x00320031, 0x00330031, 0x00340031,\n 0x00350031, 0x00360031, 0x00370031, 0x00380031, 0x00390031,\n 0x00300032, 0x00310032, 0x00320032, 0x00330032, 0x00340032,\n 0x00350032, 0x00360032, 0x00370032, 0x00380032, 0x00390032,\n 0x00300033, 0x00310033, 0x00320033, 0x00330033, 0x00340033,\n 0x00350033, 0x00360033, 0x00370033, 0x00380033, 0x00390033,\n 0x00300034, 0x00310034, 0x00320034, 0x00330034, 0x00340034,\n 0x00350034, 0x00360034, 0x00370034, 0x00380034, 0x00390034,\n 0x00300035, 0x00310035, 0x00320035, 0x00330035, 0x00340035,\n 0x00350035, 0x00360035, 0x00370035, 0x00380035, 0x00390035,\n 0x00300036, 0x00310036, 0x00320036, 0x00330036, 0x00340036,\n 0x00350036, 0x00360036, 0x00370036, 0x00380036, 0x00390036,\n 0x00300037, 0x00310037, 0x00320037, 0x00330037, 0x00340037,\n 0x00350037, 0x00360037, 0x00370037, 0x00380037, 0x00390037,\n 0x00300038, 0x00310038, 0x00320038, 0x00330038, 0x00340038,\n 0x00350038, 0x00360038, 0x00370038, 0x00380038, 0x00390038,\n 0x00300039, 0x00310039, 0x00320039, 0x00330039, 0x00340039,\n 0x00350039, 0x00360039, 0x00370039, 0x00380039, 0x00390039\n];\n\n// @ts-ignore: decorator\n@lazy @inline\nconst EXP_POWERS: StaticArray<i16> = [\n -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,\n -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,\n -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,\n -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,\n -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,\n 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,\n 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,\n 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,\n 907, 933, 960, 986, 1013, 1039, 1066\n];\n\n// 1e-348, 1e-340, ..., 1e340\n// @ts-ignore: decorator\n@lazy @inline\nconst FRC_POWERS: StaticArray<u64> = [\n 0xFA8FD5A0081C0288, 0xBAAEE17FA23EBF76, 0x8B16FB203055AC76, 0xCF42894A5DCE35EA,\n 0x9A6BB0AA55653B2D, 0xE61ACF033D1A45DF, 0xAB70FE17C79AC6CA, 0xFF77B1FCBEBCDC4F,\n 0xBE5691EF416BD60C, 0x8DD01FAD907FFC3C, 0xD3515C2831559A83, 0x9D71AC8FADA6C9B5,\n 0xEA9C227723EE8BCB, 0xAECC49914078536D, 0x823C12795DB6CE57, 0xC21094364DFB5637,\n 0x9096EA6F3848984F, 0xD77485CB25823AC7, 0xA086CFCD97BF97F4, 0xEF340A98172AACE5,\n 0xB23867FB2A35B28E, 0x84C8D4DFD2C63F3B, 0xC5DD44271AD3CDBA, 0x936B9FCEBB25C996,\n 0xDBAC6C247D62A584, 0xA3AB66580D5FDAF6, 0xF3E2F893DEC3F126, 0xB5B5ADA8AAFF80B8,\n 0x87625F056C7C4A8B, 0xC9BCFF6034C13053, 0x964E858C91BA2655, 0xDFF9772470297EBD,\n 0xA6DFBD9FB8E5B88F, 0xF8A95FCF88747D94, 0xB94470938FA89BCF, 0x8A08F0F8BF0F156B,\n 0xCDB02555653131B6, 0x993FE2C6D07B7FAC, 0xE45C10C42A2B3B06, 0xAA242499697392D3,\n 0xFD87B5F28300CA0E, 0xBCE5086492111AEB, 0x8CBCCC096F5088CC, 0xD1B71758E219652C,\n 0x9C40000000000000, 0xE8D4A51000000000, 0xAD78EBC5AC620000, 0x813F3978F8940984,\n 0xC097CE7BC90715B3, 0x8F7E32CE7BEA5C70, 0xD5D238A4ABE98068, 0x9F4F2726179A2245,\n 0xED63A231D4C4FB27, 0xB0DE65388CC8ADA8, 0x83C7088E1AAB65DB, 0xC45D1DF942711D9A,\n 0x924D692CA61BE758, 0xDA01EE641A708DEA, 0xA26DA3999AEF774A, 0xF209787BB47D6B85,\n 0xB454E4A179DD1877, 0x865B86925B9BC5C2, 0xC83553C5C8965D3D, 0x952AB45CFA97A0B3,\n 0xDE469FBD99A05FE3, 0xA59BC234DB398C25, 0xF6C69A72A3989F5C, 0xB7DCBF5354E9BECE,\n 0x88FCF317F22241E2, 0xCC20CE9BD35C78A5, 0x98165AF37B2153DF, 0xE2A0B5DC971F303A,\n 0xA8D9D1535CE3B396, 0xFB9B7CD9A4A7443C, 0xBB764C4CA7A44410, 0x8BAB8EEFB6409C1A,\n 0xD01FEF10A657842C, 0x9B10A4E5E9913129, 0xE7109BFBA19C0C9D, 0xAC2820D9623BF429,\n 0x80444B5E7AA7CF85, 0xBF21E44003ACDD2D, 0x8E679C2F5E44FF8F, 0xD433179D9C8CB841,\n 0x9E19DB92B4E31BA9, 0xEB96BF6EBADF77D9, 0xAF87023B9BF0EE6B\n];\n\n// Count number of decimals for u32 values\n// In our case input value always non-zero so we can simplify some parts\nexport function decimalCount32(value: u32): u32 {\n if (value < 100000) {\n if (value < 100) {\n return select<u32>(1, 2, value < 10);\n } else {\n let m = select<u32>(4, 5, value < 10000);\n return select<u32>(3, m, value < 1000);\n }\n } else {\n if (value < 10000000) {\n return select<u32>(6, 7, value < 1000000);\n } else {\n let m = select<u32>(9, 10, value < 1000000000);\n return select<u32>(8, m, value < 100000000);\n }\n }\n}\n\n// Count number of decimals for u64 values\n// In our case input value always greater than 2^32-1 so we can skip some parts\nexport function decimalCount64(value: u64): u32 {\n if (value < 1000000000000000) {\n if (value < 1000000000000) {\n let m = select<u32>(11, 12, value < 100000000000);\n return select<u32>(10, m, value < 10000000000);\n } else {\n let m = select<u32>(14, 15, value < 100000000000000);\n return select<u32>(13, m, value < 10000000000000);\n }\n } else {\n if (value < 100000000000000000) {\n return select<u32>(16, 17, value < 10000000000000000);\n } else {\n let m = select<u32>(19, 20, value < 10000000000000000000);\n return select<u32>(18, m, value < 1000000000000000000);\n }\n }\n}\n\nfunction utoa32_lut(buffer: usize, num: u32, offset: usize): void {\n while (num >= 10000) {\n // in most VMs i32/u32 div and modulo by constant can be shared and simplificate\n let t = num / 10000;\n let r = num % 10000;\n num = t;\n\n let d1 = r / 100;\n let d2 = r % 100;\n\n let digits1 = <u64>load<u32>(changetype<usize>(DIGITS) + (<usize>d1 << alignof<u32>()));\n let digits2 = <u64>load<u32>(changetype<usize>(DIGITS) + (<usize>d2 << alignof<u32>()));\n\n offset -= 4;\n store<u64>(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n if (num >= 100) {\n let t = num / 100;\n let d1 = num % 100;\n num = t;\n offset -= 2;\n let digits = load<u32>(changetype<usize>(DIGITS) + (<usize>d1 << alignof<u32>()));\n store<u32>(buffer + (offset << 1), digits);\n }\n\n if (num >= 10) {\n offset -= 2;\n let digits = load<u32>(changetype<usize>(DIGITS) + (<usize>num << alignof<u32>()));\n store<u32>(buffer + (offset << 1), digits);\n } else {\n offset -= 1;\n let digit = CharCode._0 + num;\n store<u16>(buffer + (offset << 1), digit);\n }\n}\n\nfunction utoa64_lut(buffer: usize, num: u64, offset: usize): void {\n while (num >= 100000000) {\n let t = num / 100000000;\n let r = <usize>(num - t * 100000000);\n num = t;\n\n let b = r / 10000;\n let c = r % 10000;\n\n let b1 = b / 100;\n let b2 = b % 100;\n let c1 = c / 100;\n let c2 = c % 100;\n\n let digits1 = <u64>load<u32>(changetype<usize>(DIGITS) + (<usize>c1 << alignof<u32>()));\n let digits2 = <u64>load<u32>(changetype<usize>(DIGITS) + (<usize>c2 << alignof<u32>()));\n\n offset -= 4;\n store<u64>(buffer + (offset << 1), digits1 | (digits2 << 32));\n\n digits1 = <u64>load<u32>(changetype<usize>(DIGITS) + (<usize>b1 << alignof<u32>()));\n digits2 = <u64>load<u32>(changetype<usize>(DIGITS) + (<usize>b2 << alignof<u32>()));\n\n offset -= 4;\n store<u64>(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n utoa32_lut(buffer, <u32>num, offset);\n}\n\nfunction utoa_simple<T extends number>(buffer: usize, num: T, offset: usize): void {\n do {\n let t = num / 10;\n let r = <u32>(num % 10);\n num = changetype<T>(t);\n offset -= 1;\n store<u16>(buffer + (offset << 1), CharCode._0 + r);\n } while (num);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function utoa32_core(buffer: usize, num: u32, offset: u32): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_simple(buffer, num, offset);\n } else {\n utoa32_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function utoa64_core(buffer: usize, num: u64, offset: u32): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_simple(buffer, num, offset);\n } else {\n utoa64_lut(buffer, num, offset);\n }\n}\n\nexport function utoa32(value: u32): String {\n if (!value) return \"0\";\n\n var decimals = decimalCount32(value);\n var out = __alloc(decimals << 1, idof<String>());\n\n utoa32_core(out, value, decimals);\n return changetype<String>(out); // retains\n}\n\nexport function itoa32(value: i32): String {\n if (!value) return \"0\";\n\n var sign = value < 0;\n if (sign) value = -value;\n\n var decimals = decimalCount32(value) + u32(sign);\n var out = __alloc(decimals << 1, idof<String>());\n\n utoa32_core(out, value, decimals);\n if (sign) store<u16>(out, CharCode.MINUS);\n return changetype<String>(out); // retains\n}\n\nexport function utoa64(value: u64): String {\n if (!value) return \"0\";\n\n var out: usize;\n if (value <= u32.MAX_VALUE) {\n let val32 = <u32>value;\n let decimals = decimalCount32(val32);\n out = __alloc(decimals << 1, idof<String>());\n utoa32_core(out, val32, decimals);\n } else {\n let decimals = decimalCount64(value);\n out = __alloc(decimals << 1, idof<String>());\n utoa64_core(out, value, decimals);\n }\n return changetype<String>(out); // retains\n}\n\nexport function itoa64(value: i64): String {\n if (!value) return \"0\";\n\n var sign = value < 0;\n if (sign) value = -value;\n\n var out: usize;\n if (<u64>value <= <u64>u32.MAX_VALUE) {\n let val32 = <u32>value;\n let decimals = decimalCount32(val32) + u32(sign);\n out = __alloc(decimals << 1, idof<String>());\n utoa32_core(out, val32, decimals);\n } else {\n let decimals = decimalCount64(value) + u32(sign);\n out = __alloc(decimals << 1, idof<String>());\n utoa64_core(out, value, decimals);\n }\n if (sign) store<u16>(out, CharCode.MINUS);\n\n return changetype<String>(out); // retains\n}\n\nexport function itoa<T extends number>(value: T): String {\n if (!isInteger<T>()) ERROR(\"integer type expected\");\n if (isSigned<T>()) {\n if (sizeof<T>() <= 4) {\n return itoa32(<i32>value);\n } else {\n return itoa64(<i64>value);\n }\n } else {\n if (sizeof<T>() <= 4) {\n return utoa32(<u32>value);\n } else {\n return utoa64(<u64>value);\n }\n }\n}\n\n// @ts-ignore: decorator\n@lazy\nvar _K: i32 = 0;\n\n// // @ts-ignore: decorator\n// @lazy\n// var _frc: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy\nvar _exp: i32 = 0;\n\n// @ts-ignore: decorator\n@lazy\nvar _frc_minus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy\nvar _frc_plus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy\nvar _frc_pow: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy\nvar _exp_pow: i32 = 0;\n\n// @ts-ignore: decorator\n@inline\nfunction umul64f(u: u64, v: u64): u64 {\n var u0 = u & 0xFFFFFFFF;\n var v0 = v & 0xFFFFFFFF;\n\n var u1 = u >> 32;\n var v1 = v >> 32;\n\n var l = u0 * v0;\n var t = u1 * v0 + (l >> 32);\n var w = u0 * v1 + (t & 0xFFFFFFFF);\n\n w += 0x7FFFFFFF; // rounding\n\n t >>= 32;\n w >>= 32;\n\n return u1 * v1 + t + w;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction umul64e(e1: i32, e2: i32): i32 {\n return e1 + e2 + 64; // where 64 is significand size\n}\n\n// @ts-ignore: decorator\n@inline\nfunction normalizedBoundaries(f: u64, e: i32): void {\n var frc = (f << 1) + 1;\n var exp = e - 1;\n var off = <i32>clz<u64>(frc);\n frc <<= off;\n exp -= off;\n\n var m = 1 + i32(f == 0x0010000000000000);\n\n _frc_plus = frc;\n _frc_minus = ((f << m) - 1) << e - m - exp;\n _exp = exp;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisuRound(buffer: usize, len: i32, delta: u64, rest: u64, ten_kappa: u64, wp_w: u64): void {\n var lastp = buffer + ((len - 1) << 1);\n var digit = load<u16>(lastp);\n while (\n rest < wp_w &&\n delta - rest >= ten_kappa && (\n rest + ten_kappa < wp_w ||\n wp_w - rest > rest + ten_kappa - wp_w\n )\n ) {\n --digit;\n rest += ten_kappa;\n }\n store<u16>(lastp, digit);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction getCachedPower(minExp: i32): void {\n const c = reinterpret<f64>(0x3FD34413509F79FE); // 1 / lg(10) = 0.30102999566398114\n var dk = (-61 - minExp) * c + 347;\t // dk must be positive, so can do ceiling in positive\n var k = <i32>dk;\n k += i32(k != dk); // conversion with ceil\n\n var index = (k >> 3) + 1;\n _K = 348 - (index << 3);\t// decimal exponent no need lookup table\n _frc_pow = load<u64>(changetype<usize>(FRC_POWERS) + (<usize>index << alignof<u64>()));\n _exp_pow = load<i16>(changetype<usize>(EXP_POWERS) + (<usize>index << alignof<i16>()));\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisu2(value: f64, buffer: usize, sign: i32): i32 {\n\n // frexp routine\n var uv = reinterpret<u64>(value);\n var exp = <i32>((uv & 0x7FF0000000000000) >>> 52);\n var sid = uv & 0x000FFFFFFFFFFFFF;\n var frc = (u64(exp != 0) << 52) + sid;\n exp = select<i32>(exp, 1, exp != 0) - (0x3FF + 52);\n\n normalizedBoundaries(frc, exp);\n getCachedPower(_exp);\n\n // normalize\n var off = <i32>clz<u64>(frc);\n frc <<= off;\n exp -= off;\n\n var frc_pow = _frc_pow;\n var exp_pow = _exp_pow;\n\n var w_frc = umul64f(frc, frc_pow);\n var w_exp = umul64e(exp, exp_pow);\n\n var wp_frc = umul64f(_frc_plus, frc_pow) - 1;\n var wp_exp = umul64e(_exp, exp_pow);\n\n var wm_frc = umul64f(_frc_minus, frc_pow) + 1;\n var delta = wp_frc - wm_frc;\n\n return genDigits(buffer, w_frc, w_exp, wp_frc, wp_exp, delta, sign);\n}\n\nfunction genDigits(buffer: usize, w_frc: u64, w_exp: i32, mp_frc: u64, mp_exp: i32, delta: u64, sign: i32): i32 {\n var one_exp = -mp_exp;\n var one_frc = (<u64>1) << one_exp;\n var mask = one_frc - 1;\n\n var wp_w_frc = mp_frc - w_frc;\n var wp_w_exp = mp_exp;\n\n var p1 = <u32>(mp_frc >> one_exp);\n var p2 = mp_frc & mask;\n\n var kappa = <i32>decimalCount32(p1);\n var len = sign;\n\n while (kappa > 0) {\n let d: u32;\n switch (kappa) {\n case 10: { d = p1 / 1000000000; p1 %= 1000000000; break; }\n case 9: { d = p1 / 100000000; p1 %= 100000000; break; }\n case 8: { d = p1 / 10000000; p1 %= 10000000; break; }\n case 7: { d = p1 / 1000000; p1 %= 1000000; break; }\n case 6: { d = p1 / 100000; p1 %= 100000; break; }\n case 5: { d = p1 / 10000; p1 %= 10000; break; }\n case 4: { d = p1 / 1000; p1 %= 1000; break; }\n case 3: { d = p1 / 100; p1 %= 100; break; }\n case 2: { d = p1 / 10; p1 %= 10; break; }\n case 1: { d = p1; p1 = 0; break; }\n default: { d = 0; break; }\n }\n\n if (d | len) store<u16>(buffer + (len++ << 1), CharCode._0 + <u16>d);\n\n --kappa;\n let tmp = ((<u64>p1) << one_exp) + p2;\n if (tmp <= delta) {\n _K += kappa;\n grisuRound(buffer, len, delta, tmp, <u64>load<u32>(changetype<usize>(POWERS10) + (<usize>kappa << alignof<u32>())) << one_exp, wp_w_frc);\n return len;\n }\n }\n\n while (true) {\n p2 *= 10;\n delta *= 10;\n\n let d = p2 >> one_exp;\n if (d | len) store<u16>(buffer + (len++ << 1), CharCode._0 + <u16>d);\n\n p2 &= mask;\n --kappa;\n if (p2 < delta) {\n _K += kappa;\n wp_w_frc *= <u64>load<u32>(changetype<usize>(POWERS10) + (<usize>-kappa << alignof<u32>()));\n grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc);\n return len;\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction genExponent(buffer: usize, k: i32): i32 {\n var sign = k < 0;\n if (sign) k = -k;\n var decimals = decimalCount32(k) + 1;\n utoa32_core(buffer, k, decimals);\n store<u16>(buffer, <u16>select<u32>(CharCode.MINUS, CharCode.PLUS, sign));\n return decimals;\n}\n\nfunction prettify(buffer: usize, length: i32, k: i32): i32 {\n if (!k) {\n store<u32>(buffer + (length << 1), CharCode.DOT | (CharCode._0 << 16));\n return length + 2;\n }\n\n var kk = length + k;\n if (length <= kk && kk <= 21) {\n // 1234e7 -> 12340000000\n for (let i = length; i < kk; ++i) {\n store<u16>(buffer + (i << 1), CharCode._0);\n }\n store<u32>(buffer + (kk << 1), CharCode.DOT | (CharCode._0 << 16));\n return kk + 2;\n } else if (kk > 0 && kk <= 21) {\n // 1234e-2 -> 12.34\n let ptr = buffer + (kk << 1);\n memory.copy(\n ptr + 2,\n ptr,\n -k << 1\n );\n store<u16>(buffer + (kk << 1), CharCode.DOT);\n return length + 1;\n } else if (-6 < kk && kk <= 0) {\n // 1234e-6 -> 0.001234\n let offset = 2 - kk;\n memory.copy(\n buffer + (offset << 1),\n buffer,\n length << 1\n );\n store<u32>(buffer, CharCode._0 | (CharCode.DOT << 16));\n for (let i = 2; i < offset; ++i) {\n store<u16>(buffer + (i << 1), CharCode._0);\n }\n return length + offset;\n } else if (length == 1) {\n // 1e30\n store<u16>(buffer, CharCode.e, 2);\n length = genExponent(buffer + 4, kk - 1);\n return length + 2;\n } else {\n let len = length << 1;\n memory.copy(\n buffer + 4,\n buffer + 2,\n len - 2\n );\n store<u16>(buffer, CharCode.DOT, 2);\n store<u16>(buffer + len, CharCode.e, 2);\n length += genExponent(buffer + len + 4, kk - 1);\n return length + 2;\n }\n}\n\nexport function dtoa_core(buffer: usize, value: f64): i32 {\n var sign = i32(value < 0);\n if (sign) {\n value = -value;\n store<u16>(buffer, CharCode.MINUS);\n }\n // assert(value > 0 && value <= 1.7976931348623157e308);\n var len = grisu2(value, buffer, sign);\n len = prettify(buffer + (sign << 1), len - sign, _K);\n return len + sign;\n}\n\nexport function dtoa(value: f64): String {\n if (value == 0) return \"0.0\";\n if (!isFinite<f64>(value)) {\n if (isNaN<f64>(value)) return \"NaN\";\n return select<String>(\"-Infinity\", \"Infinity\", value < 0);\n }\n var buffer = __alloc(MAX_DOUBLE_LENGTH << 1, idof<String>());\n var length = dtoa_core(buffer, value);\n if (length == MAX_DOUBLE_LENGTH) return changetype<String>(buffer);\n var result = changetype<String>(buffer).substring(0, length);\n __free(buffer);\n return result;\n}\n\nexport function itoa_stream<T extends number>(buffer: usize, offset: usize, value: T): u32 {\n buffer += (offset << 1);\n if (!value) {\n store<u16>(buffer, CharCode._0);\n return 1;\n }\n var decimals: u32 = 0;\n if (isSigned<T>()) {\n let sign = i32(value < 0);\n if (sign) value = changetype<T>(-value);\n if (sizeof<T>() <= 4) {\n decimals = decimalCount32(value) + <u32>sign;\n utoa32_core(buffer, value, decimals);\n } else {\n if (<u64>value <= <u64>u32.MAX_VALUE) {\n let val32 = <u32>value;\n decimals = decimalCount32(val32) + <u32>sign;\n utoa32_core(buffer, val32, decimals);\n } else {\n decimals = decimalCount64(value) + <u32>sign;\n utoa64_core(buffer, value, decimals);\n }\n }\n if (sign) store<u16>(buffer, CharCode.MINUS);\n } else {\n if (sizeof<T>() <= 4) {\n decimals = decimalCount32(value);\n utoa32_core(buffer, value, decimals);\n } else {\n if (<u64>value <= <u64>u32.MAX_VALUE) {\n let val32 = <u32>value;\n decimals = decimalCount32(val32);\n utoa32_core(buffer, val32, decimals);\n } else {\n decimals = decimalCount64(value);\n utoa64_core(buffer, value, decimals);\n }\n }\n }\n return decimals;\n}\n\nexport function dtoa_stream(buffer: usize, offset: usize, value: f64): u32 {\n buffer += (offset << 1);\n if (value == 0.0) {\n store<u16>(buffer, CharCode._0);\n store<u16>(buffer, CharCode.DOT, 2);\n store<u16>(buffer, CharCode._0, 4);\n return 3;\n }\n if (!isFinite<f64>(value)) {\n if (isNaN<f64>(value)) {\n store<u16>(buffer, CharCode.N);\n store<u16>(buffer, CharCode.a, 2);\n store<u16>(buffer, CharCode.N, 4);\n return 3;\n } else {\n let sign = i32(value < 0);\n let len = 8 + sign;\n memory.copy(buffer, changetype<usize>(select<String>(\"-Infinity\", \"Infinity\", sign)), len << 1);\n return len;\n }\n }\n return dtoa_core(buffer, value);\n}\n","//\n// Lookup data for exp2f\n//\n\n// @ts-ignore: decorator\n@inline\nconst EXP2F_TABLE_BITS = 5;\n\n// @ts-ignore: decorator\n@lazy @inline\nconst EXP2F_DATA_TAB: StaticArray<u64> = [\n // exp2f_data_tab[i] = uint(2^(i/N)) - (i << 52-BITS)\n // used for computing 2^(k/N) for an int |k| < 150 N as\n // double(tab[k%N] + (k << 52-BITS))\n 0x3FF0000000000000, 0x3FEFD9B0D3158574, 0x3FEFB5586CF9890F, 0x3FEF9301D0125B51,\n 0x3FEF72B83C7D517B, 0x3FEF54873168B9AA, 0x3FEF387A6E756238, 0x3FEF1E9DF51FDEE1,\n 0x3FEF06FE0A31B715, 0x3FEEF1A7373AA9CB, 0x3FEEDEA64C123422, 0x3FEECE086061892D,\n 0x3FEEBFDAD5362A27, 0x3FEEB42B569D4F82, 0x3FEEAB07DD485429, 0x3FEEA47EB03A5585,\n 0x3FEEA09E667F3BCD, 0x3FEE9F75E8EC5F74, 0x3FEEA11473EB0187, 0x3FEEA589994CCE13,\n 0x3FEEACE5422AA0DB, 0x3FEEB737B0CDC5E5, 0x3FEEC49182A3F090, 0x3FEED503B23E255D,\n 0x3FEEE89F995AD3AD, 0x3FEEFF76F2FB5E47, 0x3FEF199BDD85529C, 0x3FEF3720DCEF9069,\n 0x3FEF5818DCFBA487, 0x3FEF7C97337B9B5F, 0x3FEFA4AFA2A490DA, 0x3FEFD0765B6E4540\n];\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)\n// Wrong count: 168353 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function exp2f_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret<f64>(0x4338000000000000) / N, // 0x1.8p+52\n Ox127f = reinterpret<f32>(0x7F000000);\n\n const\n C0 = reinterpret<f64>(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret<f64>(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret<f64>(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n var xd = <f64>x;\n var ix = reinterpret<u32>(x);\n var ux = ix >> 20 & 0x7FF;\n if (ux >= 0x430) {\n // |x| >= 128 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > 0) return x * Ox127f; // x > 0 -> HugeVal (Owerflow)\n if (x <= -150) return 0; // x <= -150 -> 0 (Underflow)\n }\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)] and int k.\n var kd = xd + shift;\n var ki = reinterpret<u64>(kd);\n var r = xd - (kd - shift);\n var t: u64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load<u64>(changetype<usize>(EXP2F_DATA_TAB) + ((<usize>ki & N_MASK) << alignof<u64>()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret<f64>(t);\n y = C2 * r + 1;\n y += (C0 * r + C1) * (r * r);\n y *= s;\n\n return <f32>y;\n}\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)\n// Wrong count: 170635 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function expf_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret<f64>(0x4338000000000000), // 0x1.8p+52\n InvLn2N = reinterpret<f64>(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep+0\n Ox1p127f = reinterpret<f32>(0x7F000000);\n\n const\n C0 = reinterpret<f64>(0x3FAC6AF84B912394) / N / N / N, // 0x1.c6af84b912394p-5\n C1 = reinterpret<f64>(0x3FCEBFCE50FAC4F3) / N / N, // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret<f64>(0x3FE62E42FF0C52D6) / N; // 0x1.62e42ff0c52d6p-1\n\n var xd = <f64>x;\n var ix = reinterpret<u32>(x);\n var ux = ix >> 20 & 0x7FF;\n if (ux >= 0x42B) {\n // |x| >= 88 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > reinterpret<f32>(0x42B17217)) return x * Ox1p127f; // x > log(0x1p128) ~= 88.72 -> HugeVal (Owerflow)\n if (x < reinterpret<f32>(0xC2CFF1B4)) return 0; // x < log(0x1p-150) ~= -103.97 -> 0 (Underflow)\n }\n\n // x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k.\n var z = InvLn2N * xd;\n\n // Round and convert z to int, the result is in [-150*N, 128*N] and\n // ideally ties-to-even rule is used, otherwise the magnitude of r\n // can be bigger which gives larger approximation error.\n var kd = <f64>(z + shift);\n var ki = reinterpret<u64>(kd);\n var r = z - (kd - shift);\n var s: f64, y: f64, t: u64;\n\n // exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load<u64>(changetype<usize>(EXP2F_DATA_TAB) + ((<usize>ki & N_MASK) << alignof<u64>()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret<f64>(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n\n return <f32>y;\n}\n\n//\n// Lookup data for log2f\n//\n\n// @ts-ignore: decorator\n@inline\nconst LOG2F_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline\nconst LOG2F_DATA_TAB: StaticArray<f64> = [\n reinterpret<f64>(0x3FF661EC79F8F3BE), reinterpret<f64>(0xBFDEFEC65B963019), // 0x1.661ec79f8f3bep+0, -0x1.efec65b963019p-2,\n reinterpret<f64>(0x3FF571ED4AAF883D), reinterpret<f64>(0xBFDB0B6832D4FCA4), // 0x1.571ed4aaf883dp+0, -0x1.b0b6832d4fca4p-2,\n reinterpret<f64>(0x3FF49539F0F010B0), reinterpret<f64>(0xBFD7418B0A1FB77B), // 0x1.49539f0f010bp+0 , -0x1.7418b0a1fb77bp-2,\n reinterpret<f64>(0x3FF3C995B0B80385), reinterpret<f64>(0xBFD39DE91A6DCF7B), // 0x1.3c995b0b80385p+0, -0x1.39de91a6dcf7bp-2,\n reinterpret<f64>(0x3FF30D190C8864A5), reinterpret<f64>(0xBFD01D9BF3F2B631), // 0x1.30d190c8864a5p+0, -0x1.01d9bf3f2b631p-2,\n reinterpret<f64>(0x3FF25E227B0B8EA0), reinterpret<f64>(0xBFC97C1D1B3B7AF0), // 0x1.25e227b0b8eap+0 , -0x1.97c1d1b3b7afp-3 ,\n reinterpret<f64>(0x3FF1BB4A4A1A343F), reinterpret<f64>(0xBFC2F9E393AF3C9F), // 0x1.1bb4a4a1a343fp+0, -0x1.2f9e393af3c9fp-3,\n reinterpret<f64>(0x3FF12358F08AE5BA), reinterpret<f64>(0xBFB960CBBF788D5C), // 0x1.12358f08ae5bap+0, -0x1.960cbbf788d5cp-4,\n reinterpret<f64>(0x3FF0953F419900A7), reinterpret<f64>(0xBFAA6F9DB6475FCE), // 0x1.0953f419900a7p+0, -0x1.a6f9db6475fcep-5,\n reinterpret<f64>(0x3FF0000000000000), 0, // 0x1p+0, 0x0,\n reinterpret<f64>(0x3FEE608CFD9A47AC), reinterpret<f64>(0x3FB338CA9F24F53D), // 0x1.e608cfd9a47acp-1, 0x1.338ca9f24f53dp-4,\n reinterpret<f64>(0x3FECA4B31F026AA0), reinterpret<f64>(0x3FC476A9543891BA), // 0x1.ca4b31f026aap-1 , 0x1.476a9543891bap-3,\n reinterpret<f64>(0x3FEB2036576AFCE6), reinterpret<f64>(0x3FCE840B4AC4E4D2), // 0x1.b2036576afce6p-1, 0x1.e840b4ac4e4d2p-3,\n reinterpret<f64>(0x3FE9C2D163A1AA2D), reinterpret<f64>(0x3FD40645F0C6651C), // 0x1.9c2d163a1aa2dp-1, 0x1.40645f0c6651cp-2,\n reinterpret<f64>(0x3FE886E6037841ED), reinterpret<f64>(0x3FD88E9C2C1B9FF8), // 0x1.886e6037841edp-1, 0x1.88e9c2c1b9ff8p-2,\n reinterpret<f64>(0x3FE767DCF5534862), reinterpret<f64>(0x3FDCE0A44EB17BCC) // 0x1.767dcf5534862p-1, 0x1.ce0a44eb17bccp-2\n];\n\n// ULP error: 0.752 (nearest rounding.)\n// Relative error: 1.9 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function log2f_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOG2F_TABLE_BITS) - 1,\n Ox1p23f = reinterpret<f32>(0x4B000000); // 0x1p23f\n\n const\n A0 = reinterpret<f64>(0xBFD712B6F70A7E4D), // -0x1.712b6f70a7e4dp-2\n A1 = reinterpret<f64>(0x3FDECABF496832E0), // 0x1.ecabf496832ep-2\n A2 = reinterpret<f64>(0xBFE715479FFAE3DE), // -0x1.715479ffae3dep-1\n A3 = reinterpret<f64>(0x3FF715475F35C8B8); // 0x1.715475f35c8b8p0\n\n var ux = reinterpret<u32>(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && predict_false(ix == 0x3f800000)) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if (ux * 2 == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log2(inf) == inf.\n if ((ux >> 31) || ux * 2 >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret<u32>(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = (tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK;\n var top = tmp & 0xFF800000;\n var iz = ux - top;\n var k = <i32>tmp >> 23;\n\n var invc = load<f64>(changetype<usize>(LOG2F_DATA_TAB) + (i << (1 + alignof<f64>())), 0 << alignof<f64>());\n var logc = load<f64>(changetype<usize>(LOG2F_DATA_TAB) + (i << (1 + alignof<f64>())), 1 << alignof<f64>());\n var z = <f64>reinterpret<f32>(iz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n var r = z * invc - 1;\n var y0 = logc + <f64>k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n var y = A1 * r + A2;\n var p = A3 * r + y0;\n var r2 = r * r;\n y += A0 * r2;\n y = y * r2 + p;\n\n return <f32>y;\n}\n\n//\n// Lookup data for logf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/logf.c\n//\n\n// @ts-ignore: decorator\n@inline\nconst LOGF_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline\nconst LOGF_DATA_TAB: StaticArray<f64> = [\n reinterpret<f64>(0x3FF661EC79F8F3BE), reinterpret<f64>(0xBFD57BF7808CAADE), // 0x1.661ec79f8f3bep+0, -0x1.57bf7808caadep-2,\n reinterpret<f64>(0x3FF571ED4AAF883D), reinterpret<f64>(0xBFD2BEF0A7C06DDB), // 0x1.571ed4aaf883dp+0, -0x1.2bef0a7c06ddbp-2,\n reinterpret<f64>(0x3FF49539F0F010B0), reinterpret<f64>(0xBFD01EAE7F513A67), // 0x1.49539f0f010bp+0 , -0x1.01eae7f513a67p-2,\n reinterpret<f64>(0x3FF3C995B0B80385), reinterpret<f64>(0xBFCB31D8A68224E9), // 0x1.3c995b0b80385p+0, -0x1.b31d8a68224e9p-3,\n reinterpret<f64>(0x3FF30D190C8864A5), reinterpret<f64>(0xBFC6574F0AC07758), // 0x1.30d190c8864a5p+0, -0x1.6574f0ac07758p-3,\n reinterpret<f64>(0x3FF25E227B0B8EA0), reinterpret<f64>(0xBFC1AA2BC79C8100), // 0x1.25e227b0b8eap+0 , -0x1.1aa2bc79c81p-3 ,\n reinterpret<f64>(0x3FF1BB4A4A1A343F), reinterpret<f64>(0xBFBA4E76CE8C0E5E), // 0x1.1bb4a4a1a343fp+0, -0x1.a4e76ce8c0e5ep-4,\n reinterpret<f64>(0x3FF12358F08AE5BA), reinterpret<f64>(0xBFB1973C5A611CCC), // 0x1.12358f08ae5bap+0, -0x1.1973c5a611cccp-4,\n reinterpret<f64>(0x3FF0953F419900A7), reinterpret<f64>(0xBFA252F438E10C1E), // 0x1.0953f419900a7p+0, -0x1.252f438e10c1ep-5,\n reinterpret<f64>(0x3FF0000000000000), 0, // 0x1p+0, 0,\n reinterpret<f64>(0x3FEE608CFD9A47AC), reinterpret<f64>(0x3FAAA5AA5DF25984), // 0x1.e608cfd9a47acp-1, 0x1.aa5aa5df25984p-5,\n reinterpret<f64>(0x3FECA4B31F026AA0), reinterpret<f64>(0x3FBC5E53AA362EB4), // 0x1.ca4b31f026aap-1 , 0x1.c5e53aa362eb4p-4,\n reinterpret<f64>(0x3FEB2036576AFCE6), reinterpret<f64>(0x3FC526E57720DB08), // 0x1.b2036576afce6p-1, 0x1.526e57720db08p-3,\n reinterpret<f64>(0x3FE9C2D163A1AA2D), reinterpret<f64>(0x3FCBC2860D224770), // 0x1.9c2d163a1aa2dp-1, 0x1.bc2860d22477p-3 ,\n reinterpret<f64>(0x3FE886E6037841ED), reinterpret<f64>(0x3FD1058BC8A07EE1), // 0x1.886e6037841edp-1, 0x1.1058bc8a07ee1p-2,\n reinterpret<f64>(0x3FE767DCF5534862), reinterpret<f64>(0x3FD4043057B6EE09) // 0x1.767dcf5534862p-1, 0x1.4043057b6ee09p-2\n];\n\n// ULP error: 0.818 (nearest rounding.)\n// Relative error: 1.957 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function logf_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOGF_TABLE_BITS) - 1,\n Ox1p23f = reinterpret<f32>(0x4B000000); // 0x1p23f\n\n const\n Ln2 = reinterpret<f64>(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1;\n A0 = reinterpret<f64>(0xBFD00EA348B88334), // -0x1.00ea348b88334p-2\n A1 = reinterpret<f64>(0x3FD5575B0BE00B6A), // 0x1.5575b0be00b6ap-2\n A2 = reinterpret<f64>(0xBFDFFFFEF20A4123); // -0x1.ffffef20a4123p-2\n\n var ux = reinterpret<u32>(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && ux == 0x3f800000) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if ((ux << 1) == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log(inf) == inf.\n if ((ux >> 31) || (ux << 1) >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret<u32>(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = (tmp >> (23 - LOGF_TABLE_BITS)) & N_MASK;\n var k = <i32>tmp >> 23;\n var iz = ux - (tmp & 0x1FF << 23);\n\n var invc = load<f64>(changetype<usize>(LOGF_DATA_TAB) + (i << (1 + alignof<f64>())), 0 << alignof<f64>());\n var logc = load<f64>(changetype<usize>(LOGF_DATA_TAB) + (i << (1 + alignof<f64>())), 1 << alignof<f64>());\n\n var z = <f64>reinterpret<f32>(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2\n var r = z * invc - 1;\n var y0 = logc + <f64>k * Ln2;\n\n // Pipelined polynomial evaluation to approximate log1p(r).\n var r2 = r * r;\n var y = A1 * r + A2;\n y += A0 * r2;\n y = y * r2 + (y0 + r);\n\n return <f32>y;\n}\n\n//\n// Lookup data for powf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/powf.c\n//\n\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnanf(ux: u32): bool {\n return (ux << 1) - 1 >= (<u32>0x7f800000 << 1) - 1;\n}\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkintf(iy: u32): i32 {\n var e = iy >> 23 & 0xFF;\n if (e < 0x7F ) return 0;\n if (e > 0x7F + 23) return 2;\n e = 1 << (0x7F + 23 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// Subnormal input is normalized so ix has negative biased exponent.\n// Output is multiplied by N (POWF_SCALE) if TOINT_INTRINICS is set.\n// @ts-ignore: decorator\n@inline\nfunction log2f_inline(ux: u32): f64 {\n const N_MASK = (1 << LOG2F_TABLE_BITS) - 1;\n\n const\n A0 = reinterpret<f64>(0x3FD27616C9496E0B), // 0x1.27616c9496e0bp-2\n A1 = reinterpret<f64>(0xBFD71969A075C67A), // -0x1.71969a075c67ap-2\n A2 = reinterpret<f64>(0x3FDEC70A6CA7BADD), // 0x1.ec70a6ca7baddp-2\n A3 = reinterpret<f64>(0xBFE7154748BEF6C8), // -0x1.7154748bef6c8p-1\n A4 = reinterpret<f64>(0x3FF71547652AB82B); // 0x1.71547652ab82bp+0\n\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = <usize>((tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK);\n var top = tmp & 0xFF800000;\n var uz = ux - top;\n var k = <i32>(<i32>top >> 23);\n\n var invc = load<f64>(changetype<usize>(LOG2F_DATA_TAB) + (i << (1 + alignof<f64>())), 0 << alignof<f64>());\n var logc = load<f64>(changetype<usize>(LOG2F_DATA_TAB) + (i << (1 + alignof<f64>())), 1 << alignof<f64>());\n var z = <f64>reinterpret<f32>(uz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n var r = z * invc - 1;\n var y0 = logc + <f64>k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n var y = A0 * r + A1;\n var p = A2 * r + A3;\n var q = A4 * r + y0;\n\n r *= r;\n q += p * r;\n y = y * (r * r) + q;\n\n return y;\n}\n\n// The output of log2 and thus the input of exp2 is either scaled by N\n// (in case of fast toint intrinsics) or not. The unscaled xd must be\n// in [-1021,1023], sign_bias sets the sign of the result.\n// @ts-ignore: decorator\n@inline\nfunction exp2f_inline(xd: f64, signBias: u32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret<f64>(0x4338000000000000) / N; // 0x1.8p+52\n\n const\n C0 = reinterpret<f64>(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret<f64>(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret<f64>(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)]\n var kd = <f64>(xd + shift);\n var ki = reinterpret<u64>(kd);\n var r = xd - (kd - shift);\n var t: u64, z: f64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load<u64>(changetype<usize>(EXP2F_DATA_TAB) + ((<usize>ki & N_MASK) << alignof<u64>()));\n t += (ki + signBias) << (52 - EXP2F_TABLE_BITS);\n s = reinterpret<f64>(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n return <f32>y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflowf(sign: u32, y: f32): f32 {\n return select<f32>(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret<f32>(0x70000000)); // 0x1p97f\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret<f32>(0x10000000)); // 0x1p-95f\n}\n\n// @ts-ignore: decorator\n@inline\nexport function powf_lut(x: f32, y: f32): f32 {\n const\n Ox1p23f = reinterpret<f32>(0x4B000000), // 0x1p23f\n UPPER_LIMIT = reinterpret<f64>(0x405FFFFFFFD1D571), // 0x1.fffffffd1d571p+6\n LOWER_LIMIT = -150.0,\n SIGN_BIAS = 1 << (EXP2F_TABLE_BITS + 11);\n\n var signBias: u32 = 0;\n var ix = reinterpret<u32>(x);\n var iy = reinterpret<u32>(y);\n var ny = 0;\n\n if (i32(ix - 0x00800000 >= 0x7f800000 - 0x00800000) | (ny = i32(zeroinfnanf(iy)))) {\n // Either (x < 0x1p-126 or inf or nan) or (y is 0 or inf or nan).\n if (ny) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3F800000) return NaN; // original: 1.0\n if ((ix << 1) > (<u32>0x7F800000 << 1) || (iy << 1) > (<u32>0x7F800000 << 1)) return x + y;\n if ((ix << 1) == (0x3F800000 << 1)) return NaN; // original: 1.0\n if (((ix << 1) < (0x3F800000 << 1)) == !(iy >> 31)) return 0; // |x| < 1 && y==inf or |x| > 1 && y==-inf.\n return y * y;\n }\n if (zeroinfnanf(ix)) {\n let x2 = x * x;\n if ((ix >> 31) && checkintf(iy) == 1) x2 = -x2;\n return iy >> 31 ? 1 / x2 : x2;\n }\n // x and y are non-zero finite.\n if (ix >> 31) {\n // Finite x < 0.\n let yint = checkintf(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) signBias = SIGN_BIAS;\n ix &= 0x7FFFFFFF;\n }\n if (ix < 0x00800000) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret<u32>(x * Ox1p23f);\n ix &= 0x7FFFFFFF;\n ix -= 23 << 23;\n }\n }\n var logx = log2f_inline(ix);\n var ylogx = y * logx; // cannot overflow, y is single prec.\n if ((reinterpret<u64>(ylogx) >> 47 & 0xFFFF) >= 0x80BF) { // reinterpret<u64>(126.0) >> 47\n // |y * log(x)| >= 126\n if (ylogx > UPPER_LIMIT) return oflowf(signBias); // overflow\n if (ylogx <= LOWER_LIMIT) return uflowf(signBias); // underflow\n }\n return exp2f_inline(ylogx, signBias);\n}\n\n//\n// Lookup data for exp. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c\n//\n\n// @ts-ignore: decorator\n@inline\nconst EXP_TABLE_BITS = 7;\n\n// @ts-ignore: decorator\n@lazy @inline\nconst EXP_DATA_TAB: StaticArray<u64> = [\n 0x0000000000000000, 0x3FF0000000000000,\n 0x3C9B3B4F1A88BF6E, 0x3FEFF63DA9FB3335,\n 0xBC7160139CD8DC5D, 0x3FEFEC9A3E778061,\n 0xBC905E7A108766D1, 0x3FEFE315E86E7F85,\n 0x3C8CD2523567F613, 0x3FEFD9B0D3158574,\n 0xBC8BCE8023F98EFA, 0x3FEFD06B29DDF6DE,\n 0x3C60F74E61E6C861, 0x3FEFC74518759BC8,\n 0x3C90A3E45B33D399, 0x3FEFBE3ECAC6F383,\n 0x3C979AA65D837B6D, 0x3FEFB5586CF9890F,\n 0x3C8EB51A92FDEFFC, 0x3FEFAC922B7247F7,\n 0x3C3EBE3D702F9CD1, 0x3FEFA3EC32D3D1A2,\n 0xBC6A033489906E0B, 0x3FEF9B66AFFED31B,\n 0xBC9556522A2FBD0E, 0x3FEF9301D0125B51,\n 0xBC5080EF8C4EEA55, 0x3FEF8ABDC06C31CC,\n 0xBC91C923B9D5F416, 0x3FEF829AAEA92DE0,\n 0x3C80D3E3E95C55AF, 0x3FEF7A98C8A58E51,\n 0xBC801B15EAA59348, 0x3FEF72B83C7D517B,\n 0xBC8F1FF055DE323D, 0x3FEF6AF9388C8DEA,\n 0x3C8B898C3F1353BF, 0x3FEF635BEB6FCB75,\n 0xBC96D99C7611EB26, 0x3FEF5BE084045CD4,\n 0x3C9AECF73E3A2F60, 0x3FEF54873168B9AA,\n 0xBC8FE782CB86389D, 0x3FEF4D5022FCD91D,\n 0x3C8A6F4144A6C38D, 0x3FEF463B88628CD6,\n 0x3C807A05B0E4047D, 0x3FEF3F49917DDC96,\n 0x3C968EFDE3A8A894, 0x3FEF387A6E756238,\n 0x3C875E18F274487D, 0x3FEF31CE4FB2A63F,\n 0x3C80472B981FE7F2, 0x3FEF2B4565E27CDD,\n 0xBC96B87B3F71085E, 0x3FEF24DFE1F56381,\n 0x3C82F7E16D09AB31, 0x3FEF1E9DF51FDEE1,\n 0xBC3D219B1A6FBFFA, 0x3FEF187FD0DAD990,\n 0x3C8B3782720C0AB4, 0x3FEF1285A6E4030B,\n 0x3C6E149289CECB8F, 0x3FEF0CAFA93E2F56,\n 0x3C834D754DB0ABB6, 0x3FEF06FE0A31B715,\n 0x3C864201E2AC744C, 0x3FEF0170FC4CD831,\n 0x3C8FDD395DD3F84A, 0x3FEEFC08B26416FF,\n 0xBC86A3803B8E5B04, 0x3FEEF6C55F929FF1,\n 0xBC924AEDCC4B5068, 0x3FEEF1A7373AA9CB,\n 0xBC9907F81B512D8E, 0x3FEEECAE6D05D866,\n 0xBC71D1E83E9436D2, 0x3FEEE7DB34E59FF7,\n 0xBC991919B3CE1B15, 0x3FEEE32DC313A8E5,\n 0x3C859F48A72A4C6D, 0x3FEEDEA64C123422,\n 0xBC9312607A28698A, 0x3FEEDA4504AC801C,\n 0xBC58A78F4817895B, 0x3FEED60A21F72E2A,\n 0xBC7C2C9B67499A1B, 0x3FEED1F5D950A897,\n 0x3C4363ED60C2AC11, 0x3FEECE086061892D,\n 0x3C9666093B0664EF, 0x3FEECA41ED1D0057,\n 0x3C6ECCE1DAA10379, 0x3FEEC6A2B5C13CD0,\n 0x3C93FF8E3F0F1230, 0x3FEEC32AF0D7D3DE,\n 0x3C7690CEBB7AAFB0, 0x3FEEBFDAD5362A27,\n 0x3C931DBDEB54E077, 0x3FEEBCB299FDDD0D,\n 0xBC8F94340071A38E, 0x3FEEB9B2769D2CA7,\n 0xBC87DECCDC93A349, 0x3FEEB6DAA2CF6642,\n 0xBC78DEC6BD0F385F, 0x3FEEB42B569D4F82,\n 0xBC861246EC7B5CF6, 0x3FEEB1A4CA5D920F,\n 0x3C93350518FDD78E, 0x3FEEAF4736B527DA,\n 0x3C7B98B72F8A9B05, 0x3FEEAD12D497C7FD,\n 0x3C9063E1E21C5409, 0x3FEEAB07DD485429,\n 0x3C34C7855019C6EA, 0x3FEEA9268A5946B7,\n 0x3C9432E62B64C035, 0x3FEEA76F15AD2148,\n 0xBC8CE44A6199769F, 0x3FEEA5E1B976DC09,\n 0xBC8C33C53BEF4DA8, 0x3FEEA47EB03A5585,\n 0xBC845378892BE9AE, 0x3FEEA34634CCC320,\n 0xBC93CEDD78565858, 0x3FEEA23882552225,\n 0x3C5710AA807E1964, 0x3FEEA155D44CA973,\n 0xBC93B3EFBF5E2228, 0x3FEEA09E667F3BCD,\n 0xBC6A12AD8734B982, 0x3FEEA012750BDABF,\n 0xBC6367EFB86DA9EE, 0x3FEE9FB23C651A2F,\n 0xBC80DC3D54E08851, 0x3FEE9F7DF9519484,\n 0xBC781F647E5A3ECF, 0x3FEE9F75E8EC5F74,\n 0xBC86EE4AC08B7DB0, 0x3FEE9F9A48A58174,\n 0xBC8619321E55E68A, 0x3FEE9FEB564267C9,\n 0x3C909CCB5E09D4D3, 0x3FEEA0694FDE5D3F,\n 0xBC7B32DCB94DA51D, 0x3FEEA11473EB0187,\n 0x3C94ECFD5467C06B, 0x3FEEA1ED0130C132,\n 0x3C65EBE1ABD66C55, 0x3FEEA2F336CF4E62,\n 0xBC88A1C52FB3CF42, 0x3FEEA427543E1A12,\n 0xBC9369B6F13B3734, 0x3FEEA589994CCE13,\n 0xBC805E843A19FF1E, 0x3FEEA71A4623C7AD,\n 0xBC94D450D872576E, 0x3FEEA8D99B4492ED,\n 0x3C90AD675B0E8A00, 0x3FEEAAC7D98A6699,\n 0x3C8DB72FC1F0EAB4, 0x3FEEACE5422AA0DB,\n 0xBC65B6609CC5E7FF, 0x3FEEAF3216B5448C,\n 0x3C7BF68359F35F44, 0x3FEEB1AE99157736,\n 0xBC93091FA71E3D83, 0x3FEEB45B0B91FFC6,\n 0xBC5DA9B88B6C1E29, 0x3FEEB737B0CDC5E5,\n 0xBC6C23F97C90B959, 0x3FEEBA44CBC8520F,\n 0xBC92434322F4F9AA, 0x3FEEBD829FDE4E50,\n 0xBC85CA6CD7668E4B, 0x3FEEC0F170CA07BA,\n 0x3C71AFFC2B91CE27, 0x3FEEC49182A3F090,\n 0x3C6DD235E10A73BB, 0x3FEEC86319E32323,\n 0xBC87C50422622263, 0x3FEECC667B5DE565,\n 0x3C8B1C86E3E231D5, 0x3FEED09BEC4A2D33,\n 0xBC91BBD1D3BCBB15, 0x3FEED503B23E255D,\n 0x3C90CC319CEE31D2, 0x3FEED99E1330B358,\n 0x3C8469846E735AB3, 0x3FEEDE6B5579FDBF,\n 0xBC82DFCD978E9DB4, 0x3FEEE36BBFD3F37A,\n 0x3C8C1A7792CB3387, 0x3FEEE89F995AD3AD,\n 0xBC907B8F4AD1D9FA, 0x3FEEEE07298DB666,\n 0xBC55C3D956DCAEBA, 0x3FEEF3A2B84F15FB,\n 0xBC90A40E3DA6F640, 0x3FEEF9728DE5593A,\n 0xBC68D6F438AD9334, 0x3FEEFF76F2FB5E47,\n 0xBC91EEE26B588A35, 0x3FEF05B030A1064A,\n 0x3C74FFD70A5FDDCD, 0x3FEF0C1E904BC1D2,\n 0xBC91BDFBFA9298AC, 0x3FEF12C25BD71E09,\n 0x3C736EAE30AF0CB3, 0x3FEF199BDD85529C,\n 0x3C8EE3325C9FFD94, 0x3FEF20AB5FFFD07A,\n 0x3C84E08FD10959AC, 0x3FEF27F12E57D14B,\n 0x3C63CDAF384E1A67, 0x3FEF2F6D9406E7B5,\n 0x3C676B2C6C921968, 0x3FEF3720DCEF9069,\n 0xBC808A1883CCB5D2, 0x3FEF3F0B555DC3FA,\n 0xBC8FAD5D3FFFFA6F, 0x3FEF472D4A07897C,\n 0xBC900DAE3875A949, 0x3FEF4F87080D89F2,\n 0x3C74A385A63D07A7, 0x3FEF5818DCFBA487,\n 0xBC82919E2040220F, 0x3FEF60E316C98398,\n 0x3C8E5A50D5C192AC, 0x3FEF69E603DB3285,\n 0x3C843A59AC016B4B, 0x3FEF7321F301B460,\n 0xBC82D52107B43E1F, 0x3FEF7C97337B9B5F,\n 0xBC892AB93B470DC9, 0x3FEF864614F5A129,\n 0x3C74B604603A88D3, 0x3FEF902EE78B3FF6,\n 0x3C83C5EC519D7271, 0x3FEF9A51FBC74C83,\n 0xBC8FF7128FD391F0, 0x3FEFA4AFA2A490DA,\n 0xBC8DAE98E223747D, 0x3FEFAF482D8E67F1,\n 0x3C8EC3BC41AA2008, 0x3FEFBA1BEE615A27,\n 0x3C842B94C3A9EB32, 0x3FEFC52B376BBA97,\n 0x3C8A64A931D185EE, 0x3FEFD0765B6E4540,\n 0xBC8E37BAE43BE3ED, 0x3FEFDBFDAD9CBE14,\n 0x3C77893B4D91CD9D, 0x3FEFE7C1819E90D8,\n 0x3C5305C14160CC89, 0x3FEFF3C22B8F71F1\n];\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase(tmp: f64, sbits: u64, ki: u64): f64 {\n const\n Ox1p_1022 = reinterpret<f64>(0x0010000000000000), // 0x1p-1022\n Ox1p1009 = reinterpret<f64>(0x7F00000000000000); // 0x1p1009\n\n var scale: f64;\n if (!(ki & 0x80000000)) {\n // k > 0, the exponent of scale might have overflowed by <= 460.\n sbits -= u64(1009) << 52;\n scale = reinterpret<f64>(sbits);\n return Ox1p1009 * (scale + scale * tmp); // 0x1p1009\n }\n // k < 0, need special care in the subnormal range.\n sbits += u64(1022) << 52;\n // Note: sbits is signed scale.\n scale = reinterpret<f64>(sbits);\n var y = scale + scale * tmp;\n if (abs(y) < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let one = copysign(1.0, y);\n let lo = scale - y + scale * tmp;\n let hi = one + y;\n lo = one - hi + y + lo;\n y = (hi + lo) - one;\n // Fix the sign of 0.\n if (y == 0.0) y = reinterpret<f64>(sbits & 0x8000000000000000);\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret<f64>(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret<f64>(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret<f64>(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret<f64>(0x4338000000000000); // 0x1.8p52;\n\n const\n C2 = reinterpret<f64>(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret<f64>(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret<f64>(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret<f64>(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n var ux = reinterpret<u64>(x);\n var abstop = <u32>(ux >> 52 & 0x7FF);\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) return 1.0 + x;\n return select<f64>(0, Infinity, ux >> 63);\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]\n var z = InvLn2N * x;\n // #if TOINT_INTRINSICS\n // \tkd = roundtoint(z);\n // \tki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // \t// z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // var kd = z + shift;\n // var ki = reinterpret<u64>(kd) >> 16;\n // var kd = <f64><i32>ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes.\n var kd = z + shift;\n var ki = reinterpret<u64>(kd);\n kd -= shift;\n// #endif\n var r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // 2^(k/N) ~= scale * (1 + tail).\n var idx = <usize>((ki & N_MASK) << 1);\n var top = ki << (52 - EXP_TABLE_BITS);\n\n var tail = reinterpret<f64>(load<u64>(changetype<usize>(EXP_DATA_TAB) + (idx << alignof<u64>()))); // T[idx]\n // This is only a valid scale when -1023*N < k < 1024*N\n var sbits = load<u64>(changetype<usize>(EXP_DATA_TAB) + (idx << alignof<u64>()), 1 << alignof<u64>()) + top; // T[idx + 1]\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n var r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.\n var tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n var scale = reinterpret<f64>(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n//\n// Lookup data for exp2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp2.c\n//\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase2(tmp: f64, sbits: u64, ki: u64): f64 {\n const Ox1p_1022 = reinterpret<f64>(0x10000000000000); // 0x1p-1022\n var scale: f64;\n if ((ki & 0x80000000) == 0) {\n // k > 0, the exponent of scale might have overflowed by 1\n sbits -= u64(1) << 52;\n scale = reinterpret<f64>(sbits);\n return 2 * (scale * tmp + scale);\n }\n // k < 0, need special care in the subnormal range\n sbits += u64(1022) << 52;\n scale = reinterpret<f64>(sbits);\n var y = scale * tmp + scale;\n if (y < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let hi: f64, lo: f64;\n lo = scale - y + scale * tmp;\n hi = 1.0 + y;\n lo = 1.0 - hi + y + lo;\n y = (hi + lo) - 1.0;\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp2_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret<f64>(0x4338000000000000) / N; // 0x1.8p52\n\n const\n C1 = reinterpret<f64>(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1\n C2 = reinterpret<f64>(0x3FCEBFBDFF82C424), // 0x1.ebfbdff82c424p-3\n C3 = reinterpret<f64>(0x3FAC6B08D70CF4B5), // 0x1.c6b08d70cf4b5p-5\n C4 = reinterpret<f64>(0x3F83B2ABD24650CC), // 0x1.3b2abd24650ccp-7\n C5 = reinterpret<f64>(0x3F55D7E09B4E3A84); // 0x1.5d7e09b4e3a84p-10\n\n var ux = reinterpret<u64>(x);\n var abstop = <u32>(ux >> 52 & 0x7ff);\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1.0;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) return 1.0 + x;\n if (!(ux >> 63)) return Infinity;\n else if (ux >= 0xC090CC0000000000) return 0;\n }\n if ((ux << 1) > 0x811A000000000000) abstop = 0; // Large x is special cased below.\n }\n\n // exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)].\n // x = k/N + r, with int k and r in [-1/2N, 1/2N]\n var kd = x + shift;\n var ki = reinterpret<u64>(kd);\n kd -= shift; // k/N for int k\n var r = x - kd;\n // 2^(k/N) ~= scale * (1 + tail)\n var idx = <usize>((ki & N_MASK) << 1);\n var top = ki << (52 - EXP_TABLE_BITS);\n\n var tail = reinterpret<f64>(load<u64>(changetype<usize>(EXP_DATA_TAB) + (idx << alignof<u64>()), 0 << alignof<u64>())); // T[idx])\n // This is only a valid scale when -1023*N < k < 1024*N\n var sbits = load<u64>(changetype<usize>(EXP_DATA_TAB) + (idx << alignof<u64>()), 1 << alignof<u64>()) + top; // T[idx + 1]\n // exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1).\n // Evaluation is optimized assuming superscalar pipelined execution\n var r2 = r * r;\n // Without fma the worst case error is 0.5/N ulp larger.\n // Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp.\n var tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase2(tmp, sbits, ki);\n var scale = reinterpret<f64>(sbits);\n // Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there\n // is no spurious underflow here even without fma.\n return scale * tmp + scale;\n}\n\n//\n// Lookup data for log2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c\n//\n\n// @ts-ignore: decorator\n@inline\nconst LOG2_TABLE_BITS = 6;\n\n/* Algorithm:\n\n x = 2^k z\n log2(x) = k + log2(c) + log2(z/c)\n log2(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log2(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p10 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-64 and\n 3) the rounding error in (double)log2(c) is minimized (< 0x1p-68).\n\nNote: 1) ensures that k + logc can be computed without rounding error, 2)\nensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to a\nsingle rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log2(x)| < 0x1p-4, this is not enough so that is special cased. */\n\n// @ts-ignore: decorator\n@lazy @inline\nconst LOG2_DATA_TAB1: StaticArray<f64> = [\n // invc , logc\n reinterpret<f64>(0x3FF724286BB1ACF8), reinterpret<f64>(0xBFE1095FEECDB000),\n reinterpret<f64>(0x3FF6E1F766D2CCA1), reinterpret<f64>(0xBFE08494BD76D000),\n reinterpret<f64>(0x3FF6A13D0E30D48A), reinterpret<f64>(0xBFE00143AEE8F800),\n reinterpret<f64>(0x3FF661EC32D06C85), reinterpret<f64>(0xBFDEFEC5360B4000),\n reinterpret<f64>(0x3FF623FA951198F8), reinterpret<f64>(0xBFDDFDD91AB7E000),\n reinterpret<f64>(0x3FF5E75BA4CF026C), reinterpret<f64>(0xBFDCFFAE0CC79000),\n reinterpret<f64>(0x3FF5AC055A214FB8), reinterpret<f64>(0xBFDC043811FDA000),\n reinterpret<f64>(0x3FF571ED0F166E1E), reinterpret<f64>(0xBFDB0B67323AE000),\n reinterpret<f64>(0x3FF53909590BF835), reinterpret<f64>(0xBFDA152F5A2DB000),\n reinterpret<f64>(0x3FF5014FED61ADDD), reinterpret<f64>(0xBFD9217F5AF86000),\n reinterpret<f64>(0x3FF4CAB88E487BD0), reinterpret<f64>(0xBFD8304DB0719000),\n reinterpret<f64>(0x3FF49539B4334FEE), reinterpret<f64>(0xBFD74189F9A9E000),\n reinterpret<f64>(0x3FF460CBDFAFD569), reinterpret<f64>(0xBFD6552BB5199000),\n reinterpret<f64>(0x3FF42D664EE4B953), reinterpret<f64>(0xBFD56B23A29B1000),\n reinterpret<f64>(0x3FF3FB01111DD8A6), reinterpret<f64>(0xBFD483650F5FA000),\n reinterpret<f64>(0x3FF3C995B70C5836), reinterpret<f64>(0xBFD39DE937F6A000),\n reinterpret<f64>(0x3FF3991C4AB6FD4A), reinterpret<f64>(0xBFD2BAA1538D6000),\n reinterpret<f64>(0x3FF3698E0CE099B5), reinterpret<f64>(0xBFD1D98340CA4000),\n reinterpret<f64>(0x3FF33AE48213E7B2), reinterpret<f64>(0xBFD0FA853A40E000),\n reinterpret<f64>(0x3FF30D191985BDB1), reinterpret<f64>(0xBFD01D9C32E73000),\n reinterpret<f64>(0x3FF2E025CAB271D7), reinterpret<f64>(0xBFCE857DA2FA6000),\n reinterpret<f64>(0x3FF2B404CF13CD82), reinterpret<f64>(0xBFCCD3C8633D8000),\n reinterpret<f64>(0x3FF288B02C7CCB50), reinterpret<f64>(0xBFCB26034C14A000),\n reinterpret<f64>(0x3FF25E2263944DE5), reinterpret<f64>(0xBFC97C1C2F4FE000),\n reinterpret<f64>(0x3FF234563D8615B1), reinterpret<f64>(0xBFC7D6023F800000),\n reinterpret<f64>(0x3FF20B46E33EAF38), reinterpret<f64>(0xBFC633A71A05E000),\n reinterpret<f64>(0x3FF1E2EEFDCDA3DD), reinterpret<f64>(0xBFC494F5E9570000),\n reinterpret<f64>(0x3FF1BB4A580B3930), reinterpret<f64>(0xBFC2F9E424E0A000),\n reinterpret<f64>(0x3FF19453847F2200), reinterpret<f64>(0xBFC162595AFDC000),\n reinterpret<f64>(0x3FF16E06C0D5D73C), reinterpret<f64>(0xBFBF9C9A75BD8000),\n reinterpret<f64>(0x3FF1485F47B7E4C2), reinterpret<f64>(0xBFBC7B575BF9C000),\n reinterpret<f64>(0x3FF12358AD0085D1), reinterpret<f64>(0xBFB960C60FF48000),\n reinterpret<f64>(0x3FF0FEF00F532227), reinterpret<f64>(0xBFB64CE247B60000),\n reinterpret<f64>(0x3FF0DB2077D03A8F), reinterpret<f64>(0xBFB33F78B2014000),\n reinterpret<f64>(0x3FF0B7E6D65980D9), reinterpret<f64>(0xBFB0387D1A42C000),\n reinterpret<f64>(0x3FF0953EFE7B408D), reinterpret<f64>(0xBFAA6F9208B50000),\n reinterpret<f64>(0x3FF07325CAC53B83), reinterpret<f64>(0xBFA47A954F770000),\n reinterpret<f64>(0x3FF05197E40D1B5C), reinterpret<f64>(0xBF9D23A8C50C0000),\n reinterpret<f64>(0x3FF03091C1208EA2), reinterpret<f64>(0xBF916A2629780000),\n reinterpret<f64>(0x3FF0101025B37E21), reinterpret<f64>(0xBF7720F8D8E80000),\n reinterpret<f64>(0x3FEFC07EF9CAA76B), reinterpret<f64>(0x3F86FE53B1500000),\n reinterpret<f64>(0x3FEF4465D3F6F184), reinterpret<f64>(0x3FA11CCCE10F8000),\n reinterpret<f64>(0x3FEECC079F84107F), reinterpret<f64>(0x3FAC4DFC8C8B8000),\n reinterpret<f64>(0x3FEE573A99975AE8), reinterpret<f64>(0x3FB3AA321E574000),\n reinterpret<f64>(0x3FEDE5D6F0BD3DE6), reinterpret<f64>(0x3FB918A0D08B8000),\n reinterpret<f64>(0x3FED77B681FF38B3), reinterpret<f64>(0x3FBE72E9DA044000),\n reinterpret<f64>(0x3FED0CB5724DE943), reinterpret<f64>(0x3FC1DCD2507F6000),\n reinterpret<f64>(0x3FECA4B2DC0E7563), reinterpret<f64>(0x3FC476AB03DEA000),\n reinterpret<f64>(0x3FEC3F8EE8D6CB51), reinterpret<f64>(0x3FC7074377E22000),\n reinterpret<f64>(0x3FEBDD2B4F020C4C), reinterpret<f64>(0x3FC98EDE8BA94000),\n reinterpret<f64>(0x3FEB7D6C006015CA), reinterpret<f64>(0x3FCC0DB86AD2E000),\n reinterpret<f64>(0x3FEB20366E2E338F), reinterpret<f64>(0x3FCE840AAFCEE000),\n reinterpret<f64>(0x3FEAC57026295039), reinterpret<f64>(0x3FD0790AB4678000),\n reinterpret<f64>(0x3FEA6D01BC2731DD), reinterpret<f64>(0x3FD1AC056801C000),\n reinterpret<f64>(0x3FEA16D3BC3FF18B), reinterpret<f64>(0x3FD2DB11D4FEE000),\n reinterpret<f64>(0x3FE9C2D14967FEAD), reinterpret<f64>(0x3FD406464EC58000),\n reinterpret<f64>(0x3FE970E4F47C9902), reinterpret<f64>(0x3FD52DBE093AF000),\n reinterpret<f64>(0x3FE920FB3982BCF2), reinterpret<f64>(0x3FD651902050D000),\n reinterpret<f64>(0x3FE8D30187F759F1), reinterpret<f64>(0x3FD771D2CDEAF000),\n reinterpret<f64>(0x3FE886E5EBB9F66D), reinterpret<f64>(0x3FD88E9C857D9000),\n reinterpret<f64>(0x3FE83C97B658B994), reinterpret<f64>(0x3FD9A80155E16000),\n reinterpret<f64>(0x3FE7F405FFC61022), reinterpret<f64>(0x3FDABE186ED3D000),\n reinterpret<f64>(0x3FE7AD22181415CA), reinterpret<f64>(0x3FDBD0F2AEA0E000),\n reinterpret<f64>(0x3FE767DCF99EFF8C), reinterpret<f64>(0x3FDCE0A43DBF4000)\n];\n\n// @ts-ignore: decorator\n@lazy @inline\nconst LOG2_DATA_TAB2: StaticArray<f64> = [\n // chi , clo\n reinterpret<f64>(0x3FE6200012B90A8E), reinterpret<f64>(0x3C8904AB0644B605),\n reinterpret<f64>(0x3FE66000045734A6), reinterpret<f64>(0x3C61FF9BEA62F7A9),\n reinterpret<f64>(0x3FE69FFFC325F2C5), reinterpret<f64>(0x3C827ECFCB3C90BA),\n reinterpret<f64>(0x3FE6E00038B95A04), reinterpret<f64>(0x3C88FF8856739326),\n reinterpret<f64>(0x3FE71FFFE09994E3), reinterpret<f64>(0x3C8AFD40275F82B1),\n reinterpret<f64>(0x3FE7600015590E10), reinterpret<f64>(0xBC72FD75B4238341),\n reinterpret<f64>(0x3FE7A00012655BD5), reinterpret<f64>(0x3C7808E67C242B76),\n reinterpret<f64>(0x3FE7E0003259E9A6), reinterpret<f64>(0xBC6208E426F622B7),\n reinterpret<f64>(0x3FE81FFFEDB4B2D2), reinterpret<f64>(0xBC8402461EA5C92F),\n reinterpret<f64>(0x3FE860002DFAFCC3), reinterpret<f64>(0x3C6DF7F4A2F29A1F),\n reinterpret<f64>(0x3FE89FFFF78C6B50), reinterpret<f64>(0xBC8E0453094995FD),\n reinterpret<f64>(0x3FE8E00039671566), reinterpret<f64>(0xBC8A04F3BEC77B45),\n reinterpret<f64>(0x3FE91FFFE2BF1745), reinterpret<f64>(0xBC77FA34400E203C),\n reinterpret<f64>(0x3FE95FFFCC5C9FD1), reinterpret<f64>(0xBC76FF8005A0695D),\n reinterpret<f64>(0x3FE9A0003BBA4767), reinterpret<f64>(0x3C70F8C4C4EC7E03),\n reinterpret<f64>(0x3FE9DFFFE7B92DA5), reinterpret<f64>(0x3C8E7FD9478C4602),\n reinterpret<f64>(0x3FEA1FFFD72EFDAF), reinterpret<f64>(0xBC6A0C554DCDAE7E),\n reinterpret<f64>(0x3FEA5FFFDE04FF95), reinterpret<f64>(0x3C867DA98CE9B26B),\n reinterpret<f64>(0x3FEA9FFFCA5E8D2B), reinterpret<f64>(0xBC8284C9B54C13DE),\n reinterpret<f64>(0x3FEADFFFDDAD03EA), reinterpret<f64>(0x3C5812C8EA602E3C),\n reinterpret<f64>(0x3FEB1FFFF10D3D4D), reinterpret<f64>(0xBC8EFADDAD27789C),\n reinterpret<f64>(0x3FEB5FFFCE21165A), reinterpret<f64>(0x3C53CB1719C61237),\n reinterpret<f64>(0x3FEB9FFFD950E674), reinterpret<f64>(0x3C73F7D94194CE00),\n reinterpret<f64>(0x3FEBE000139CA8AF), reinterpret<f64>(0x3C750AC4215D9BC0),\n reinterpret<f64>(0x3FEC20005B46DF99), reinterpret<f64>(0x3C6BEEA653E9C1C9),\n reinterpret<f64>(0x3FEC600040B9F7AE), reinterpret<f64>(0xBC7C079F274A70D6),\n reinterpret<f64>(0x3FECA0006255FD8A), reinterpret<f64>(0xBC7A0B4076E84C1F),\n reinterpret<f64>(0x3FECDFFFD94C095D), reinterpret<f64>(0x3C88F933F99AB5D7),\n reinterpret<f64>(0x3FED1FFFF975D6CF), reinterpret<f64>(0xBC582C08665FE1BE),\n reinterpret<f64>(0x3FED5FFFA2561C93), reinterpret<f64>(0xBC7B04289BD295F3),\n reinterpret<f64>(0x3FED9FFF9D228B0C), reinterpret<f64>(0x3C870251340FA236),\n reinterpret<f64>(0x3FEDE00065BC7E16), reinterpret<f64>(0xBC75011E16A4D80C),\n reinterpret<f64>(0x3FEE200002F64791), reinterpret<f64>(0x3C89802F09EF62E0),\n reinterpret<f64>(0x3FEE600057D7A6D8), reinterpret<f64>(0xBC7E0B75580CF7FA),\n reinterpret<f64>(0x3FEEA00027EDC00C), reinterpret<f64>(0xBC8C848309459811),\n reinterpret<f64>(0x3FEEE0006CF5CB7C), reinterpret<f64>(0xBC8F8027951576F4),\n reinterpret<f64>(0x3FEF2000782B7DCC), reinterpret<f64>(0xBC8F81D97274538F),\n reinterpret<f64>(0x3FEF6000260C450A), reinterpret<f64>(0xBC4071002727FFDC),\n reinterpret<f64>(0x3FEF9FFFE88CD533), reinterpret<f64>(0xBC581BDCE1FDA8B0),\n reinterpret<f64>(0x3FEFDFFFD50F8689), reinterpret<f64>(0x3C87F91ACB918E6E),\n reinterpret<f64>(0x3FF0200004292367), reinterpret<f64>(0x3C9B7FF365324681),\n reinterpret<f64>(0x3FF05FFFE3E3D668), reinterpret<f64>(0x3C86FA08DDAE957B),\n reinterpret<f64>(0x3FF0A0000A85A757), reinterpret<f64>(0xBC57E2DE80D3FB91),\n reinterpret<f64>(0x3FF0E0001A5F3FCC), reinterpret<f64>(0xBC91823305C5F014),\n reinterpret<f64>(0x3FF11FFFF8AFBAF5), reinterpret<f64>(0xBC8BFABB6680BAC2),\n reinterpret<f64>(0x3FF15FFFE54D91AD), reinterpret<f64>(0xBC9D7F121737E7EF),\n reinterpret<f64>(0x3FF1A00011AC36E1), reinterpret<f64>(0x3C9C000A0516F5FF),\n reinterpret<f64>(0x3FF1E00019C84248), reinterpret<f64>(0xBC9082FBE4DA5DA0),\n reinterpret<f64>(0x3FF220000FFE5E6E), reinterpret<f64>(0xBC88FDD04C9CFB43),\n reinterpret<f64>(0x3FF26000269FD891), reinterpret<f64>(0x3C8CFE2A7994D182),\n reinterpret<f64>(0x3FF2A00029A6E6DA), reinterpret<f64>(0xBC700273715E8BC5),\n reinterpret<f64>(0x3FF2DFFFE0293E39), reinterpret<f64>(0x3C9B7C39DAB2A6F9),\n reinterpret<f64>(0x3FF31FFFF7DCF082), reinterpret<f64>(0x3C7DF1336EDC5254),\n reinterpret<f64>(0x3FF35FFFF05A8B60), reinterpret<f64>(0xBC9E03564CCD31EB),\n reinterpret<f64>(0x3FF3A0002E0EAECC), reinterpret<f64>(0x3C75F0E74BD3A477),\n reinterpret<f64>(0x3FF3E000043BB236), reinterpret<f64>(0x3C9C7DCB149D8833),\n reinterpret<f64>(0x3FF4200002D187FF), reinterpret<f64>(0x3C7E08AFCF2D3D28),\n reinterpret<f64>(0x3FF460000D387CB1), reinterpret<f64>(0x3C820837856599A6),\n reinterpret<f64>(0x3FF4A00004569F89), reinterpret<f64>(0xBC89FA5C904FBCD2),\n reinterpret<f64>(0x3FF4E000043543F3), reinterpret<f64>(0xBC781125ED175329),\n reinterpret<f64>(0x3FF51FFFCC027F0F), reinterpret<f64>(0x3C9883D8847754DC),\n reinterpret<f64>(0x3FF55FFFFD87B36F), reinterpret<f64>(0xBC8709E731D02807),\n reinterpret<f64>(0x3FF59FFFF21DF7BA), reinterpret<f64>(0x3C87F79F68727B02),\n reinterpret<f64>(0x3FF5DFFFEBFC3481), reinterpret<f64>(0xBC9180902E30E93E)\n];\n\n// @ts-ignore: decorator\n@inline\nexport function log2_lut(x: f64): f64 {\n const N_MASK = (1 << LOG2_TABLE_BITS) - 1;\n\n const\n LO: u64 = 0x3FEEA4AF00000000, // reinterpret<u64>(1.0 - 0x1.5b51p-5)\n HI: u64 = 0x3FF0B55900000000; // reinterpret<u64>(1.0 + 0x1.6ab2p-5)\n\n const\n InvLn2hi = reinterpret<f64>(0x3FF7154765200000), // 0x1.7154765200000p+0\n InvLn2lo = reinterpret<f64>(0x3DE705FC2EEFA200), // 0x1.705fc2eefa200p-33\n Ox1p52 = reinterpret<f64>(0x4330000000000000); // 0x1p52\n\n const\n B0 = reinterpret<f64>(0xBFE71547652B82FE), // -0x1.71547652b82fep-1\n B1 = reinterpret<f64>(0x3FDEC709DC3A03F7), // 0x1.ec709dc3a03f7p-2\n B2 = reinterpret<f64>(0xBFD71547652B7C3F), // -0x1.71547652b7c3fp-2\n B3 = reinterpret<f64>(0x3FD2776C50F05BE4), // 0x1.2776c50f05be4p-2\n B4 = reinterpret<f64>(0xBFCEC709DD768FE5), // -0x1.ec709dd768fe5p-3\n B5 = reinterpret<f64>(0x3FCA61761EC4E736), // 0x1.a61761ec4e736p-3\n B6 = reinterpret<f64>(0xBFC7153FBC64A79B), // -0x1.7153fbc64a79bp-3\n B7 = reinterpret<f64>(0x3FC484D154F01B4A), // 0x1.484d154f01b4ap-3\n B8 = reinterpret<f64>(0xBFC289E4A72C383C), // -0x1.289e4a72c383cp-3\n B9 = reinterpret<f64>(0x3FC0B32F285AEE66); // 0x1.0b32f285aee66p-3\n\n const\n A0 = reinterpret<f64>(0xBFE71547652B8339), // -0x1.71547652b8339p-1\n A1 = reinterpret<f64>(0x3FDEC709DC3A04BE), // 0x1.ec709dc3a04bep-2\n A2 = reinterpret<f64>(0xBFD7154764702FFB), // -0x1.7154764702ffbp-2\n A3 = reinterpret<f64>(0x3FD2776C50034C48), // 0x1.2776c50034c48p-2\n A4 = reinterpret<f64>(0xBFCEC7B328EA92BC), // -0x1.ec7b328ea92bcp-3\n A5 = reinterpret<f64>(0x3FCA6225E117F92E); // 0x1.a6225e117f92ep-3\n\n var ix = reinterpret<u64>(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n// #if __FP_FAST_FMA\n// hi = r * InvLn2hi;\n// lo = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -hi);\n// #else\n let rhi = reinterpret<f64>(reinterpret<u64>(r) & 0xFFFFFFFF00000000);\n let rlo = r - rhi;\n let hi = rhi * InvLn2hi;\n let lo = rlo * InvLn2hi + r * InvLn2lo;\n// #endif\n let r2 = r * r; // rounding error: 0x1p-62\n let r4 = r2 * r2;\n // Worst-case error is less than 0.54 ULP (0.55 ULP without fma)\n let p = r2 * (B0 + r * B1);\n let y = hi + p;\n lo += hi - y + p;\n lo += r4 * (B2 + r * B3 + r2 * (B4 + r * B5) +\n r4 * (B6 + r * B7 + r2 * (B8 + r * B9)));\n return y + lo;\n }\n var top = <u32>(ix >> 48);\n if (top - 0x0010 >= 0x7ff0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan.\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == 0x7FF0000000000000) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ix = reinterpret<u64>(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3FE6000000000000;\n var i = <usize>((tmp >> (52 - LOG2_TABLE_BITS)) & N_MASK);\n var k = <i64>tmp >> 52;\n var iz = ix - (tmp & 0xFFF0000000000000);\n\n var invc = load<f64>(changetype<usize>(LOG2_DATA_TAB1) + (i << (1 + alignof<f64>())), 0 << alignof<f64>()); // T[i].invc;\n var logc = load<f64>(changetype<usize>(LOG2_DATA_TAB1) + (i << (1 + alignof<f64>())), 1 << alignof<f64>()); // T[i].logc;\n var z = reinterpret<f64>(iz);\n var kd = <f64>k;\n\n // log2(x) = log2(z/c) + log2(c) + k.\n // r ~= z/c - 1, |r| < 1/(2*N).\n// #if __FP_FAST_FMA\n// \t// rounding error: 0x1p-55/N.\n// \tr = __builtin_fma(z, invc, -1.0);\n// \tt1 = r * InvLn2hi;\n// \tt2 = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -t1);\n// #else\n // rounding error: 0x1p-55/N + 0x1p-65.\n var chi = load<f64>(changetype<usize>(LOG2_DATA_TAB2) + (i << (1 + alignof<f64>())), 0 << alignof<f64>()); // T[i].chi;\n var clo = load<f64>(changetype<usize>(LOG2_DATA_TAB2) + (i << (1 + alignof<f64>())), 1 << alignof<f64>()); // T[i].clo;\n\n var r = (z - chi - clo) * invc;\n var rhi = reinterpret<f64>(reinterpret<u64>(r) & 0xFFFFFFFF00000000);\n var rlo = r - rhi;\n var t1 = rhi * InvLn2hi;\n var t2 = rlo * InvLn2hi + r * InvLn2lo;\n// #endif\n\n // hi + lo = r/ln2 + log2(c) + k\n var t3 = kd + logc;\n var hi = t3 + t1;\n var lo = t3 - hi + t1 + t2;\n\n // log2(r+1) = r/ln2 + r^2*poly(r)\n // Evaluation is optimized assuming superscalar pipelined execution\n var r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).\n // ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma).\n var p = A0 + r * A1 + r2 * (A2 + r * A3) + (r2 * r2) * (A4 + r * A5);\n return lo + r2 * p + hi;\n}\n\n//\n// Lookup data for log. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log.c\n//\n\n// @ts-ignore: decorator\n@inline\nconst LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p9 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-66 and\n 3) the rounding error in (double)log(c) is minimized (< 0x1p-66).\n\nNote: 1) ensures that k*ln2hi + logc can be computed without rounding error,\n2) ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to\na single rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log(x)| < 0x1p-4, this is not enough so that is special cased.*/\n\n// @ts-ignore: decorator\n@lazy @inline\nconst LOG_DATA_TAB1: StaticArray<f64> = [\n // invc , logc\n reinterpret<f64>(0x3FF734F0C3E0DE9F), reinterpret<f64>(0xBFD7CC7F79E69000),\n reinterpret<f64>(0x3FF713786A2CE91F), reinterpret<f64>(0xBFD76FEEC20D0000),\n reinterpret<f64>(0x3FF6F26008FAB5A0), reinterpret<f64>(0xBFD713E31351E000),\n reinterpret<f64>(0x3FF6D1A61F138C7D), reinterpret<f64>(0xBFD6B85B38287800),\n reinterpret<f64>(0x3FF6B1490BC5B4D1), reinterpret<f64>(0xBFD65D5590807800),\n reinterpret<f64>(0x3FF69147332F0CBA), reinterpret<f64>(0xBFD602D076180000),\n reinterpret<f64>(0x3FF6719F18224223), reinterpret<f64>(0xBFD5A8CA86909000),\n reinterpret<f64>(0x3FF6524F99A51ED9), reinterpret<f64>(0xBFD54F4356035000),\n reinterpret<f64>(0x3FF63356AA8F24C4), reinterpret<f64>(0xBFD4F637C36B4000),\n reinterpret<f64>(0x3FF614B36B9DDC14), reinterpret<f64>(0xBFD49DA7FDA85000),\n reinterpret<f64>(0x3FF5F66452C65C4C), reinterpret<f64>(0xBFD445923989A800),\n reinterpret<f64>(0x3FF5D867B5912C4F), reinterpret<f64>(0xBFD3EDF439B0B800),\n reinterpret<f64>(0x3FF5BABCCB5B90DE), reinterpret<f64>(0xBFD396CE448F7000),\n reinterpret<f64>(0x3FF59D61F2D91A78), reinterpret<f64>(0xBFD3401E17BDA000),\n reinterpret<f64>(0x3FF5805612465687), reinterpret<f64>(0xBFD2E9E2EF468000),\n reinterpret<f64>(0x3FF56397CEE76BD3), reinterpret<f64>(0xBFD2941B3830E000),\n reinterpret<f64>(0x3FF54725E2A77F93), reinterpret<f64>(0xBFD23EC58CDA8800),\n reinterpret<f64>(0x3FF52AFF42064583), reinterpret<f64>(0xBFD1E9E129279000),\n reinterpret<f64>(0x3FF50F22DBB2BDDF), reinterpret<f64>(0xBFD1956D2B48F800),\n reinterpret<f64>(0x3FF4F38F4734DED7), reinterpret<f64>(0xBFD141679AB9F800),\n reinterpret<f64>(0x3FF4D843CFDE2840), reinterpret<f64>(0xBFD0EDD094EF9800),\n reinterpret<f64>(0x3FF4BD3EC078A3C8), reinterpret<f64>(0xBFD09AA518DB1000),\n reinterpret<f64>(0x3FF4A27FC3E0258A), reinterpret<f64>(0xBFD047E65263B800),\n reinterpret<f64>(0x3FF4880524D48434), reinterpret<f64>(0xBFCFEB224586F000),\n reinterpret<f64>(0x3FF46DCE1B192D0B), reinterpret<f64>(0xBFCF474A7517B000),\n reinterpret<f64>(0x3FF453D9D3391854), reinterpret<f64>(0xBFCEA4443D103000),\n reinterpret<f64>(0x3FF43A2744B4845A), reinterpret<f64>(0xBFCE020D44E9B000),\n reinterpret<f64>(0x3FF420B54115F8FB), reinterpret<f64>(0xBFCD60A22977F000),\n reinterpret<f64>(0x3FF40782DA3EF4B1), reinterpret<f64>(0xBFCCC00104959000),\n reinterpret<f64>(0x3FF3EE8F5D57FE8F), reinterpret<f64>(0xBFCC202956891000),\n reinterpret<f64>(0x3FF3D5D9A00B4CE9), reinterpret<f64>(0xBFCB81178D811000),\n reinterpret<f64>(0x3FF3BD60C010C12B), reinterpret<f64>(0xBFCAE2C9CCD3D000),\n reinterpret<f64>(0x3FF3A5242B75DAB8), reinterpret<f64>(0xBFCA45402E129000),\n reinterpret<f64>(0x3FF38D22CD9FD002), reinterpret<f64>(0xBFC9A877681DF000),\n reinterpret<f64>(0x3FF3755BC5847A1C), reinterpret<f64>(0xBFC90C6D69483000),\n reinterpret<f64>(0x3FF35DCE49AD36E2), reinterpret<f64>(0xBFC87120A645C000),\n reinterpret<f64>(0x3FF34679984DD440), reinterpret<f64>(0xBFC7D68FB4143000),\n reinterpret<f64>(0x3FF32F5CCEFFCB24), reinterpret<f64>(0xBFC73CB83C627000),\n reinterpret<f64>(0x3FF3187775A10D49), reinterpret<f64>(0xBFC6A39A9B376000),\n reinterpret<f64>(0x3FF301C8373E3990), reinterpret<f64>(0xBFC60B3154B7A000),\n reinterpret<f64>(0x3FF2EB4EBB95F841), reinterpret<f64>(0xBFC5737D76243000),\n reinterpret<f64>(0x3FF2D50A0219A9D1), reinterpret<f64>(0xBFC4DC7B8FC23000),\n reinterpret<f64>(0x3FF2BEF9A8B7FD2A), reinterpret<f64>(0xBFC4462C51D20000),\n reinterpret<f64>(0x3FF2A91C7A0C1BAB), reinterpret<f64>(0xBFC3B08ABC830000),\n reinterpret<f64>(0x3FF293726014B530), reinterpret<f64>(0xBFC31B996B490000),\n reinterpret<f64>(0x3FF27DFA5757A1F5), reinterpret<f64>(0xBFC2875490A44000),\n reinterpret<f64>(0x3FF268B39B1D3BBF), reinterpret<f64>(0xBFC1F3B9F879A000),\n reinterpret<f64>(0x3FF2539D838FF5BD), reinterpret<f64>(0xBFC160C8252CA000),\n reinterpret<f64>(0x3FF23EB7AAC9083B), reinterpret<f64>(0xBFC0CE7F57F72000),\n reinterpret<f64>(0x3FF22A012BA940B6), reinterpret<f64>(0xBFC03CDC49FEA000),\n reinterpret<f64>(0x3FF2157996CC4132), reinterpret<f64>(0xBFBF57BDBC4B8000),\n reinterpret<f64>(0x3FF201201DD2FC9B), reinterpret<f64>(0xBFBE370896404000),\n reinterpret<f64>(0x3FF1ECF4494D480B), reinterpret<f64>(0xBFBD17983EF94000),\n reinterpret<f64>(0x3FF1D8F5528F6569), reinterpret<f64>(0xBFBBF9674ED8A000),\n reinterpret<f64>(0x3FF1C52311577E7C), reinterpret<f64>(0xBFBADC79202F6000),\n reinterpret<f64>(0x3FF1B17C74CB26E9), reinterpret<f64>(0xBFB9C0C3E7288000),\n reinterpret<f64>(0x3FF19E010C2C1AB6), reinterpret<f64>(0xBFB8A646B372C000),\n reinterpret<f64>(0x3FF18AB07BB670BD), reinterpret<f64>(0xBFB78D01B3AC0000),\n reinterpret<f64>(0x3FF1778A25EFBCB6), reinterpret<f64>(0xBFB674F145380000),\n reinterpret<f64>(0x3FF1648D354C31DA), reinterpret<f64>(0xBFB55E0E6D878000),\n reinterpret<f64>(0x3FF151B990275FDD), reinterpret<f64>(0xBFB4485CDEA1E000),\n reinterpret<f64>(0x3FF13F0EA432D24C), reinterpret<f64>(0xBFB333D94D6AA000),\n reinterpret<f64>(0x3FF12C8B7210F9DA), reinterpret<f64>(0xBFB22079F8C56000),\n reinterpret<f64>(0x3FF11A3028ECB531), reinterpret<f64>(0xBFB10E4698622000),\n reinterpret<f64>(0x3FF107FBDA8434AF), reinterpret<f64>(0xBFAFFA6C6AD20000),\n reinterpret<f64>(0x3FF0F5EE0F4E6BB3), reinterpret<f64>(0xBFADDA8D4A774000),\n reinterpret<f64>(0x3FF0E4065D2A9FCE), reinterpret<f64>(0xBFABBCECE4850000),\n reinterpret<f64>(0x3FF0D244632CA521), reinterpret<f64>(0xBFA9A1894012C000),\n reinterpret<f64>(0x3FF0C0A77CE2981A), reinterpret<f64>(0xBFA788583302C000),\n reinterpret<f64>(0x3FF0AF2F83C636D1), reinterpret<f64>(0xBFA5715E67D68000),\n reinterpret<f64>(0x3FF09DDB98A01339), reinterpret<f64>(0xBFA35C8A49658000),\n reinterpret<f64>(0x3FF08CABAF52E7DF), reinterpret<f64>(0xBFA149E364154000),\n reinterpret<f64>(0x3FF07B9F2F4E28FB), reinterpret<f64>(0xBF9E72C082EB8000),\n reinterpret<f64>(0x3FF06AB58C358F19), reinterpret<f64>(0xBF9A55F152528000),\n reinterpret<f64>(0x3FF059EEA5ECF92C), reinterpret<f64>(0xBF963D62CF818000),\n reinterpret<f64>(0x3FF04949CDD12C90), reinterpret<f64>(0xBF9228FB8CAA0000),\n reinterpret<f64>(0x3FF038C6C6F0ADA9), reinterpret<f64>(0xBF8C317B20F90000),\n reinterpret<f64>(0x3FF02865137932A9), reinterpret<f64>(0xBF8419355DAA0000),\n reinterpret<f64>(0x3FF0182427EA7348), reinterpret<f64>(0xBF781203C2EC0000),\n reinterpret<f64>(0x3FF008040614B195), reinterpret<f64>(0xBF60040979240000),\n reinterpret<f64>(0x3FEFE01FF726FA1A), reinterpret<f64>(0x3F6FEFF384900000),\n reinterpret<f64>(0x3FEFA11CC261EA74), reinterpret<f64>(0x3F87DC41353D0000),\n reinterpret<f64>(0x3FEF6310B081992E), reinterpret<f64>(0x3F93CEA3C4C28000),\n reinterpret<f64>(0x3FEF25F63CEEADCD), reinterpret<f64>(0x3F9B9FC114890000),\n reinterpret<f64>(0x3FEEE9C8039113E7), reinterpret<f64>(0x3FA1B0D8CE110000),\n reinterpret<f64>(0x3FEEAE8078CBB1AB), reinterpret<f64>(0x3FA58A5BD001C000),\n reinterpret<f64>(0x3FEE741AA29D0C9B), reinterpret<f64>(0x3FA95C8340D88000),\n reinterpret<f64>(0x3FEE3A91830A99B5), reinterpret<f64>(0x3FAD276AEF578000),\n reinterpret<f64>(0x3FEE01E009609A56), reinterpret<f64>(0x3FB07598E598C000),\n reinterpret<f64>(0x3FEDCA01E577BB98), reinterpret<f64>(0x3FB253F5E30D2000),\n reinterpret<f64>(0x3FED92F20B7C9103), reinterpret<f64>(0x3FB42EDD8B380000),\n reinterpret<f64>(0x3FED5CAC66FB5CCE), reinterpret<f64>(0x3FB606598757C000),\n reinterpret<f64>(0x3FED272CAA5EDE9D), reinterpret<f64>(0x3FB7DA76356A0000),\n reinterpret<f64>(0x3FECF26E3E6B2CCD), reinterpret<f64>(0x3FB9AB434E1C6000),\n reinterpret<f64>(0x3FECBE6DA2A77902), reinterpret<f64>(0x3FBB78C7BB0D6000),\n reinterpret<f64>(0x3FEC8B266D37086D), reinterpret<f64>(0x3FBD431332E72000),\n reinterpret<f64>(0x3FEC5894BD5D5804), reinterpret<f64>(0x3FBF0A3171DE6000),\n reinterpret<f64>(0x3FEC26B533BB9F8C), reinterpret<f64>(0x3FC067152B914000),\n reinterpret<f64>(0x3FEBF583EEECE73F), reinterpret<f64>(0x3FC147858292B000),\n reinterpret<f64>(0x3FEBC4FD75DB96C1), reinterpret<f64>(0x3FC2266ECDCA3000),\n reinterpret<f64>(0x3FEB951E0C864A28), reinterpret<f64>(0x3FC303D7A6C55000),\n reinterpret<f64>(0x3FEB65E2C5EF3E2C), reinterpret<f64>(0x3FC3DFC33C331000),\n reinterpret<f64>(0x3FEB374867C9888B), reinterpret<f64>(0x3FC4BA366B7A8000),\n reinterpret<f64>(0x3FEB094B211D304A), reinterpret<f64>(0x3FC5933928D1F000),\n reinterpret<f64>(0x3FEADBE885F2EF7E), reinterpret<f64>(0x3FC66ACD2418F000),\n reinterpret<f64>(0x3FEAAF1D31603DA2), reinterpret<f64>(0x3FC740F8EC669000),\n reinterpret<f64>(0x3FEA82E63FD358A7), reinterpret<f64>(0x3FC815C0F51AF000),\n reinterpret<f64>(0x3FEA5740EF09738B), reinterpret<f64>(0x3FC8E92954F68000),\n reinterpret<f64>(0x3FEA2C2A90AB4B27), reinterpret<f64>(0x3FC9BB3602F84000),\n reinterpret<f64>(0x3FEA01A01393F2D1), reinterpret<f64>(0x3FCA8BED1C2C0000),\n reinterpret<f64>(0x3FE9D79F24DB3C1B), reinterpret<f64>(0x3FCB5B515C01D000),\n reinterpret<f64>(0x3FE9AE2505C7B190), reinterpret<f64>(0x3FCC2967CCBCC000),\n reinterpret<f64>(0x3FE9852EF297CE2F), reinterpret<f64>(0x3FCCF635D5486000),\n reinterpret<f64>(0x3FE95CBAEEA44B75), reinterpret<f64>(0x3FCDC1BD3446C000),\n reinterpret<f64>(0x3FE934C69DE74838), reinterpret<f64>(0x3FCE8C01B8CFE000),\n reinterpret<f64>(0x3FE90D4F2F6752E6), reinterpret<f64>(0x3FCF5509C0179000),\n reinterpret<f64>(0x3FE8E6528EFFD79D), reinterpret<f64>(0x3FD00E6C121FB800),\n reinterpret<f64>(0x3FE8BFCE9FCC007C), reinterpret<f64>(0x3FD071B80E93D000),\n reinterpret<f64>(0x3FE899C0DABEC30E), reinterpret<f64>(0x3FD0D46B9E867000),\n reinterpret<f64>(0x3FE87427AA2317FB), reinterpret<f64>(0x3FD13687334BD000),\n reinterpret<f64>(0x3FE84F00ACB39A08), reinterpret<f64>(0x3FD1980D67234800),\n reinterpret<f64>(0x3FE82A49E8653E55), reinterpret<f64>(0x3FD1F8FFE0CC8000),\n reinterpret<f64>(0x3FE8060195F40260), reinterpret<f64>(0x3FD2595FD7636800),\n reinterpret<f64>(0x3FE7E22563E0A329), reinterpret<f64>(0x3FD2B9300914A800),\n reinterpret<f64>(0x3FE7BEB377DCB5AD), reinterpret<f64>(0x3FD3187210436000),\n reinterpret<f64>(0x3FE79BAA679725C2), reinterpret<f64>(0x3FD377266DEC1800),\n reinterpret<f64>(0x3FE77907F2170657), reinterpret<f64>(0x3FD3D54FFBAF3000),\n reinterpret<f64>(0x3FE756CADBD6130C), reinterpret<f64>(0x3FD432EEE32FE000)\n];\n\n// @ts-ignore: decorator\n@lazy @inline\nconst LOG_DATA_TAB2: StaticArray<f64> = [\n // chi , clo\n reinterpret<f64>(0x3FE61000014FB66B), reinterpret<f64>(0x3C7E026C91425B3C),\n reinterpret<f64>(0x3FE63000034DB495), reinterpret<f64>(0x3C8DBFEA48005D41),\n reinterpret<f64>(0x3FE650000D94D478), reinterpret<f64>(0x3C8E7FA786D6A5B7),\n reinterpret<f64>(0x3FE67000074E6FAD), reinterpret<f64>(0x3C61FCEA6B54254C),\n reinterpret<f64>(0x3FE68FFFFEDF0FAE), reinterpret<f64>(0xBC7C7E274C590EFD),\n reinterpret<f64>(0x3FE6B0000763C5BC), reinterpret<f64>(0xBC8AC16848DCDA01),\n reinterpret<f64>(0x3FE6D0001E5CC1F6), reinterpret<f64>(0x3C833F1C9D499311),\n reinterpret<f64>(0x3FE6EFFFEB05F63E), reinterpret<f64>(0xBC7E80041AE22D53),\n reinterpret<f64>(0x3FE710000E869780), reinterpret<f64>(0x3C7BFF6671097952),\n reinterpret<f64>(0x3FE72FFFFC67E912), reinterpret<f64>(0x3C8C00E226BD8724),\n reinterpret<f64>(0x3FE74FFFDF81116A), reinterpret<f64>(0xBC6E02916EF101D2),\n reinterpret<f64>(0x3FE770000F679C90), reinterpret<f64>(0xBC67FC71CD549C74),\n reinterpret<f64>(0x3FE78FFFFA7EC835), reinterpret<f64>(0x3C81BEC19EF50483),\n reinterpret<f64>(0x3FE7AFFFFE20C2E6), reinterpret<f64>(0xBC707E1729CC6465),\n reinterpret<f64>(0x3FE7CFFFED3FC900), reinterpret<f64>(0xBC808072087B8B1C),\n reinterpret<f64>(0x3FE7EFFFE9261A76), reinterpret<f64>(0x3C8DC0286D9DF9AE),\n reinterpret<f64>(0x3FE81000049CA3E8), reinterpret<f64>(0x3C897FD251E54C33),\n reinterpret<f64>(0x3FE8300017932C8F), reinterpret<f64>(0xBC8AFEE9B630F381),\n reinterpret<f64>(0x3FE850000633739C), reinterpret<f64>(0x3C89BFBF6B6535BC),\n reinterpret<f64>(0x3FE87000204289C6), reinterpret<f64>(0xBC8BBF65F3117B75),\n reinterpret<f64>(0x3FE88FFFEBF57904), reinterpret<f64>(0xBC89006EA23DCB57),\n reinterpret<f64>(0x3FE8B00022BC04DF), reinterpret<f64>(0xBC7D00DF38E04B0A),\n reinterpret<f64>(0x3FE8CFFFE50C1B8A), reinterpret<f64>(0xBC88007146FF9F05),\n reinterpret<f64>(0x3FE8EFFFFC918E43), reinterpret<f64>(0x3C83817BD07A7038),\n reinterpret<f64>(0x3FE910001EFA5FC7), reinterpret<f64>(0x3C893E9176DFB403),\n reinterpret<f64>(0x3FE9300013467BB9), reinterpret<f64>(0x3C7F804E4B980276),\n reinterpret<f64>(0x3FE94FFFE6EE076F), reinterpret<f64>(0xBC8F7EF0D9FF622E),\n reinterpret<f64>(0x3FE96FFFDE3C12D1), reinterpret<f64>(0xBC7082AA962638BA),\n reinterpret<f64>(0x3FE98FFFF4458A0D), reinterpret<f64>(0xBC87801B9164A8EF),\n reinterpret<f64>(0x3FE9AFFFDD982E3E), reinterpret<f64>(0xBC8740E08A5A9337),\n reinterpret<f64>(0x3FE9CFFFED49FB66), reinterpret<f64>(0x3C3FCE08C19BE000),\n reinterpret<f64>(0x3FE9F00020F19C51), reinterpret<f64>(0xBC8A3FAA27885B0A),\n reinterpret<f64>(0x3FEA10001145B006), reinterpret<f64>(0x3C74FF489958DA56),\n reinterpret<f64>(0x3FEA300007BBF6FA), reinterpret<f64>(0x3C8CBEAB8A2B6D18),\n reinterpret<f64>(0x3FEA500010971D79), reinterpret<f64>(0x3C88FECADD787930),\n reinterpret<f64>(0x3FEA70001DF52E48), reinterpret<f64>(0xBC8F41763DD8ABDB),\n reinterpret<f64>(0x3FEA90001C593352), reinterpret<f64>(0xBC8EBF0284C27612),\n reinterpret<f64>(0x3FEAB0002A4F3E4B), reinterpret<f64>(0xBC69FD043CFF3F5F),\n reinterpret<f64>(0x3FEACFFFD7AE1ED1), reinterpret<f64>(0xBC823EE7129070B4),\n reinterpret<f64>(0x3FEAEFFFEE510478), reinterpret<f64>(0x3C6A063EE00EDEA3),\n reinterpret<f64>(0x3FEB0FFFDB650D5B), reinterpret<f64>(0x3C5A06C8381F0AB9),\n reinterpret<f64>(0x3FEB2FFFFEAACA57), reinterpret<f64>(0xBC79011E74233C1D),\n reinterpret<f64>(0x3FEB4FFFD995BADC), reinterpret<f64>(0xBC79FF1068862A9F),\n reinterpret<f64>(0x3FEB7000249E659C), reinterpret<f64>(0x3C8AFF45D0864F3E),\n reinterpret<f64>(0x3FEB8FFFF9871640), reinterpret<f64>(0x3C7CFE7796C2C3F9),\n reinterpret<f64>(0x3FEBAFFFD204CB4F), reinterpret<f64>(0xBC63FF27EEF22BC4),\n reinterpret<f64>(0x3FEBCFFFD2415C45), reinterpret<f64>(0xBC6CFFB7EE3BEA21),\n reinterpret<f64>(0x3FEBEFFFF86309DF), reinterpret<f64>(0xBC814103972E0B5C),\n reinterpret<f64>(0x3FEC0FFFE1B57653), reinterpret<f64>(0x3C8BC16494B76A19),\n reinterpret<f64>(0x3FEC2FFFF1FA57E3), reinterpret<f64>(0xBC64FEEF8D30C6ED),\n reinterpret<f64>(0x3FEC4FFFDCBFE424), reinterpret<f64>(0xBC843F68BCEC4775),\n reinterpret<f64>(0x3FEC6FFFED54B9F7), reinterpret<f64>(0x3C847EA3F053E0EC),\n reinterpret<f64>(0x3FEC8FFFEB998FD5), reinterpret<f64>(0x3C7383068DF992F1),\n reinterpret<f64>(0x3FECB0002125219A), reinterpret<f64>(0xBC68FD8E64180E04),\n reinterpret<f64>(0x3FECCFFFDD94469C), reinterpret<f64>(0x3C8E7EBE1CC7EA72),\n reinterpret<f64>(0x3FECEFFFEAFDC476), reinterpret<f64>(0x3C8EBE39AD9F88FE),\n reinterpret<f64>(0x3FED1000169AF82B), reinterpret<f64>(0x3C757D91A8B95A71),\n reinterpret<f64>(0x3FED30000D0FF71D), reinterpret<f64>(0x3C89C1906970C7DA),\n reinterpret<f64>(0x3FED4FFFEA790FC4), reinterpret<f64>(0xBC580E37C558FE0C),\n reinterpret<f64>(0x3FED70002EDC87E5), reinterpret<f64>(0xBC7F80D64DC10F44),\n reinterpret<f64>(0x3FED900021DC82AA), reinterpret<f64>(0xBC747C8F94FD5C5C),\n reinterpret<f64>(0x3FEDAFFFD86B0283), reinterpret<f64>(0x3C8C7F1DC521617E),\n reinterpret<f64>(0x3FEDD000296C4739), reinterpret<f64>(0x3C88019EB2FFB153),\n reinterpret<f64>(0x3FEDEFFFE54490F5), reinterpret<f64>(0x3C6E00D2C652CC89),\n reinterpret<f64>(0x3FEE0FFFCDABF694), reinterpret<f64>(0xBC7F8340202D69D2),\n reinterpret<f64>(0x3FEE2FFFDB52C8DD), reinterpret<f64>(0x3C7B00C1CA1B0864),\n reinterpret<f64>(0x3FEE4FFFF24216EF), reinterpret<f64>(0x3C72FFA8B094AB51),\n reinterpret<f64>(0x3FEE6FFFE88A5E11), reinterpret<f64>(0xBC57F673B1EFBE59),\n reinterpret<f64>(0x3FEE9000119EFF0D), reinterpret<f64>(0xBC84808D5E0BC801),\n reinterpret<f64>(0x3FEEAFFFDFA51744), reinterpret<f64>(0x3C780006D54320B5),\n reinterpret<f64>(0x3FEED0001A127FA1), reinterpret<f64>(0xBC5002F860565C92),\n reinterpret<f64>(0x3FEEF00007BABCC4), reinterpret<f64>(0xBC8540445D35E611),\n reinterpret<f64>(0x3FEF0FFFF57A8D02), reinterpret<f64>(0xBC4FFB3139EF9105),\n reinterpret<f64>(0x3FEF30001EE58AC7), reinterpret<f64>(0x3C8A81ACF2731155),\n reinterpret<f64>(0x3FEF4FFFF5823494), reinterpret<f64>(0x3C8A3F41D4D7C743),\n reinterpret<f64>(0x3FEF6FFFFCA94C6B), reinterpret<f64>(0xBC6202F41C987875),\n reinterpret<f64>(0x3FEF8FFFE1F9C441), reinterpret<f64>(0x3C777DD1F477E74B),\n reinterpret<f64>(0x3FEFAFFFD2E0E37E), reinterpret<f64>(0xBC6F01199A7CA331),\n reinterpret<f64>(0x3FEFD0001C77E49E), reinterpret<f64>(0x3C7181EE4BCEACB1),\n reinterpret<f64>(0x3FEFEFFFF7E0C331), reinterpret<f64>(0xBC6E05370170875A),\n reinterpret<f64>(0x3FF00FFFF465606E), reinterpret<f64>(0xBC8A7EAD491C0ADA),\n reinterpret<f64>(0x3FF02FFFF3867A58), reinterpret<f64>(0xBC977F69C3FCB2E0),\n reinterpret<f64>(0x3FF04FFFFDFC0D17), reinterpret<f64>(0x3C97BFFE34CB945B),\n reinterpret<f64>(0x3FF0700003CD4D82), reinterpret<f64>(0x3C820083C0E456CB),\n reinterpret<f64>(0x3FF08FFFF9F2CBE8), reinterpret<f64>(0xBC6DFFDFBE37751A),\n reinterpret<f64>(0x3FF0B000010CDA65), reinterpret<f64>(0xBC913F7FAEE626EB),\n reinterpret<f64>(0x3FF0D00001A4D338), reinterpret<f64>(0x3C807DFA79489FF7),\n reinterpret<f64>(0x3FF0EFFFFADAFDFD), reinterpret<f64>(0xBC77040570D66BC0),\n reinterpret<f64>(0x3FF110000BBAFD96), reinterpret<f64>(0x3C8E80D4846D0B62),\n reinterpret<f64>(0x3FF12FFFFAE5F45D), reinterpret<f64>(0x3C9DBFFA64FD36EF),\n reinterpret<f64>(0x3FF150000DD59AD9), reinterpret<f64>(0x3C9A0077701250AE),\n reinterpret<f64>(0x3FF170000F21559A), reinterpret<f64>(0x3C8DFDF9E2E3DEEE),\n reinterpret<f64>(0x3FF18FFFFC275426), reinterpret<f64>(0x3C910030DC3B7273),\n reinterpret<f64>(0x3FF1B000123D3C59), reinterpret<f64>(0x3C997F7980030188),\n reinterpret<f64>(0x3FF1CFFFF8299EB7), reinterpret<f64>(0xBC65F932AB9F8C67),\n reinterpret<f64>(0x3FF1EFFFF48AD400), reinterpret<f64>(0x3C937FBF9DA75BEB),\n reinterpret<f64>(0x3FF210000C8B86A4), reinterpret<f64>(0x3C9F806B91FD5B22),\n reinterpret<f64>(0x3FF2300003854303), reinterpret<f64>(0x3C93FFC2EB9FBF33),\n reinterpret<f64>(0x3FF24FFFFFBCF684), reinterpret<f64>(0x3C7601E77E2E2E72),\n reinterpret<f64>(0x3FF26FFFF52921D9), reinterpret<f64>(0x3C7FFCBB767F0C61),\n reinterpret<f64>(0x3FF2900014933A3C), reinterpret<f64>(0xBC7202CA3C02412B),\n reinterpret<f64>(0x3FF2B00014556313), reinterpret<f64>(0xBC92808233F21F02),\n reinterpret<f64>(0x3FF2CFFFEBFE523B), reinterpret<f64>(0xBC88FF7E384FDCF2),\n reinterpret<f64>(0x3FF2F0000BB8AD96), reinterpret<f64>(0xBC85FF51503041C5),\n reinterpret<f64>(0x3FF30FFFFB7AE2AF), reinterpret<f64>(0xBC810071885E289D),\n reinterpret<f64>(0x3FF32FFFFEAC5F7F), reinterpret<f64>(0xBC91FF5D3FB7B715),\n reinterpret<f64>(0x3FF350000CA66756), reinterpret<f64>(0x3C957F82228B82BD),\n reinterpret<f64>(0x3FF3700011FBF721), reinterpret<f64>(0x3C8000BAC40DD5CC),\n reinterpret<f64>(0x3FF38FFFF9592FB9), reinterpret<f64>(0xBC943F9D2DB2A751),\n reinterpret<f64>(0x3FF3B00004DDD242), reinterpret<f64>(0x3C857F6B707638E1),\n reinterpret<f64>(0x3FF3CFFFF5B2C957), reinterpret<f64>(0x3C7A023A10BF1231),\n reinterpret<f64>(0x3FF3EFFFEAB0B418), reinterpret<f64>(0x3C987F6D66B152B0),\n reinterpret<f64>(0x3FF410001532AFF4), reinterpret<f64>(0x3C67F8375F198524),\n reinterpret<f64>(0x3FF4300017478B29), reinterpret<f64>(0x3C8301E672DC5143),\n reinterpret<f64>(0x3FF44FFFE795B463), reinterpret<f64>(0x3C89FF69B8B2895A),\n reinterpret<f64>(0x3FF46FFFE80475E0), reinterpret<f64>(0xBC95C0B19BC2F254),\n reinterpret<f64>(0x3FF48FFFEF6FC1E7), reinterpret<f64>(0x3C9B4009F23A2A72),\n reinterpret<f64>(0x3FF4AFFFE5BEA704), reinterpret<f64>(0xBC94FFB7BF0D7D45),\n reinterpret<f64>(0x3FF4D000171027DE), reinterpret<f64>(0xBC99C06471DC6A3D),\n reinterpret<f64>(0x3FF4F0000FF03EE2), reinterpret<f64>(0x3C977F890B85531C),\n reinterpret<f64>(0x3FF5100012DC4BD1), reinterpret<f64>(0x3C6004657166A436),\n reinterpret<f64>(0x3FF530001605277A), reinterpret<f64>(0xBC96BFCECE233209),\n reinterpret<f64>(0x3FF54FFFECDB704C), reinterpret<f64>(0xBC8902720505A1D7),\n reinterpret<f64>(0x3FF56FFFEF5F54A9), reinterpret<f64>(0x3C9BBFE60EC96412),\n reinterpret<f64>(0x3FF5900017E61012), reinterpret<f64>(0x3C887EC581AFEF90),\n reinterpret<f64>(0x3FF5B00003C93E92), reinterpret<f64>(0xBC9F41080ABF0CC0),\n reinterpret<f64>(0x3FF5D0001D4919BC), reinterpret<f64>(0xBC98812AFB254729),\n reinterpret<f64>(0x3FF5EFFFE7B87A89), reinterpret<f64>(0xBC947EB780ED6904)\n];\n\n// @ts-ignore: decorator\n@inline\nexport function log_lut(x: f64): f64 {\n const N_MASK = (1 << LOG_TABLE_BITS) - 1;\n\n const\n B0 = reinterpret<f64>(0xBFE0000000000000), // -0x1p-1\n B1 = reinterpret<f64>(0x3FD5555555555577), // 0x1.5555555555577p-2\n B2 = reinterpret<f64>(0xBFCFFFFFFFFFFDCB), // -0x1.ffffffffffdcbp-3\n B3 = reinterpret<f64>(0x3FC999999995DD0C), // 0x1.999999995dd0cp-3\n B4 = reinterpret<f64>(0xBFC55555556745A7), // -0x1.55555556745a7p-3\n B5 = reinterpret<f64>(0x3FC24924A344DE30), // 0x1.24924a344de3p-3\n B6 = reinterpret<f64>(0xBFBFFFFFA4423D65), // -0x1.fffffa4423d65p-4\n B7 = reinterpret<f64>(0x3FBC7184282AD6CA), // 0x1.c7184282ad6cap-4\n B8 = reinterpret<f64>(0xBFB999EB43B068FF), // -0x1.999eb43b068ffp-4\n B9 = reinterpret<f64>(0x3FB78182F7AFD085), // 0x1.78182f7afd085p-4\n B10 = reinterpret<f64>(0xBFB5521375D145CD); // -0x1.5521375d145cdp-4\n\n const\n A0 = reinterpret<f64>(0xBFE0000000000001), // -0x1.0000000000001p-1\n A1 = reinterpret<f64>(0x3FD555555551305B), // 0x1.555555551305bp-2\n A2 = reinterpret<f64>(0xBFCFFFFFFFEB4590), // -0x1.fffffffeb459p-3\n A3 = reinterpret<f64>(0x3FC999B324F10111), // 0x1.999b324f10111p-3\n A4 = reinterpret<f64>(0xBFC55575E506C89F); // -0x1.55575e506c89fp-3\n\n const\n LO: u64 = 0x3FEE000000000000,\n HI: u64 = 0x3FF1090000000000;\n\n const\n Ln2hi = reinterpret<f64>(0x3FE62E42FEFA3800), // 0x1.62e42fefa3800p-1\n Ln2lo = reinterpret<f64>(0x3D2EF35793C76730), // 0x1.ef35793c76730p-45\n Ox1p27 = reinterpret<f64>(0x41A0000000000000), // 0x1p27\n Ox1p52 = reinterpret<f64>(0x4330000000000000); // 0x1p52\n\n var ix = reinterpret<u64>(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n let r2 = r * r;\n let r3 = r2 * r;\n let y =\n r3 * (B1 + r * B2 + r2 * B3 +\n r3 * (B4 + r * B5 + r2 * B6 +\n r3 * (B7 + r * B8 + r2 * B9 + r3 * B10)));\n // Worst-case error is around 0.507 ULP\n let w = r * Ox1p27;\n let rhi = r + w - w;\n let rlo = r - rhi;\n w = rhi * rhi * B0; // B[0] == -0.5\n let hi = r + w;\n let lo = r - hi + w;\n lo += B0 * rlo * (rhi + r);\n return y + lo + hi;\n }\n var top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7FF0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == reinterpret<u64>(Infinity)) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it\n ix = reinterpret<u64>(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3FE6000000000000;\n var i = <usize>((tmp >> (52 - LOG_TABLE_BITS)) & N_MASK);\n var k = <i64>tmp >> 52;\n var iz = ix - (tmp & (u64(0xFFF) << 52));\n\n var invc = load<f64>(changetype<usize>(LOG_DATA_TAB1) + (i << (1 + alignof<f64>())), 0 << alignof<f64>()); // T[i].invc;\n var logc = load<f64>(changetype<usize>(LOG_DATA_TAB1) + (i << (1 + alignof<f64>())), 1 << alignof<f64>()); // T[i].logc;\n var z = reinterpret<f64>(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2.\n // r ~= z/c - 1, |r| < 1/(2*N)\n// #if __FP_FAST_FMA\n// \t// rounding error: 0x1p-55/N\n// \tr = __builtin_fma(z, invc, -1.0);\n// #else\n // rounding error: 0x1p-55/N + 0x1p-66\n const chi = load<f64>(changetype<usize>(LOG_DATA_TAB2) + (i << (1 + alignof<f64>())), 0 << alignof<f64>()); // T2[i].chi\n const clo = load<f64>(changetype<usize>(LOG_DATA_TAB2) + (i << (1 + alignof<f64>())), 1 << alignof<f64>()); // T2[i].clo\n var r = (z - chi - clo) * invc;\n// #endif\n var kd = <f64>k;\n\n // hi + lo = r + log(c) + k*Ln2\n var w = kd * Ln2hi + logc;\n var hi = w + r;\n var lo = w - hi + r + kd * Ln2lo;\n\n // log(x) = lo + (log1p(r) - r) + hi\n var r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst case error if |y| > 0x1p-5:\n // 0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma)\n // Worst case error if |y| > 0x1p-4:\n // 0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma).\n return lo + r2 * A0 + r * r2 * (A1 + r * A2 + r2 * (A3 + r * A4)) + hi;\n}\n\n//\n// Lookup data for pow. See: https://git.musl-libc.org/cgit/musl/tree/src/math/pow.c\n//\n\n// @ts-ignore: decorator\n@inline\nconst POW_LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [0x1.69555p-1; 0x1.69555p0] which is split into N subintervals\nand z falls into the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = round(0x1p43*log(c))/0x1p43\n tab[i].logctail = (double)(log(c) - logc)\n\nwhere c is chosen near the center of the subinterval such that 1/c has only a\nfew precision bits so z/c - 1 is exactly representible as double:\n\n 1/c = center < 1 ? round(N/center)/N : round(2*N/center)/N/2\n\nNote: |z/c - 1| < 1/N for the chosen c, |log(c) - logc - logctail| < 0x1p-97,\nthe last few bits of logc are rounded away so k*ln2hi + logc has no rounding\nerror and the interval for z is selected such that near x == 1, where log(x)\nis tiny, large cancellation error is avoided in logc + poly(z/c - 1). */\n\n// @ts-ignore: decorator\n@lazy @inline\nconst POW_LOG_DATA_TAB: StaticArray<f64> = [\n // invc ,pad, logc , logctail\n reinterpret<f64>(0x3FF6A00000000000), 0, reinterpret<f64>(0xBFD62C82F2B9C800), reinterpret<f64>(0x3CFAB42428375680),\n reinterpret<f64>(0x3FF6800000000000), 0, reinterpret<f64>(0xBFD5D1BDBF580800), reinterpret<f64>(0xBD1CA508D8E0F720),\n reinterpret<f64>(0x3FF6600000000000), 0, reinterpret<f64>(0xBFD5767717455800), reinterpret<f64>(0xBD2362A4D5B6506D),\n reinterpret<f64>(0x3FF6400000000000), 0, reinterpret<f64>(0xBFD51AAD872DF800), reinterpret<f64>(0xBCE684E49EB067D5),\n reinterpret<f64>(0x3FF6200000000000), 0, reinterpret<f64>(0xBFD4BE5F95777800), reinterpret<f64>(0xBD041B6993293EE0),\n reinterpret<f64>(0x3FF6000000000000), 0, reinterpret<f64>(0xBFD4618BC21C6000), reinterpret<f64>(0x3D13D82F484C84CC),\n reinterpret<f64>(0x3FF5E00000000000), 0, reinterpret<f64>(0xBFD404308686A800), reinterpret<f64>(0x3CDC42F3ED820B3A),\n reinterpret<f64>(0x3FF5C00000000000), 0, reinterpret<f64>(0xBFD3A64C55694800), reinterpret<f64>(0x3D20B1C686519460),\n reinterpret<f64>(0x3FF5A00000000000), 0, reinterpret<f64>(0xBFD347DD9A988000), reinterpret<f64>(0x3D25594DD4C58092),\n reinterpret<f64>(0x3FF5800000000000), 0, reinterpret<f64>(0xBFD2E8E2BAE12000), reinterpret<f64>(0x3D267B1E99B72BD8),\n reinterpret<f64>(0x3FF5600000000000), 0, reinterpret<f64>(0xBFD2895A13DE8800), reinterpret<f64>(0x3D15CA14B6CFB03F),\n reinterpret<f64>(0x3FF5600000000000), 0, reinterpret<f64>(0xBFD2895A13DE8800), reinterpret<f64>(0x3D15CA14B6CFB03F),\n reinterpret<f64>(0x3FF5400000000000), 0, reinterpret<f64>(0xBFD22941FBCF7800), reinterpret<f64>(0xBD165A242853DA76),\n reinterpret<f64>(0x3FF5200000000000), 0, reinterpret<f64>(0xBFD1C898C1699800), reinterpret<f64>(0xBD1FAFBC68E75404),\n reinterpret<f64>(0x3FF5000000000000), 0, reinterpret<f64>(0xBFD1675CABABA800), reinterpret<f64>(0x3D1F1FC63382A8F0),\n reinterpret<f64>(0x3FF4E00000000000), 0, reinterpret<f64>(0xBFD1058BF9AE4800), reinterpret<f64>(0xBD26A8C4FD055A66),\n reinterpret<f64>(0x3FF4C00000000000), 0, reinterpret<f64>(0xBFD0A324E2739000), reinterpret<f64>(0xBD0C6BEE7EF4030E),\n reinterpret<f64>(0x3FF4A00000000000), 0, reinterpret<f64>(0xBFD0402594B4D000), reinterpret<f64>(0xBCF036B89EF42D7F),\n reinterpret<f64>(0x3FF4A00000000000), 0, reinterpret<f64>(0xBFD0402594B4D000), reinterpret<f64>(0xBCF036B89EF42D7F),\n reinterpret<f64>(0x3FF4800000000000), 0, reinterpret<f64>(0xBFCFB9186D5E4000), reinterpret<f64>(0x3D0D572AAB993C87),\n reinterpret<f64>(0x3FF4600000000000), 0, reinterpret<f64>(0xBFCEF0ADCBDC6000), reinterpret<f64>(0x3D2B26B79C86AF24),\n reinterpret<f64>(0x3FF4400000000000), 0, reinterpret<f64>(0xBFCE27076E2AF000), reinterpret<f64>(0xBD172F4F543FFF10),\n reinterpret<f64>(0x3FF4200000000000), 0, reinterpret<f64>(0xBFCD5C216B4FC000), reinterpret<f64>(0x3D21BA91BBCA681B),\n reinterpret<f64>(0x3FF4000000000000), 0, reinterpret<f64>(0xBFCC8FF7C79AA000), reinterpret<f64>(0x3D27794F689F8434),\n reinterpret<f64>(0x3FF4000000000000), 0, reinterpret<f64>(0xBFCC8FF7C79AA000), reinterpret<f64>(0x3D27794F689F8434),\n reinterpret<f64>(0x3FF3E00000000000), 0, reinterpret<f64>(0xBFCBC286742D9000), reinterpret<f64>(0x3D194EB0318BB78F),\n reinterpret<f64>(0x3FF3C00000000000), 0, reinterpret<f64>(0xBFCAF3C94E80C000), reinterpret<f64>(0x3CBA4E633FCD9066),\n reinterpret<f64>(0x3FF3A00000000000), 0, reinterpret<f64>(0xBFCA23BC1FE2B000), reinterpret<f64>(0xBD258C64DC46C1EA),\n reinterpret<f64>(0x3FF3A00000000000), 0, reinterpret<f64>(0xBFCA23BC1FE2B000), reinterpret<f64>(0xBD258C64DC46C1EA),\n reinterpret<f64>(0x3FF3800000000000), 0, reinterpret<f64>(0xBFC9525A9CF45000), reinterpret<f64>(0xBD2AD1D904C1D4E3),\n reinterpret<f64>(0x3FF3600000000000), 0, reinterpret<f64>(0xBFC87FA06520D000), reinterpret<f64>(0x3D2BBDBF7FDBFA09),\n reinterpret<f64>(0x3FF3400000000000), 0, reinterpret<f64>(0xBFC7AB890210E000), reinterpret<f64>(0x3D2BDB9072534A58),\n reinterpret<f64>(0x3FF3400000000000), 0, reinterpret<f64>(0xBFC7AB890210E000), reinterpret<f64>(0x3D2BDB9072534A58),\n reinterpret<f64>(0x3FF3200000000000), 0, reinterpret<f64>(0xBFC6D60FE719D000), reinterpret<f64>(0xBD10E46AA3B2E266),\n reinterpret<f64>(0x3FF3000000000000), 0, reinterpret<f64>(0xBFC5FF3070A79000), reinterpret<f64>(0xBD1E9E439F105039),\n reinterpret<f64>(0x3FF3000000000000), 0, reinterpret<f64>(0xBFC5FF3070A79000), reinterpret<f64>(0xBD1E9E439F105039),\n reinterpret<f64>(0x3FF2E00000000000), 0, reinterpret<f64>(0xBFC526E5E3A1B000), reinterpret<f64>(0xBD20DE8B90075B8F),\n reinterpret<f64>(0x3FF2C00000000000), 0, reinterpret<f64>(0xBFC44D2B6CCB8000), reinterpret<f64>(0x3D170CC16135783C),\n reinterpret<f64>(0x3FF2C00000000000), 0, reinterpret<f64>(0xBFC44D2B6CCB8000), reinterpret<f64>(0x3D170CC16135783C),\n reinterpret<f64>(0x3FF2A00000000000), 0, reinterpret<f64>(0xBFC371FC201E9000), reinterpret<f64>(0x3CF178864D27543A),\n reinterpret<f64>(0x3FF2800000000000), 0, reinterpret<f64>(0xBFC29552F81FF000), reinterpret<f64>(0xBD248D301771C408),\n reinterpret<f64>(0x3FF2600000000000), 0, reinterpret<f64>(0xBFC1B72AD52F6000), reinterpret<f64>(0xBD2E80A41811A396),\n reinterpret<f64>(0x3FF2600000000000), 0, reinterpret<f64>(0xBFC1B72AD52F6000), reinterpret<f64>(0xBD2E80A41811A396),\n reinterpret<f64>(0x3FF2400000000000), 0, reinterpret<f64>(0xBFC0D77E7CD09000), reinterpret<f64>(0x3D0A699688E85BF4),\n reinterpret<f64>(0x3FF2400000000000), 0, reinterpret<f64>(0xBFC0D77E7CD09000), reinterpret<f64>(0x3D0A699688E85BF4),\n reinterpret<f64>(0x3FF2200000000000), 0, reinterpret<f64>(0xBFBFEC9131DBE000), reinterpret<f64>(0xBD2575545CA333F2),\n reinterpret<f64>(0x3FF2000000000000), 0, reinterpret<f64>(0xBFBE27076E2B0000), reinterpret<f64>(0x3D2A342C2AF0003C),\n reinterpret<f64>(0x3FF2000000000000), 0, reinterpret<f64>(0xBFBE27076E2B0000), reinterpret<f64>(0x3D2A342C2AF0003C),\n reinterpret<f64>(0x3FF1E00000000000), 0, reinterpret<f64>(0xBFBC5E548F5BC000), reinterpret<f64>(0xBD1D0C57585FBE06),\n reinterpret<f64>(0x3FF1C00000000000), 0, reinterpret<f64>(0xBFBA926D3A4AE000), reinterpret<f64>(0x3D253935E85BAAC8),\n reinterpret<f64>(0x3FF1C00000000000), 0, reinterpret<f64>(0xBFBA926D3A4AE000), reinterpret<f64>(0x3D253935E85BAAC8),\n reinterpret<f64>(0x3FF1A00000000000), 0, reinterpret<f64>(0xBFB8C345D631A000), reinterpret<f64>(0x3D137C294D2F5668),\n reinterpret<f64>(0x3FF1A00000000000), 0, reinterpret<f64>(0xBFB8C345D631A000), reinterpret<f64>(0x3D137C294D2F5668),\n reinterpret<f64>(0x3FF1800000000000), 0, reinterpret<f64>(0xBFB6F0D28AE56000), reinterpret<f64>(0xBD269737C93373DA),\n reinterpret<f64>(0x3FF1600000000000), 0, reinterpret<f64>(0xBFB51B073F062000), reinterpret<f64>(0x3D1F025B61C65E57),\n reinterpret<f64>(0x3FF1600000000000), 0, reinterpret<f64>(0xBFB51B073F062000), reinterpret<f64>(0x3D1F025B61C65E57),\n reinterpret<f64>(0x3FF1400000000000), 0, reinterpret<f64>(0xBFB341D7961BE000), reinterpret<f64>(0x3D2C5EDACCF913DF),\n reinterpret<f64>(0x3FF1400000000000), 0, reinterpret<f64>(0xBFB341D7961BE000), reinterpret<f64>(0x3D2C5EDACCF913DF),\n reinterpret<f64>(0x3FF1200000000000), 0, reinterpret<f64>(0xBFB16536EEA38000), reinterpret<f64>(0x3D147C5E768FA309),\n reinterpret<f64>(0x3FF1000000000000), 0, reinterpret<f64>(0xBFAF0A30C0118000), reinterpret<f64>(0x3D2D599E83368E91),\n reinterpret<f64>(0x3FF1000000000000), 0, reinterpret<f64>(0xBFAF0A30C0118000), reinterpret<f64>(0x3D2D599E83368E91),\n reinterpret<f64>(0x3FF0E00000000000), 0, reinterpret<f64>(0xBFAB42DD71198000), reinterpret<f64>(0x3D1C827AE5D6704C),\n reinterpret<f64>(0x3FF0E00000000000), 0, reinterpret<f64>(0xBFAB42DD71198000), reinterpret<f64>(0x3D1C827AE5D6704C),\n reinterpret<f64>(0x3FF0C00000000000), 0, reinterpret<f64>(0xBFA77458F632C000), reinterpret<f64>(0xBD2CFC4634F2A1EE),\n reinterpret<f64>(0x3FF0C00000000000), 0, reinterpret<f64>(0xBFA77458F632C000), reinterpret<f64>(0xBD2CFC4634F2A1EE),\n reinterpret<f64>(0x3FF0A00000000000), 0, reinterpret<f64>(0xBFA39E87B9FEC000), reinterpret<f64>(0x3CF502B7F526FEAA),\n reinterpret<f64>(0x3FF0A00000000000), 0, reinterpret<f64>(0xBFA39E87B9FEC000), reinterpret<f64>(0x3CF502B7F526FEAA),\n reinterpret<f64>(0x3FF0800000000000), 0, reinterpret<f64>(0xBF9F829B0E780000), reinterpret<f64>(0xBD2980267C7E09E4),\n reinterpret<f64>(0x3FF0800000000000), 0, reinterpret<f64>(0xBF9F829B0E780000), reinterpret<f64>(0xBD2980267C7E09E4),\n reinterpret<f64>(0x3FF0600000000000), 0, reinterpret<f64>(0xBF97B91B07D58000), reinterpret<f64>(0xBD288D5493FAA639),\n reinterpret<f64>(0x3FF0400000000000), 0, reinterpret<f64>(0xBF8FC0A8B0FC0000), reinterpret<f64>(0xBCDF1E7CF6D3A69C),\n reinterpret<f64>(0x3FF0400000000000), 0, reinterpret<f64>(0xBF8FC0A8B0FC0000), reinterpret<f64>(0xBCDF1E7CF6D3A69C),\n reinterpret<f64>(0x3FF0200000000000), 0, reinterpret<f64>(0xBF7FE02A6B100000), reinterpret<f64>(0xBD19E23F0DDA40E4),\n reinterpret<f64>(0x3FF0200000000000), 0, reinterpret<f64>(0xBF7FE02A6B100000), reinterpret<f64>(0xBD19E23F0DDA40E4),\n reinterpret<f64>(0x3FF0000000000000), 0, 0, 0,\n reinterpret<f64>(0x3FF0000000000000), 0, 0, 0,\n reinterpret<f64>(0x3FEFC00000000000), 0, reinterpret<f64>(0x3F80101575890000), reinterpret<f64>(0xBD10C76B999D2BE8),\n reinterpret<f64>(0x3FEF800000000000), 0, reinterpret<f64>(0x3F90205658938000), reinterpret<f64>(0xBD23DC5B06E2F7D2),\n reinterpret<f64>(0x3FEF400000000000), 0, reinterpret<f64>(0x3F98492528C90000), reinterpret<f64>(0xBD2AA0BA325A0C34),\n reinterpret<f64>(0x3FEF000000000000), 0, reinterpret<f64>(0x3FA0415D89E74000), reinterpret<f64>(0x3D0111C05CF1D753),\n reinterpret<f64>(0x3FEEC00000000000), 0, reinterpret<f64>(0x3FA466AED42E0000), reinterpret<f64>(0xBD2C167375BDFD28),\n reinterpret<f64>(0x3FEE800000000000), 0, reinterpret<f64>(0x3FA894AA149FC000), reinterpret<f64>(0xBD197995D05A267D),\n reinterpret<f64>(0x3FEE400000000000), 0, reinterpret<f64>(0x3FACCB73CDDDC000), reinterpret<f64>(0xBD1A68F247D82807),\n reinterpret<f64>(0x3FEE200000000000), 0, reinterpret<f64>(0x3FAEEA31C006C000), reinterpret<f64>(0xBD0E113E4FC93B7B),\n reinterpret<f64>(0x3FEDE00000000000), 0, reinterpret<f64>(0x3FB1973BD1466000), reinterpret<f64>(0xBD25325D560D9E9B),\n reinterpret<f64>(0x3FEDA00000000000), 0, reinterpret<f64>(0x3FB3BDF5A7D1E000), reinterpret<f64>(0x3D2CC85EA5DB4ED7),\n reinterpret<f64>(0x3FED600000000000), 0, reinterpret<f64>(0x3FB5E95A4D97A000), reinterpret<f64>(0xBD2C69063C5D1D1E),\n reinterpret<f64>(0x3FED400000000000), 0, reinterpret<f64>(0x3FB700D30AEAC000), reinterpret<f64>(0x3CEC1E8DA99DED32),\n reinterpret<f64>(0x3FED000000000000), 0, reinterpret<f64>(0x3FB9335E5D594000), reinterpret<f64>(0x3D23115C3ABD47DA),\n reinterpret<f64>(0x3FECC00000000000), 0, reinterpret<f64>(0x3FBB6AC88DAD6000), reinterpret<f64>(0xBD1390802BF768E5),\n reinterpret<f64>(0x3FECA00000000000), 0, reinterpret<f64>(0x3FBC885801BC4000), reinterpret<f64>(0x3D2646D1C65AACD3),\n reinterpret<f64>(0x3FEC600000000000), 0, reinterpret<f64>(0x3FBEC739830A2000), reinterpret<f64>(0xBD2DC068AFE645E0),\n reinterpret<f64>(0x3FEC400000000000), 0, reinterpret<f64>(0x3FBFE89139DBE000), reinterpret<f64>(0xBD2534D64FA10AFD),\n reinterpret<f64>(0x3FEC000000000000), 0, reinterpret<f64>(0x3FC1178E8227E000), reinterpret<f64>(0x3D21EF78CE2D07F2),\n reinterpret<f64>(0x3FEBE00000000000), 0, reinterpret<f64>(0x3FC1AA2B7E23F000), reinterpret<f64>(0x3D2CA78E44389934),\n reinterpret<f64>(0x3FEBA00000000000), 0, reinterpret<f64>(0x3FC2D1610C868000), reinterpret<f64>(0x3D039D6CCB81B4A1),\n reinterpret<f64>(0x3FEB800000000000), 0, reinterpret<f64>(0x3FC365FCB0159000), reinterpret<f64>(0x3CC62FA8234B7289),\n reinterpret<f64>(0x3FEB400000000000), 0, reinterpret<f64>(0x3FC4913D8333B000), reinterpret<f64>(0x3D25837954FDB678),\n reinterpret<f64>(0x3FEB200000000000), 0, reinterpret<f64>(0x3FC527E5E4A1B000), reinterpret<f64>(0x3D2633E8E5697DC7),\n reinterpret<f64>(0x3FEAE00000000000), 0, reinterpret<f64>(0x3FC6574EBE8C1000), reinterpret<f64>(0x3D19CF8B2C3C2E78),\n reinterpret<f64>(0x3FEAC00000000000), 0, reinterpret<f64>(0x3FC6F0128B757000), reinterpret<f64>(0xBD25118DE59C21E1),\n reinterpret<f64>(0x3FEAA00000000000), 0, reinterpret<f64>(0x3FC7898D85445000), reinterpret<f64>(0xBD1C661070914305),\n reinterpret<f64>(0x3FEA600000000000), 0, reinterpret<f64>(0x3FC8BEAFEB390000), reinterpret<f64>(0xBD073D54AAE92CD1),\n reinterpret<f64>(0x3FEA400000000000), 0, reinterpret<f64>(0x3FC95A5ADCF70000), reinterpret<f64>(0x3D07F22858A0FF6F),\n reinterpret<f64>(0x3FEA000000000000), 0, reinterpret<f64>(0x3FCA93ED3C8AE000), reinterpret<f64>(0xBD28724350562169),\n reinterpret<f64>(0x3FE9E00000000000), 0, reinterpret<f64>(0x3FCB31D8575BD000), reinterpret<f64>(0xBD0C358D4EACE1AA),\n reinterpret<f64>(0x3FE9C00000000000), 0, reinterpret<f64>(0x3FCBD087383BE000), reinterpret<f64>(0xBD2D4BC4595412B6),\n reinterpret<f64>(0x3FE9A00000000000), 0, reinterpret<f64>(0x3FCC6FFBC6F01000), reinterpret<f64>(0xBCF1EC72C5962BD2),\n reinterpret<f64>(0x3FE9600000000000), 0, reinterpret<f64>(0x3FCDB13DB0D49000), reinterpret<f64>(0xBD2AFF2AF715B035),\n reinterpret<f64>(0x3FE9400000000000), 0, reinterpret<f64>(0x3FCE530EFFE71000), reinterpret<f64>(0x3CC212276041F430),\n reinterpret<f64>(0x3FE9200000000000), 0, reinterpret<f64>(0x3FCEF5ADE4DD0000), reinterpret<f64>(0xBCCA211565BB8E11),\n reinterpret<f64>(0x3FE9000000000000), 0, reinterpret<f64>(0x3FCF991C6CB3B000), reinterpret<f64>(0x3D1BCBECCA0CDF30),\n reinterpret<f64>(0x3FE8C00000000000), 0, reinterpret<f64>(0x3FD07138604D5800), reinterpret<f64>(0x3CF89CDB16ED4E91),\n reinterpret<f64>(0x3FE8A00000000000), 0, reinterpret<f64>(0x3FD0C42D67616000), reinterpret<f64>(0x3D27188B163CEAE9),\n reinterpret<f64>(0x3FE8800000000000), 0, reinterpret<f64>(0x3FD1178E8227E800), reinterpret<f64>(0xBD2C210E63A5F01C),\n reinterpret<f64>(0x3FE8600000000000), 0, reinterpret<f64>(0x3FD16B5CCBACF800), reinterpret<f64>(0x3D2B9ACDF7A51681),\n reinterpret<f64>(0x3FE8400000000000), 0, reinterpret<f64>(0x3FD1BF99635A6800), reinterpret<f64>(0x3D2CA6ED5147BDB7),\n reinterpret<f64>(0x3FE8200000000000), 0, reinterpret<f64>(0x3FD214456D0EB800), reinterpret<f64>(0x3D0A87DEBA46BAEA),\n reinterpret<f64>(0x3FE7E00000000000), 0, reinterpret<f64>(0x3FD2BEF07CDC9000), reinterpret<f64>(0x3D2A9CFA4A5004F4),\n reinterpret<f64>(0x3FE7C00000000000), 0, reinterpret<f64>(0x3FD314F1E1D36000), reinterpret<f64>(0xBD28E27AD3213CB8),\n reinterpret<f64>(0x3FE7A00000000000), 0, reinterpret<f64>(0x3FD36B6776BE1000), reinterpret<f64>(0x3D116ECDB0F177C8),\n reinterpret<f64>(0x3FE7800000000000), 0, reinterpret<f64>(0x3FD3C25277333000), reinterpret<f64>(0x3D183B54B606BD5C),\n reinterpret<f64>(0x3FE7600000000000), 0, reinterpret<f64>(0x3FD419B423D5E800), reinterpret<f64>(0x3D08E436EC90E09D),\n reinterpret<f64>(0x3FE7400000000000), 0, reinterpret<f64>(0x3FD4718DC271C800), reinterpret<f64>(0xBD2F27CE0967D675),\n reinterpret<f64>(0x3FE7200000000000), 0, reinterpret<f64>(0x3FD4C9E09E173000), reinterpret<f64>(0xBD2E20891B0AD8A4),\n reinterpret<f64>(0x3FE7000000000000), 0, reinterpret<f64>(0x3FD522AE0738A000), reinterpret<f64>(0x3D2EBE708164C759),\n reinterpret<f64>(0x3FE6E00000000000), 0, reinterpret<f64>(0x3FD57BF753C8D000), reinterpret<f64>(0x3D1FADEDEE5D40EF),\n reinterpret<f64>(0x3FE6C00000000000), 0, reinterpret<f64>(0x3FD5D5BDDF596000), reinterpret<f64>(0xBD0A0B2A08A465DC)\n];\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkint(iy: u64): i32 {\n var e = iy >> 52 & 0x7FF;\n if (e < 0x3FF ) return 0;\n if (e > 0x3FF + 52) return 2;\n e = u64(1) << (0x3FF + 52 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflow(sign: u32, y: f64): f64 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflow(sign: u32): f64 {\n return xflow(sign, reinterpret<f64>(0x1000000000000000)); // 0x1p-767\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflow(sign: u32): f64 {\n return xflow(sign, reinterpret<f64>(0x7000000000000000)); // 0x1p769\n}\n\n// Returns 1 if input is the bit representation of 0, infinity or nan.\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnan(u: u64): bool {\n return (u << 1) - 1 >= 0xFFE0000000000000 - 1;\n}\n\n// @ts-ignore: decorator\n@lazy\nvar log_tail: f64 = 0;\n\n// Compute y+TAIL = log(x) where the rounded result is y and TAIL has about\n// additional 15 bits precision. IX is the bit representation of x, but\n// normalized in the subnormal range using the sign bit for the exponent.\n// @ts-ignore: decorator\n@inline\nfunction log_inline(ix: u64): f64 {\n const N = 1 << POW_LOG_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n Ln2hi = reinterpret<f64>(0x3FE62E42FEFA3800),\n Ln2lo = reinterpret<f64>(0x3D2EF35793C76730);\n\n const\n A0 = reinterpret<f64>(0xBFE0000000000000),\n A1 = reinterpret<f64>(0xBFE5555555555560),\n A2 = reinterpret<f64>(0x3FE0000000000006),\n A3 = reinterpret<f64>(0x3FE999999959554E),\n A4 = reinterpret<f64>(0xBFE555555529A47A),\n A5 = reinterpret<f64>(0xBFF2495B9B4845E9),\n A6 = reinterpret<f64>(0x3FF0002B8B263FC3);\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3fE6955500000000;\n var i = <usize>((tmp >> (52 - POW_LOG_TABLE_BITS)) & N_MASK);\n var k = <i64>tmp >> 52;\n var iz = ix - (tmp & u64(0xFFF) << 52);\n var z = reinterpret<f64>(iz);\n var kd = <f64>k;\n\n // log(x) = k*Ln2 + log(c) + log1p(z/c-1).\n var invc = load<f64>(changetype<usize>(POW_LOG_DATA_TAB) + (i << (2 + alignof<f64>())), 0 << alignof<f64>()); // tab[i].invc\n var logc = load<f64>(changetype<usize>(POW_LOG_DATA_TAB) + (i << (2 + alignof<f64>())), 2 << alignof<f64>()); // tab[i].logc\n var logctail = load<f64>(changetype<usize>(POW_LOG_DATA_TAB) + (i << (2 + alignof<f64>())), 3 << alignof<f64>()); // tab[i].logctail\n\n // Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and\n // |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.\n // Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|.\n var zhi = reinterpret<f64>((iz + u64(0x80000000)) & 0xFFFFFFFF00000000);\n var zlo = z - zhi;\n var rhi = zhi * invc - 1.0;\n var rlo = zlo * invc;\n var r = rhi + rlo;\n\n // k * Ln2 + log(c) + r.\n var t1 = kd * Ln2hi + logc;\n var t2 = t1 + r;\n var lo1 = kd * Ln2lo + logctail;\n var lo2 = t1 - t2 + r;\n\n // Evaluation is optimized assuming superscalar pipelined execution.\n var ar = A0 * r; // A[0] = -0.5\n var ar2 = r * ar;\n var ar3 = r * ar2;\n // k * Ln2 + log(c) + r + A[0] * r * r.\n var arhi = A0 * rhi;\n var arhi2 = rhi * arhi;\n var hi = t2 + arhi2;\n var lo3 = rlo * (ar + arhi);\n var lo4 = t2 - hi + arhi2;\n\n // p = log1p(r) - r - A[0] * r * r.\n var p = ar3 * (A1 + r * A2 + ar2 * (A3 + r * A4 + ar2 * (A5 + r * A6)));\n var lo = lo1 + lo2 + lo3 + lo4 + p;\n var y = hi + lo;\n log_tail = hi - y + lo;\n\n return y;\n}\n\n// @ts-ignore: decorator\n@inline\nconst SIGN_BIAS = 0x800 << EXP_TABLE_BITS;\n\n// Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.\n// The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1.\n// @ts-ignore: decorator\n@inline\nfunction exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 {\n const N = 1 << EXP_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret<f64>(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret<f64>(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret<f64>(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret<f64>(0x4338000000000000); // 0x1.8p52\n\n const\n C2 = reinterpret<f64>(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret<f64>(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret<f64>(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret<f64>(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n var abstop: u32;\n var ki: u64, top: u64, sbits: u64;\n var idx: usize;\n // double_t for better performance on targets with FLT_EVAL_METHOD==2.\n var kd: f64, z: f64, r: f64, r2: f64, scale: f64, tail: f64, tmp: f64;\n\n var ux = reinterpret<u64>(x);\n abstop = <u32>(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) {\n // Avoid spurious underflow for tiny x.\n // Note: 0 is common input.\n return select(-1.0, 1.0, sign_bias);\n }\n if (abstop >= 0x409) { // top12(1024.0)\n // Note: inf and nan are already handled.\n return ux >> 63 ? uflow(sign_bias) : oflow(sign_bias);\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].\n z = InvLn2N * x;\n\n// #if TOINT_INTRINSICS\n// kd = roundtoint(z);\n// ki = converttoint(z);\n// #elif EXP_USE_TOINT_NARROW\n// // z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n// kd = eval_as_double(z + shift);\n// ki = asuint64(kd) >> 16;\n// kd = (double_t)(int32_t)ki;\n// #else\n // z - kd is in [-1, 1] in non-nearest rounding modes\n kd = z + shift;\n ki = reinterpret<u64>(kd);\n kd -= shift;\n// #endif\n r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // The code assumes 2^-200 < |xtail| < 2^-8/N\n r += xtail;\n // 2^(k/N) ~= scale * (1 + tail)\n idx = <usize>((ki & N_MASK) << 1);\n top = (ki + sign_bias) << (52 - EXP_TABLE_BITS);\n\n tail = reinterpret<f64>(load<u64>(changetype<usize>(EXP_DATA_TAB) + (idx << alignof<u64>())));\n // This is only a valid scale when -1023*N < k < 1024*N\n sbits = load<u64>(changetype<usize>(EXP_DATA_TAB) + (idx << alignof<u64>()), 1 << alignof<u64>()) + top;\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp\n tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n scale = reinterpret<f64>(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function pow_lut(x: f64, y: f64): f64 {\n const Ox1p52 = reinterpret<f64>(0x4330000000000000); // 0x1p52\n\n var sign_bias: u32 = 0;\n var ix = reinterpret<u64>(x);\n var iy = reinterpret<u64>(y);\n var topx = ix >> 52;\n var topy = iy >> 52;\n\n if (topx - 0x001 >= 0x7FF - 0x001 || (topy & 0x7FF) - 0x3BE >= 0x43e - 0x3BE) {\n // Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0\n // and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.\n // Special cases: (x < 0x1p-126 or inf or nan) or\n // (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).\n if (zeroinfnan(iy)) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3FF0000000000000) return NaN; // original: 1.0\n if ((ix << 1) > 0xFFE0000000000000 || (iy << 1) > 0xFFE0000000000000) return x + y;\n if ((ix << 1) == 0x7FE0000000000000) return NaN; // original: 1.0\n if (((ix << 1) < 0x7FE0000000000000) == !(iy >> 63)) return 0; // |x|<1 && y==inf or |x|>1 && y==-inf.\n return y * y;\n }\n if (zeroinfnan(ix)) {\n let x2 = x * x;\n if (i32(ix >> 63) && checkint(iy) == 1) x2 = -x2;\n return iy >> 63 ? 1 / x2 : x2;\n }\n // Here x and y are non-zero finite\n if (ix >> 63) {\n // Finite x < 0\n let yint = checkint(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) sign_bias = SIGN_BIAS;\n ix &= 0x7FFFFFFFFFFFFFFF;\n topx &= 0x7FF;\n }\n if ((topy & 0x7FF) - 0x3BE >= 0x43E - 0x3BE) {\n // Note: sign_bias == 0 here because y is not odd.\n if (ix == 0x3FF0000000000000) return 1;\n if ((topy & 0x7FF) < 0x3BE) return 1; // |y| < 2^-65, x^y ~= 1 + y*log(x).\n return (ix > 0x3FF0000000000000) == (topy < 0x800) ? Infinity : 0;\n }\n if (topx == 0) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret<u64>(x * Ox1p52);\n ix &= 0x7FFFFFFFFFFFFFFF;\n ix -= u64(52) << 52;\n }\n }\n\n var hi = log_inline(ix);\n var lo = log_tail;\n var ehi: f64, elo: f64;\n// #if __FP_FAST_FMA\n// ehi = y * hi;\n// elo = y * lo + __builtin_fma(y, hi, -ehi);\n// #else\n var yhi = reinterpret<f64>(iy & 0xFFFFFFFFF8000000);\n var ylo = y - yhi;\n var lhi = reinterpret<f64>(reinterpret<u64>(hi) & 0xFFFFFFFFF8000000);\n var llo = hi - lhi + lo;\n ehi = yhi * lhi;\n elo = ylo * lhi + y * llo; // |elo| < |ehi| * 2^-25.\n// #endif\n return exp_inline(ehi, elo, sign_bias);\n}\n","import { itoa, dtoa, itoa_stream, dtoa_stream, MAX_DOUBLE_LENGTH } from \"./number\";\nimport { ipow32 } from \"../math\";\n\n// All tables are stored as two staged lookup tables (static tries)\n// because the full range of Unicode symbols can't be efficiently\n// represented as-is in memory (see Unicode spec ch 5, p.196):\n// https://www.unicode.org/versions/Unicode12.0.0/ch05.pdf\n// Tables have been generated using these forked musl tools:\n// https://github.com/MaxGraey/musl-chartable-tools/tree/case-ignorable\n\n// Lookup table to check if a character is alphanumeric or not\n// See: https://git.musl-libc.org/cgit/musl/tree/src/ctype/alpha.h\n// size: 3904 bytes\n// @ts-ignore\n@inline @lazy\nconst ALPHA_TABLE: StaticArray<u8> = [\n 18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,17,34,35,36,17,37,38,39,40,\n 41,42,43,44,17,45,46,47,16,16,48,16,16,16,16,16,16,16,49,50,51,16,52,53,16,16,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,54,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67,\n 68,69,70,71,72,73,74,17,75,76,77,78,79,80,81,16,82,83,84,85,86,87,88,89,90,91,\n 92,93,16,94,95,96,16,17,17,17,97,98,99,16,16,16,16,16,16,16,16,16,16,17,17,17,\n 17,100,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,101,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,17,17,102,103,16,16,104,105,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,106,17,17,107,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,\n 108,109,16,16,16,16,16,16,16,16,16,110,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,111,112,113,114,16,16,16,16,16,16,16,16,115,116,\n 117,16,16,16,16,16,118,119,16,16,16,16,120,16,16,121,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,\n 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254,\n 255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,188,64,215,255,255,\n 251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,127,2,255,255,255,\n 255,255,1,0,0,0,0,255,191,182,0,255,255,255,135,7,0,0,0,255,7,255,255,255,255,\n 255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239,\n 31,254,225,255,\n 159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255,\n 255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255,\n 1,255,7,0,0,0,0,0,0,255,255,223,63,0,0,240,255,248,3,255,255,255,255,255,255,\n 255,255,255,239,255,223,225,255,207,255,254,255,239,159,249,255,255,253,197,\n 227,159,89,128,176,207,255,3,16,238,135,249,255,255,253,109,195,135,25,2,94,\n 192,255,63,0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,30,238,159,\n 249,255,255,253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,255,\n 195,199,29,129,0,192,255,0,0,239,223,253,255,255,253,255,227,223,29,96,7,207,\n 255,0,0,239,223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,239,223,253,\n 255,255,255,255,231,223,93,240,128,207,255,0,252,236,255,127,252,255,255,251,\n 47,127,128,95,255,192,255,12,0,254,255,255,255,255,127,255,7,63,32,255,3,0,0,\n 0,0,214,247,255,255,175,255,255,59,95,32,255,243,0,0,0,\n 0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255,\n 31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,255,255,255,\n 255,255,255,255,63,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255,\n 255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61,\n 127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255,\n 7,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,63,63,254,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255,\n 255,199,255,1,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255,\n 255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255,\n 255,255,255,255,255,1,255,255,255,255,255,7,255,255,255,255,255,255,255,255,\n 63,\n 0,255,255,255,127,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255,\n 255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255,\n 127,254,255,31,0,255,3,255,3,128,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255,\n 255,191,255,3,0,255,255,255,255,255,255,127,0,255,227,255,255,255,255,255,63,\n 255,1,255,255,255,255,255,231,0,0,0,0,0,222,111,4,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,\n 128,255,31,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,255,\n 255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,\n 224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,\n 0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255,\n 255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127,\n 255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254,\n 255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,255,254,255,\n 255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,63,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,\n 0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255,\n 255,127,240,143,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,\n 0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,249,255,255,255,\n 255,255,255,124,0,0,0,0,0,128,255,191,255,255,255,255,0,0,0,255,255,255,255,\n 255,255,15,0,255,255,255,255,255,255,255,255,47,0,255,3,0,0,252,232,255,255,\n 255,255,255,7,255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,\n 255,0,128,255,3,255,255,255,127,255,255,255,255,255,255,127,0,255,63,255,3,\n 255,255,127,252,255,255,255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,\n 126,0,127,127,255,255,255,255,255,247,255,0,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255,255,\n 255,\n 15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255,255,255,\n 252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,223,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,255,3,\n 254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255,255,127,\n 252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0,\n 0,255,255,255,255,0,224,255,255,255,7,255,255,255,255,255,7,255,255,255,63,\n 255,255,255,255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,255,3,255,255,255,255,15,255,255,255,\n 255,15,255,255,255,255,255,0,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,255,255,63,0,255,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191,145,255,255,63,0,255,255,\n 127,0,255,255,255,127,0,0,0,0,0,0,0,0,255,255,55,0,255,255,63,0,255,255,255,3,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240,239,\n 254,255,255,63,0,0,0,0,0,255,255,255,31,255,255,255,31,0,0,0,0,255,254,255,\n 255,31,0,0,0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,255,255,3,\n 0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,255,255,255,255,255,255,7,\n 0,255,255,255,255,255,255,7,0,255,255,255,255,255,0,255,3,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,31,128,0,255,255,63,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,255,255,127,0,255,255,255,255,255,255,255,255,63,0,0,0,\n 192,255,0,0,252,255,255,255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,255,\n 255,255,255,199,255,112,0,255,255,255,255,71,0,255,255,255,255,255,255,255,\n 255,30,0,255,23,0,0,0,0,255,255,251,255,255,255,159,64,0,0,0,0,0,0,0,0,127,\n 189,255,191,255,1,255,255,255,255,255,255,255,1,255,3,239,159,249,255,255,253,\n 237,227,159,25,129,224,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 255,255,255,255,255,187,7,255,131,0,0,0,0,255,255,255,255,255,255,255,255,179,\n 0,255,3,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,63,127,0,0,0,63,0,0,\n 0,0,255,255,255,255,255,255,255,127,17,0,255,3,0,0,0,0,255,255,255,255,255,\n 255,63,1,255,3,0,0,0,0,0,0,255,255,255,231,255,7,255,3,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,255,3,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,252,255,255,255,255,255,252,26,0,0,0,255,255,255,255,255,255,231,\n 127,0,0,255,255,255,255,255,255,255,255,255,32,0,0,0,0,255,255,255,255,255,\n 255,255,1,255,253,255,255,255,255,127,127,1,0,255,3,0,0,252,255,255,255,252,\n 255,255,254,127,0,0,0,0,0,0,0,0,0,127,251,255,255,255,255,127,180,203,0,255,3,\n 191,253,255,255,255,127,123,1,255,3,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,127,0,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,\n 0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,127,0,\n 0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,\n 255,255,255,255,255,255,1,255,255,255,127,255,3,0,0,0,0,0,0,0,0,0,0,0,0,255,\n 255,255,63,0,0,255,255,255,255,255,255,0,0,15,0,255,3,248,255,255,224,255,255,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,255,255,255,255,135,255,255,255,255,255,255,255,128,\n 255,255,0,0,0,0,0,0,0,0,11,0,0,0,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,7,0,255,255,255,127,0,0,0,0,0,\n 0,7,0,240,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,7,255,31,255,1,255,67,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,\n 255,223,100,222,255,235,239,255,255,255,255,255,255,\n 255,191,231,223,223,255,255,255,123,95,252,253,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,\n 253,255,255,247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,\n 255,255,127,255,255,255,253,255,255,255,253,255,255,247,207,255,255,255,255,\n 255,255,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,31,128,63,255,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,\n 15,255,3,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,31,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,\n 143,8,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,239,255,255,255,150,254,247,10,132,234,150,170,150,247,247,94,255,251,255,\n 15,238,251,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,\n 255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n];\n\n// size: 1568 bytes (compressed to ~1380 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline\nconst CASED: StaticArray<u8> = [\n 18,19,20,21,22,23,16,16,16,16,16,16,16,16,16,16,\n 24,16,16,25,16,16,16,16,16,16,16,16,26,27,17,28,\n 29,30,16,16,31,16,16,16,16,16,16,16,32,33,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,34,35,16,16,16,36,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,37,16,16,16,38,\n 16,16,16,16,39,16,16,16,16,16,16,16,40,16,16,16,\n 16,16,16,16,16,16,16,16,41,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,42,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,43,44,45,46,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,47,16,16,16,16,16,16,\n 16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,0,0,0,0,0,4,32,4,\n 255,255,127,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,247,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,239,255,255,255,255,1,3,0,0,0,31,0,0,0,\n 0,0,0,0,0,0,0,0,32,0,0,0,0,0,207,188,64,215,255,255,251,255,255,255,\n 255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 3,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,255,\n 255,255,127,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 191,32,255,255,255,255,255,231,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,255,255,255,255,255,255,63,63,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,1,255,255,255,255,255,231,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,\n 255,255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,\n 132,252,47,62,80,189,31,242,224,67,0,0,255,255,255,255,24,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,0,255,255,255,255,255,127,255,255,\n 255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,120,12,0,\n 255,255,255,255,191,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,63,0,0,\n 255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,255,255,\n 255,255,255,255,255,255,255,255,255,120,255,255,255,255,255,255,124,0,0,0,0,0,0,7,\n 0,0,0,0,0,0,255,255,255,255,255,247,255,0,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,127,0,248,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,7,\n 254,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,15,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,7,0,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,\n 255,255,255,223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,255,123,\n 95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,\n 253,255,255,247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,\n 255,253,255,255,255,253,255,255,247,15,0,0,0,0,0,0,255,255,255,255,255,255,255,255,\n 15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0\n];\n\n// size: 2976 bytes (compressed to ~2050 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline\nconst CASE_IGNORABLES: StaticArray<u8> = [\n 18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,\n 33,16,16,34,16,16,16,35,36,37,38,39,40,41,16,42,\n 43,16,16,16,16,16,16,16,16,16,16,16,44,45,46,16,\n 47,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 48,16,16,16,49,16,50,51,52,53,54,55,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,56,16,16,57,58,\n 16,59,60,61,16,16,16,16,16,16,62,16,16,63,16,64,\n 65,66,67,68,69,70,71,72,73,74,75,16,76,77,78,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,79,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,80,81,16,16,16,82,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,83,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,84,85,16,16,16,16,16,16,16,86,16,16,16,16,16,\n 87,88,89,16,16,16,16,16,90,91,16,16,16,16,16,16,\n 16,16,16,92,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,128,64,0,4,0,0,0,64,1,0,0,0,0,0,0,0,0,161,144,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,48,4,176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,\n 0,0,254,255,255,255,255,191,182,0,0,0,0,0,16,0,63,0,255,23,0,0,0,0,\n 1,248,255,255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,255,61,0,0,\n 0,128,2,0,0,0,255,255,255,7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,\n 0,0,0,0,0,248,63,36,0,0,192,255,255,63,0,0,0,0,0,14,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,248,255,255,255,255,255,7,0,0,0,0,0,0,20,\n 254,33,254,0,12,0,2,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0,64,\n 6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,\n 190,33,0,0,12,0,0,252,2,0,0,0,0,0,0,144,30,32,64,0,12,0,0,0,\n 4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,17,0,0,0,0,0,0,192,\n 193,61,96,0,12,0,0,0,2,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,\n 3,0,0,0,0,0,0,24,30,32,0,0,12,0,0,0,0,0,0,0,0,0,0,0,\n 0,4,92,0,0,0,0,0,0,0,0,0,0,0,242,7,192,127,0,0,0,0,0,0,\n 0,0,0,0,0,0,242,31,64,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,\n 0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,\n 0,0,0,0,0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,\n 0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,\n 0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,143,32,0,0,0,0,\n 0,120,0,0,0,0,0,0,8,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,\n 0,0,64,127,229,31,248,159,0,0,0,0,128,0,255,127,0,0,0,0,0,0,0,0,\n 15,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,\n 0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,0,0,0,63,\n 0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,240,255,255,\n 255,255,255,255,255,7,0,1,0,0,0,248,255,255,255,255,255,255,255,255,255,255,255,251,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,\n 3,224,0,224,0,224,0,96,0,248,0,3,144,124,0,0,0,0,0,0,223,255,2,128,\n 0,0,255,31,0,0,0,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,128,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,60,62,8,\n 0,0,0,0,0,0,0,0,0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,112,\n 0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,0,16,0,0,0,0,0,0,\n 0,0,0,0,0,128,247,191,0,0,0,240,0,0,0,0,0,0,0,0,0,0,3,0,\n 255,255,255,255,3,0,0,0,0,0,0,0,0,0,1,0,0,7,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,3,68,8,0,0,96,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,\n 128,255,3,0,0,0,0,0,7,0,0,0,0,0,200,51,0,128,0,0,96,0,0,0,\n 0,0,0,0,0,126,102,0,8,16,0,0,0,0,1,16,0,0,0,0,0,0,157,193,\n 2,0,0,32,0,48,88,0,0,0,0,0,0,0,0,0,0,0,0,248,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,\n 255,255,8,0,255,255,0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,128,128,64,0,4,0,0,0,64,1,0,0,0,0,0,1,0,\n 0,0,0,192,0,0,0,0,0,0,0,0,8,0,0,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110,240,0,0,0,0,0,135,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,\n 0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,1,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,\n 127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,0,32,0,0,0,0,0,0,\n 7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,3,0,0,0,0,0,192,127,\n 0,30,0,0,0,0,0,0,0,0,0,0,0,128,211,64,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0,0,0,24,\n 1,0,0,0,192,31,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,0,0,0,0,0,0,248,133,\n 13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,0,0,0,0,0,0,248,167,\n 1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,\n 0,0,0,224,188,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,6,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,12,1,0,0,0,\n 254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,0,252,127,3,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,0,0,0,0,0,0,0,0,\n 0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126,180,\n 191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,1,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,\n 0,0,0,0,0,0,127,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,\n 0,128,255,255,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,96,15,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,248,\n 255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,0,0,0,0,0,0,0,0,\n 127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,63,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,240,15,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248\n];\n\n// @ts-ignore: decorator\n@lazy @inline\nconst LOWER127: StaticArray<u8> = [\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 91,92,93,94,95,96,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 123,124,125,126,127\n];\n\n// @ts-ignore: decorator\n@lazy @inline\nconst UPPER127: StaticArray<u8> = [\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 91,92,93,94,95,96,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 123,124,125,126,127\n];\n\n// 23 * 8 = 184 bytes\n// @ts-ignore: decorator\n@lazy @inline\nconst POWERS10: StaticArray<f64> = [\n 1e00, 1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09,\n 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,\n 1e20, 1e21, 1e22\n];\n\n// @ts-ignore: decorator\n@inline\nexport const enum CharCode {\n PLUS = 0x2B,\n MINUS = 0x2D,\n DOT = 0x2E,\n _0 = 0x30,\n _1 = 0x31,\n _2 = 0x32,\n _3 = 0x33,\n _4 = 0x34,\n _5 = 0x35,\n _6 = 0x36,\n _7 = 0x37,\n _8 = 0x38,\n _9 = 0x39,\n A = 0x41,\n B = 0x42,\n E = 0x45,\n I = 0x49,\n N = 0x4E,\n O = 0x4F,\n X = 0x58,\n Z = 0x5A,\n a = 0x61,\n b = 0x62,\n e = 0x65,\n n = 0x6E,\n o = 0x6F,\n x = 0x78,\n z = 0x7A\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isAscii(c: u32): bool {\n return !(c >> 7);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isLower8(c: u32): bool {\n return c - CharCode.a < 26;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isUpper8(c: u32): bool {\n return c - CharCode.A < 26;\n}\n\nexport function isSpace(c: u32): bool {\n if (c < 0x1680) { // < <LS> (1)\n // <SP>, <TAB>, <LF>, <VT>, <FF>, <CR> and <NBSP>\n // (c == 0x20 || c == 0xA0) was optimized to (c | 0x80) == 0xA0\n // @ts-ignore: cast\n return ((c | 0x80) == 0xA0) | (c - 0x09 <= 0x0D - 0x09);\n }\n if (c - 0x2000 <= 0x200A - 0x2000) return true;\n switch (c) {\n case 0x1680: // <LS> (1)\n case 0x2028: // <LS> (2)\n case 0x2029: // <PS>\n case 0x202F: // <NNS>\n case 0x205F: // <MMSP>\n case 0x3000: // <IS>\n case 0xFEFF: return true; // <ZWNBSP>\n }\n return false;\n}\n\nexport function isAlpha(c: u32): bool {\n if (isAscii(c)) return (c | 32) - CharCode.a < 26;\n if (c < 0x20000) {\n // @ts-ignore: cast\n return stagedBinaryLookup(changetype<usize>(ALPHA_TABLE), c);\n }\n return c < 0x2FFFE;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCased(c: u32): bool {\n // @ts-ignore: cast\n return c < 0x1F18A && stagedBinaryLookup(changetype<usize>(CASED), c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCaseIgnorable(c: u32): bool {\n // @ts-ignore: cast\n return c < 0xE01F0 && stagedBinaryLookup(changetype<usize>(CASE_IGNORABLES), c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isFinalSigma(buffer: usize, index: i32, len: i32): bool {\n const lookaheadLimit = 30; // max lookahead limit\n var found = false;\n var pos = index;\n var minPos = max(0, pos - lookaheadLimit);\n while (pos > minPos) {\n let c = codePointBefore(buffer, pos);\n if (!isCaseIgnorable(c)) {\n if (isCased(c)) {\n found = true;\n } else {\n return false;\n }\n }\n pos -= i32(c >= 0x10000) + 1;\n }\n if (!found) return false;\n pos = index + 1;\n var maxPos = min(pos + lookaheadLimit, len);\n while (pos < maxPos) {\n let c = <u32>load<u16>(buffer + (<usize>pos << 1));\n if (u32((c & 0xFC00) == 0xD800) & u32(pos + 1 != len)) {\n let c1 = <u32>load<u16>(buffer + (<usize>pos << 1), 2);\n if ((c1 & 0xFC00) == 0xDC00) {\n c = (c - 0xD800 << 10) + (c1 - 0xDC00) + 0x10000;\n }\n }\n if (!isCaseIgnorable(c)) {\n return !isCased(c);\n }\n pos += i32(c >= 0x10000) + 1;\n }\n return true;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction codePointBefore(buffer: usize, index: i32): i32 {\n if (index <= 0) return -1;\n var c = <u32>load<u16>(buffer + (<usize>index - 1 << 1));\n if (u32((c & 0xFC00) == 0xDC00) & u32(index - 2 >= 0)) {\n let c1 = <u32>load<u16>(buffer + (<usize>index - 2 << 1));\n if ((c1 & 0xFC00) == 0xD800) {\n return ((c1 & 0x3FF) << 10) + (c & 0x3FF) + 0x10000;\n }\n }\n return (c & 0xF800) == 0xD800 ? 0xFFFD : c;\n}\n\n// Search routine for two-staged lookup tables\nfunction stagedBinaryLookup(table: usize, c: u32): bool {\n return <bool>((load<u8>(table + (<u32>load<u8>(table + (c >>> 8)) << 5) + ((c & 255) >> 3)) >>> (c & 7)) & 1);\n}\n\nexport function compareImpl(str1: string, index1: usize, str2: string, index2: usize, len: usize): i32 {\n var ptr1 = changetype<usize>(str1) + (index1 << 1);\n var ptr2 = changetype<usize>(str2) + (index2 << 1);\n if (ASC_SHRINK_LEVEL < 2) {\n if (len >= 4 && !((ptr1 & 7) | (ptr2 & 7))) {\n do {\n if (load<u64>(ptr1) != load<u64>(ptr2)) break;\n ptr1 += 8;\n ptr2 += 8;\n len -= 4;\n } while (len >= 4);\n }\n }\n while (len--) {\n let a = <i32>load<u16>(ptr1);\n let b = <i32>load<u16>(ptr2);\n if (a != b) return a - b;\n ptr1 += 2;\n ptr2 += 2;\n }\n return 0;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toLower8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c | u32(isUpper8(c)) << 5;\n } else {\n return <u32>load<u8>(changetype<usize>(LOWER127) + c);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toUpper8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c & ~(u32(isLower8(c)) << 5);\n } else {\n return <u32>load<u8>(changetype<usize>(UPPER127) + c);\n }\n}\n\n/** Parses a string to an integer (usually), using the specified radix. */\nexport function strtol<T>(str: string, radix: i32 = 0): T {\n var len = str.length;\n if (!len) {\n // @ts-ignore: cast\n if (isFloat<T>()) return <T>NaN;\n // @ts-ignore: cast\n return <T>0;\n }\n\n var ptr = changetype<usize>(str) /* + HEAD -> offset */;\n var code = <u32>load<u16>(ptr);\n\n // determine sign\n // @ts-ignore: cast\n var sign: T = 1;\n // trim white spaces\n while (isSpace(code)) {\n code = <u32>load<u16>(ptr += 2);\n --len;\n }\n if (code == CharCode.MINUS) {\n if (!--len) {\n // @ts-ignore: cast\n if (isFloat<T>()) return <T>NaN;\n // @ts-ignore: cast\n return <T>0;\n }\n code = <u32>load<u16>(ptr += 2);\n // @ts-ignore: type\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) {\n // @ts-ignore: cast\n if (isFloat<T>()) return <T>NaN;\n // @ts-ignore: cast\n return <T>0;\n }\n code = <u32>load<u16>(ptr += 2);\n }\n\n // determine radix\n if (!radix) {\n if (code == CharCode._0 && len > 2) {\n switch (<u32>load<u16>(ptr + 2) | 32) {\n case CharCode.b: {\n ptr += 4; len -= 2;\n radix = 2;\n break;\n }\n case CharCode.o: {\n ptr += 4; len -= 2;\n radix = 8;\n break;\n }\n case CharCode.x: {\n ptr += 4; len -= 2;\n radix = 16;\n break;\n }\n default: radix = 10;\n }\n } else radix = 10;\n } else if (radix < 2 || radix > 36) {\n // @ts-ignore: cast\n if (isFloat<T>()) return <T>NaN;\n // @ts-ignore: cast\n return <T>0;\n }\n\n // calculate value\n // @ts-ignore: type\n var num: T = 0;\n while (len--) {\n code = <u32>load<u16>(ptr);\n if (code - CharCode._0 < 10) {\n code -= CharCode._0;\n } else if (code - CharCode.A <= <u32>(CharCode.Z - CharCode.A)) {\n code -= CharCode.A - 10;\n } else if (code - CharCode.a <= <u32>(CharCode.z - CharCode.a)) {\n code -= CharCode.a - 10;\n } else break;\n if (code >= <u32>radix) break;\n // @ts-ignore: type\n num = num * radix + code;\n ptr += 2;\n }\n // @ts-ignore: type\n return sign * num;\n}\n\nexport function strtod(str: string): f64 {\n var len = str.length;\n if (!len) return NaN;\n\n var ptr = changetype<usize>(str);\n var code = <u32>load<u16>(ptr);\n\n var sign = 1.;\n // skip white spaces\n while (len && isSpace(code)) {\n code = <u32>load<u16>(ptr += 2);\n --len;\n }\n if (!len) return NaN;\n\n // try parse '-' or '+'\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = <u32>load<u16>(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = <u32>load<u16>(ptr += 2);\n }\n\n // try parse Infinity\n if (len >= 8 && code == CharCode.I) {\n if (\n load<u64>(ptr, 0) == 0x690066006E0049 && // ifnI\n load<u64>(ptr, 8) == 0x7900740069006E // ytin\n ) {\n return copysign<f64>(Infinity, sign);\n }\n return NaN;\n }\n // validate next symbol\n if (code != CharCode.DOT && <u32>(code - CharCode._0) >= 10) {\n return NaN;\n }\n var savedPtr = ptr;\n // skip zeros\n while (code == CharCode._0) {\n code = <u32>load<u16>(ptr += 2);\n --len;\n }\n if (len <= 0) return 0;\n const capacity = 19; // int(64 * 0.3010)\n var pointed = false;\n var consumed = 0;\n var position = 0;\n var x: u64 = 0;\n if (code == CharCode.DOT) {\n let noDigits = !(savedPtr - ptr);\n ptr += 2; --len;\n if (!len && noDigits) return NaN;\n for (pointed = true; (code = <u32>load<u16>(ptr)) == CharCode._0; --position, ptr += 2) --len;\n if (len <= 0) return 0;\n if (!position && noDigits && code - CharCode._0 >= 10) return NaN;\n }\n for (let digit = code - CharCode._0; digit < 10 || (code == CharCode.DOT && !pointed); digit = code - CharCode._0) {\n if (digit < 10) {\n x = consumed < capacity ? 10 * x + digit : x | u64(!!digit);\n ++consumed;\n } else {\n position = consumed;\n pointed = true;\n }\n if (!--len) break;\n code = <u32>load<u16>(ptr += 2);\n }\n\n if (!pointed) position = consumed;\n return copysign<f64>(scientific(x, position - min(capacity, consumed) + parseExp(ptr, len)), sign);\n}\n\nexport function joinBooleanArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) return select(\"true\", \"false\", load<bool>(dataStart));\n\n var sepLen = separator.length;\n var valueLen = 5; // max possible length of element len(\"false\")\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype<string>(__alloc(estLen << 1, idof<string>())); // retains\n var offset = 0;\n var value: bool;\n for (let i = 0; i < lastIndex; ++i) {\n value = load<bool>(dataStart + i);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype<usize>(result) + (<usize>offset << 1),\n changetype<usize>(select(\"true\", \"false\", value)),\n <usize>valueLen << 1\n );\n offset += valueLen;\n if (sepLen) {\n memory.copy(\n changetype<usize>(result) + (<usize>offset << 1),\n changetype<usize>(separator),\n <usize>sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load<bool>(dataStart + <usize>lastIndex);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype<usize>(result) + (<usize>offset << 1),\n changetype<usize>(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinIntegerArray<T>(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n // @ts-ignore: type\n if (!lastIndex) return changetype<string>(itoa<T>(load<T>(dataStart))); // retains\n\n var sepLen = separator.length;\n const valueLen = (sizeof<T>() <= 4 ? 10 : 20) + i32(isSigned<T>());\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype<string>(__alloc(estLen << 1, idof<string>())); // retains\n var offset = 0;\n var value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load<T>(dataStart + (<usize>i << alignof<T>()));\n // @ts-ignore: type\n offset += itoa_stream<T>(changetype<usize>(result), offset, value);\n if (sepLen) {\n memory.copy(\n changetype<usize>(result) + (<usize>offset << 1),\n changetype<usize>(separator),\n <usize>sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load<T>(dataStart + (<usize>lastIndex << alignof<T>()));\n // @ts-ignore: type\n offset += itoa_stream<T>(changetype<usize>(result), offset, value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinFloatArray<T>(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n return changetype<string>(dtoa(\n // @ts-ignore: type\n load<T>(dataStart))\n ); // retains\n }\n\n const valueLen = MAX_DOUBLE_LENGTH;\n var sepLen = separator.length;\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype<string>(__alloc(estLen << 1, idof<string>())); // retains\n var offset = 0;\n var value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load<T>(dataStart + (<usize>i << alignof<T>()));\n offset += dtoa_stream(changetype<usize>(result), offset,\n // @ts-ignore: type\n value\n );\n if (sepLen) {\n memory.copy(\n changetype<usize>(result) + (<usize>offset << 1),\n changetype<usize>(separator),\n <usize>sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load<T>(dataStart + (<usize>lastIndex << alignof<T>()));\n offset += dtoa_stream(changetype<usize>(result), offset,\n // @ts-ignore: type\n value\n );\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinStringArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n // @ts-ignore: type\n return load<string>(dataStart) || \"\";\n }\n var estLen = 0;\n var value: string;\n for (let i = 0; i < length; ++i) {\n value = load<string>(dataStart + (<usize>i << alignof<string>()));\n // @ts-ignore: type\n if (value !== null) estLen += value.length;\n }\n var offset = 0;\n var sepLen = separator.length;\n var result = __alloc((estLen + sepLen * lastIndex) << 1, idof<string>());\n for (let i = 0; i < lastIndex; ++i) {\n value = load<string>(dataStart + (<usize>i << alignof<string>()));\n if (value !== null) {\n let valueLen = value.length;\n memory.copy(\n result + (<usize>offset << 1),\n changetype<usize>(value),\n <usize>valueLen << 1\n );\n offset += valueLen;\n }\n if (sepLen) {\n memory.copy(\n result + (<usize>offset << 1),\n changetype<usize>(separator),\n <usize>sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load<string>(dataStart + (<usize>lastIndex << alignof<string>()));\n if (value !== null) {\n memory.copy(\n result + (<usize>offset << 1),\n changetype<usize>(value),\n <usize>value.length << 1\n );\n }\n return changetype<string>(result); // retains\n}\n\nexport function joinReferenceArray<T>(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n var value: T;\n if (!lastIndex) {\n value = load<T>(dataStart);\n // @ts-ignore: type\n return value !== null ? value.toString() : \"\";\n }\n var result = \"\";\n var sepLen = separator.length;\n for (let i = 0; i < lastIndex; ++i) {\n value = load<T>(dataStart + (<usize>i << alignof<T>()));\n // @ts-ignore: type\n if (value !== null) result += value.toString();\n if (sepLen) result += separator;\n }\n value = load<T>(dataStart + (<usize>lastIndex << alignof<T>()));\n // @ts-ignore: type\n if (value !== null) result += value.toString();\n return result;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction scientific(significand: u64, exp: i32): f64 {\n if (!significand || exp < -342) return 0;\n if (exp > 308) return Infinity;\n // Try use fast path\n // Use fast path for string-to-double conversion if possible\n // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion\n // Simple integer\n var significandf = <f64>significand;\n if (!exp) return significandf;\n if (exp > 22 && exp <= 22 + 15) {\n significandf *= pow10(exp - 22);\n exp = 22;\n }\n if (significand <= 9007199254740991 && abs(exp) <= 22) {\n if (exp > 0) return significandf * pow10(exp);\n return significandf / pow10(-exp);\n } else if (exp < 0) {\n return scaledown(significand, exp);\n } else {\n return scaleup(significand, exp);\n }\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaledown(significand: u64, exp: i32): f64 {\n const denom: u64 = 6103515625; // 1e14 * 0x1p-14\n const scale = reinterpret<f64>(0x3F06849B86A12B9B); // 1e-14 * 0x1p32\n\n var shift = clz(significand);\n significand <<= shift;\n shift = exp - shift;\n\n for (; exp <= -14; exp += 14) {\n let q = significand / denom;\n let r = significand % denom;\n let s = clz(q);\n significand = (q << s) + <u64>nearest(scale * <f64>(r << (s - 18)));\n shift -= s;\n }\n var b = <u64>ipow32(5, -exp);\n var q = significand / b;\n var r = significand % b;\n var s = clz(q);\n significand = (q << s) + <u64>(reinterpret<f64>(reinterpret<u64>(<f64>r) + (s << 52)) / <f64>b);\n shift -= s;\n\n return NativeMath.scalbn(<f64>significand, <i32>shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaleup(significand: u64, exp: i32): f64 {\n const coeff: u32 = 1220703125; // 1e13 * 0x1p-13;\n var shift = ctz(significand);\n significand >>= shift;\n shift += exp;\n\n __fixmulShift = shift;\n for (; exp >= 13; exp -= 13) {\n significand = fixmul(significand, coeff);\n }\n significand = fixmul(significand, <u32>ipow32(5, exp));\n shift = __fixmulShift;\n return NativeMath.scalbn(<f64>significand, <i32>shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction parseExp(ptr: usize, len: i32): i32 {\n var sign = 1, magnitude = 0;\n var code = <u32>load<u16>(ptr);\n // check code is 'e' or 'E'\n if ((code | 32) != CharCode.e) return 0;\n\n code = <u32>load<u16>(ptr += 2);\n if (code == CharCode.MINUS) {\n if (!--len) return 0;\n code = <u32>load<u16>(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return 0;\n code = <u32>load<u16>(ptr += 2);\n }\n // skip zeros\n while (code == CharCode._0) {\n if (!--len) return 0;\n code = <u32>load<u16>(ptr += 2);\n }\n for (let digit: u32 = code - CharCode._0; len && digit < 10; digit = code - CharCode._0) {\n if (magnitude >= 3200) return sign * 3200;\n magnitude = 10 * magnitude + digit;\n code = <u32>load<u16>(ptr += 2);\n --len;\n }\n return sign * magnitude;\n}\n\n// @ts-ignore: decorator\n@lazy\nvar __fixmulShift: u64 = 0;\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction fixmul(a: u64, b: u32): u64 {\n var low = (a & 0xFFFFFFFF) * b;\n var high = (a >> 32) * b + (low >> 32);\n var overflow = <u32>(high >> 32);\n var space = clz(overflow);\n var revspace: u64 = 32 - space;\n __fixmulShift += revspace;\n return (high << space | (low & 0xFFFFFFFF) >> revspace) + (low << space >> 31 & 1);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction pow10(n: i32): f64 {\n // argument `n` should bounds in [0, 22] range\n return load<f64>(changetype<usize>(POWERS10) + (n << alignof<f64>()));\n}\n","import { COMPARATOR, SORT as SORT_IMPL } from \"./util/sort\";\nimport { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_NOTIMPLEMENTED } from \"./util/error\";\nimport { joinIntegerArray, joinFloatArray } from \"./util/string\";\nimport { idof } from \"./builtins\";\nimport { ArrayBufferView } from \"./arraybuffer\";\n\nexport class Int8Array extends ArrayBufferView {\n [key: number]: i8;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<i8>();\n\n constructor(length: i32) {\n super(length, alignof<i8>());\n }\n\n get length(): i32 {\n return this.byteLength;\n }\n\n @operator(\"[]\")\n private __get(index: i32): i8 {\n if (<u32>index >= <u32>this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<i8>(this.dataStart + <usize>index);\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): i8 {\n return load<i8>(this.dataStart + <usize>index);\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: native<i8>): void {\n if (<u32>index >= <u32>this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE);\n store<i8>(this.dataStart + <usize>index, value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: native<i8>): void {\n store<i8>(this.dataStart + <usize>index, value);\n }\n\n includes(searchElement: i8, fromIndex: i32 = 0): bool {\n return INCLUDES<Int8Array, i8>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: i8, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Int8Array, i8>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: i8, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Int8Array, i8>(this, searchElement, fromIndex);\n }\n\n fill(value: i32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int8Array {\n return FILL<Int8Array, i8>(this, value, start, end);\n }\n\n sort(comparator: (a: i8, b: i8) => i32 = COMPARATOR<i8>()): Int8Array {\n return SORT<Int8Array, i8>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int8Array {\n return SLICE<Int8Array, i8>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int8Array {\n return SUBARRAY<Int8Array, i8>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Int8Array {\n return COPY_WITHIN<Int8Array, i8>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: i8, index: i32, array: Int8Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Int8Array, i8, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: i8, index: i32, array: Int8Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Int8Array, i8, T>(this, fn, initialValue);\n }\n\n map(fn: (value: i8, index: i32, self: Int8Array) => i8): Int8Array {\n return MAP<Int8Array, i8>(this, fn);\n }\n\n filter(fn: (value: i8, index: i32, self: Int8Array) => bool): Int8Array {\n return FILTER<Int8Array, i8>(this, fn);\n }\n\n findIndex(fn: (value: i8, index: i32, self: Int8Array) => bool): i32 {\n return FIND_INDEX<Int8Array, i8>(this, fn);\n }\n\n some(fn: (value: i8, index: i32, self: Int8Array) => bool): bool {\n return SOME<Int8Array, i8>(this, fn);\n }\n\n every(fn: (value: i8, index: i32, self: Int8Array) => bool): bool {\n return EVERY<Int8Array, i8>(this, fn);\n }\n\n forEach(fn: (value: i8, index: i32, self: Int8Array) => void): void {\n FOREACH<Int8Array, i8>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, i8>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<i8>(this.dataStart, this.length, separator);\n }\n\n toString(): string {\n return this.join();\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Int8Array, i8, U, valueof<U>>(this, source, offset);\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Int8Array {\n return WRAP<Int8Array, i8>(buffer, byteOffset, length);\n }\n}\n\nexport class Uint8Array extends ArrayBufferView {\n [key: number]: u8;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<u8>();\n\n constructor(length: i32) {\n super(length, alignof<u8>());\n }\n\n get length(): i32 {\n return this.byteLength;\n }\n\n @operator(\"[]\")\n private __get(index: i32): u8 {\n if (<u32>index >= <u32>this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<u8>(this.dataStart + <usize>index);\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): u8 {\n return load<u8>(this.dataStart + <usize>index);\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: native<u8>): void {\n if (<u32>index >= <u32>this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE);\n store<u8>(this.dataStart + <usize>index, value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: native<u8>): void {\n store<u8>(this.dataStart + <usize>index, value);\n }\n\n includes(searchElement: u8, fromIndex: i32 = 0): bool {\n return INCLUDES<Uint8Array, u8>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: u8, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Uint8Array, u8>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: u8, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Uint8Array, u8>(this, searchElement, fromIndex);\n }\n\n fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8Array {\n return FILL<Uint8Array, u8>(this, value, start, end);\n }\n\n sort(comparator: (a: u8, b: u8) => i32 = COMPARATOR<u8>()): Uint8Array {\n return SORT<Uint8Array, u8>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8Array {\n return SLICE<Uint8Array, u8>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8Array {\n return SUBARRAY<Uint8Array, u8>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Uint8Array {\n return COPY_WITHIN<Uint8Array, u8>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: u8, index: i32, array: Uint8Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Uint8Array, u8, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: u8, index: i32, array: Uint8Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Uint8Array, u8, T>(this, fn, initialValue);\n }\n\n map(fn: (value: u8, index: i32, self: Uint8Array) => u8): Uint8Array {\n return MAP<Uint8Array, u8>(this, fn);\n }\n\n filter(fn: (value: u8, index: i32, self: Uint8Array) => bool): Uint8Array {\n return FILTER<Uint8Array, u8>(this, fn);\n }\n\n findIndex(fn: (value: u8, index: i32, self: Uint8Array) => bool): i32 {\n return FIND_INDEX<Uint8Array, u8>(this, fn);\n }\n\n some(fn: (value: u8, index: i32, self: Uint8Array) => bool): bool {\n return SOME<Uint8Array, u8>(this, fn);\n }\n\n every(fn: (value: u8, index: i32, self: Uint8Array) => bool): bool {\n return EVERY<Uint8Array, u8>(this, fn);\n }\n\n forEach(fn: (value: u8, index: i32, self: Uint8Array) => void): void {\n FOREACH<Uint8Array, u8>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, u8>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<u8>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Uint8Array, u8, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Uint8Array {\n return WRAP<Uint8Array, u8>(buffer, byteOffset, length);\n }\n}\n\nexport class Uint8ClampedArray extends ArrayBufferView {\n [key: number]: u8;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<u8>();\n\n constructor(length: i32) {\n super(length, alignof<u8>());\n }\n\n get length(): i32 {\n return this.byteLength;\n }\n\n @operator(\"[]\")\n private __get(index: i32): u8 {\n if (<u32>index >= <u32>this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<u8>(this.dataStart + <usize>index);\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): u8 {\n return load<u8>(this.dataStart + <usize>index);\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: native<u8>): void {\n if (<u32>index >= <u32>this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE);\n store<u8>(this.dataStart + <usize>index, ~(<i32>value >> 31) & (((255 - value) >> 31) | value));\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: native<u8>): void {\n store<u8>(this.dataStart + <usize>index, ~(<i32>value >> 31) & (((255 - value) >> 31) | value));\n }\n\n includes(searchElement: u8, fromIndex: i32 = 0): bool {\n return INCLUDES<Uint8ClampedArray, u8>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: u8, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Uint8ClampedArray, u8>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: u8, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Uint8ClampedArray, u8>(this, searchElement, fromIndex);\n }\n\n fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8ClampedArray {\n return FILL<Uint8ClampedArray, u8>(this, value, start, end);\n }\n\n sort(fn: (a: u8, b: u8) => i32 = COMPARATOR<u8>()): Uint8ClampedArray {\n return SORT<Uint8ClampedArray, u8>(this, fn);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8ClampedArray {\n return SLICE<Uint8ClampedArray, u8>(this, begin, end);\n }\n\n subarray(start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8ClampedArray {\n return SUBARRAY<Uint8ClampedArray, u8>(this, start, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Uint8ClampedArray {\n return COPY_WITHIN<Uint8ClampedArray, u8>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: u8, index: i32, array: Uint8ClampedArray) => T,\n initialValue: T,\n ): T {\n return REDUCE<Uint8ClampedArray, u8, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: u8, index: i32, array: Uint8ClampedArray) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Uint8ClampedArray, u8, T>(this, fn, initialValue);\n }\n\n map(fn: (value: u8, index: i32, self: Uint8ClampedArray) => u8): Uint8ClampedArray {\n return MAP<Uint8ClampedArray, u8>(this, fn);\n }\n\n filter(fn: (value: u8, index: i32, self: Uint8ClampedArray) => bool): Uint8ClampedArray {\n return FILTER<Uint8ClampedArray, u8>(this, fn);\n }\n\n findIndex(fn: (value: u8, index: i32, self: Uint8ClampedArray) => bool): i32 {\n return FIND_INDEX<Uint8ClampedArray, u8>(this, fn);\n }\n\n some(fn: (value: u8, index: i32, self: Uint8ClampedArray) => bool): bool {\n return SOME<Uint8ClampedArray, u8>(this, fn);\n }\n\n every(fn: (value: u8, index: i32, self: Uint8ClampedArray) => bool): bool {\n return EVERY<Uint8ClampedArray, u8>(this, fn);\n }\n\n forEach(fn: (value: u8, index: i32, self: Uint8ClampedArray) => void): void {\n FOREACH<Uint8ClampedArray, u8>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, u8>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<u8>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Uint8ClampedArray, u8, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Uint8ClampedArray {\n return WRAP<Uint8ClampedArray, u8>(buffer, byteOffset, length);\n }\n}\n\nexport class Int16Array extends ArrayBufferView {\n [key: number]: i16;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<i16>();\n\n constructor(length: i32) {\n super(length, alignof<i16>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<i16>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): i16 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<i16>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<i16>(this.dataStart + (<usize>index << alignof<i16>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): i16 {\n return load<i16>(this.dataStart + (<usize>index << alignof<i16>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: native<i16>): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<i16>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<i16>(this.dataStart + (<usize>index << alignof<i16>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: native<i16>): void {\n store<i16>(this.dataStart + (<usize>index << alignof<i16>()), value);\n }\n\n includes(searchElement: i16, fromIndex: i32 = 0): bool {\n return INCLUDES<Int16Array, i16>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: i16, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Int16Array, i16>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: i16, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Int16Array, i16>(this, searchElement, fromIndex);\n }\n\n fill(value: i32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int16Array {\n return FILL<Int16Array, i16>(this, value, start, end);\n }\n\n sort(comparator: (a: i16, b: i16) => i32 = COMPARATOR<i16>()): Int16Array {\n return SORT<Int16Array, i16>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int16Array {\n return SLICE<Int16Array, i16>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int16Array {\n return SUBARRAY<Int16Array, i16>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Int16Array {\n return COPY_WITHIN<Int16Array, i16>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: i16, index: i32, array: Int16Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Int16Array, i16, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: i16, index: i32, array: Int16Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Int16Array, i16, T>(this, fn, initialValue);\n }\n\n map(fn: (value: i16, index: i32, self: Int16Array) => i16): Int16Array {\n return MAP<Int16Array, i16>(this, fn);\n }\n\n filter(fn: (value: i16, index: i32, self: Int16Array) => bool): Int16Array {\n return FILTER<Int16Array, i16>(this, fn);\n }\n\n findIndex(fn: (value: i16, index: i32, self: Int16Array) => bool): i32 {\n return FIND_INDEX<Int16Array, i16>(this, fn);\n }\n\n some(fn: (value: i16, index: i32, self: Int16Array) => bool): bool {\n return SOME<Int16Array, i16>(this, fn);\n }\n\n every(fn: (value: i16, index: i32, self: Int16Array) => bool): bool {\n return EVERY<Int16Array, i16>(this, fn);\n }\n\n forEach(fn: (value: i16, index: i32, self: Int16Array) => void): void {\n FOREACH<Int16Array, i16>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, i16>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<i16>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Int16Array, i16, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Int16Array {\n return WRAP<Int16Array, i16>(buffer, byteOffset, length);\n }\n}\n\nexport class Uint16Array extends ArrayBufferView {\n [key: number]: u16;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<u16>();\n\n constructor(length: i32) {\n super(length, alignof<u16>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<u16>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): u16 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<u16>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<u16>(this.dataStart + (<usize>index << alignof<u16>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): u16 {\n return load<u16>(this.dataStart + (<usize>index << alignof<u16>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: native<u16>): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<u16>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<u16>(this.dataStart + (<usize>index << alignof<u16>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: native<u16>): void {\n store<u16>(this.dataStart + (<usize>index << alignof<u16>()), value);\n }\n\n includes(searchElement: u16, fromIndex: i32 = 0): bool {\n return INCLUDES<Uint16Array, u16>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: u16, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Uint16Array, u16>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: u16, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Uint16Array, u16>(this, searchElement, fromIndex);\n }\n\n fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint16Array {\n return FILL<Uint16Array, u16>(this, value, start, end);\n }\n\n sort(comparator: (a: u16, b: u16) => i32 = COMPARATOR<u16>()): Uint16Array {\n return SORT<Uint16Array, u16>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint16Array {\n return SLICE<Uint16Array, u16>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint16Array {\n return SUBARRAY<Uint16Array, u16>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Uint16Array {\n return COPY_WITHIN<Uint16Array, u16>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: u16, index: i32, array: Uint16Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Uint16Array, u16, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: u16, index: i32, array: Uint16Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Uint16Array, u16, T>(this, fn, initialValue);\n }\n\n map(fn: (value: u16, index: i32, self: Uint16Array) => u16): Uint16Array {\n return MAP<Uint16Array, u16>(this, fn);\n }\n\n filter(fn: (value: u16, index: i32, self: Uint16Array) => bool): Uint16Array {\n return FILTER<Uint16Array, u16>(this, fn);\n }\n\n findIndex(fn: (value: u16, index: i32, self: Uint16Array) => bool): i32 {\n return FIND_INDEX<Uint16Array, u16>(this, fn);\n }\n\n some(fn: (value: u16, index: i32, self: Uint16Array) => bool): bool {\n return SOME<Uint16Array, u16>(this, fn);\n }\n\n every(fn: (value: u16, index: i32, self: Uint16Array) => bool): bool {\n return EVERY<Uint16Array, u16>(this, fn);\n }\n\n forEach(fn: (value: u16, index: i32, self: Uint16Array) => void): void {\n FOREACH<Uint16Array, u16>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, u16>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<u16>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Uint16Array, u16, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Uint16Array {\n return WRAP<Uint16Array, u16>(buffer, byteOffset, length);\n }\n}\n\nexport class Int32Array extends ArrayBufferView {\n [key: number]: i32;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<i32>();\n\n constructor(length: i32) {\n super(length, alignof<i32>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<i32>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): i32 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<i32>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<i32>(this.dataStart + (<usize>index << alignof<i32>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): i32 {\n return load<i32>(this.dataStart + (<usize>index << alignof<i32>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: i32): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<i32>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<i32>(this.dataStart + (<usize>index << alignof<i32>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: i32): void {\n store<i32>(this.dataStart + (<usize>index << alignof<i32>()), value);\n }\n\n includes(searchElement: i32, fromIndex: i32 = 0): bool {\n return INCLUDES<Int32Array, i32>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: i32, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Int32Array, i32>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: i32, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Int32Array, i32>(this, searchElement, fromIndex);\n }\n\n fill(value: i32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int32Array {\n return FILL<Int32Array, i32>(this, value, start, end);\n }\n\n sort(comparator: (a: i32, b: i32) => i32 = COMPARATOR<i32>()): Int32Array {\n return SORT<Int32Array, i32>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int32Array {\n return SLICE<Int32Array, i32>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int32Array {\n return SUBARRAY<Int32Array, i32>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Int32Array {\n return COPY_WITHIN<Int32Array, i32>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: i32, index: i32, array: Int32Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Int32Array, i32, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: i32, index: i32, array: Int32Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Int32Array, i32, T>(this, fn, initialValue);\n }\n\n map(fn: (value: i32, index: i32, self: Int32Array) => i32): Int32Array {\n return MAP<Int32Array, i32>(this, fn);\n }\n\n filter(fn: (value: i32, index: i32, self: Int32Array) => bool): Int32Array {\n return FILTER<Int32Array, i32>(this, fn);\n }\n\n findIndex(fn: (value: i32, index: i32, self: Int32Array) => bool): i32 {\n return FIND_INDEX<Int32Array, i32>(this, fn);\n }\n\n some(fn: (value: i32, index: i32, self: Int32Array) => bool): bool {\n return SOME<Int32Array, i32>(this, fn);\n }\n\n every(fn: (value: i32, index: i32, self: Int32Array) => bool): bool {\n return EVERY<Int32Array, i32>(this, fn);\n }\n\n forEach(fn: (value: i32, index: i32, self: Int32Array) => void): void {\n FOREACH<Int32Array, i32>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, i32>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<i32>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Int32Array, i32, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Int32Array {\n return WRAP<Int32Array, i32>(buffer, byteOffset, length);\n }\n}\n\nexport class Uint32Array extends ArrayBufferView {\n [key: number]: u32;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<u32>();\n\n constructor(length: i32) {\n super(length, alignof<u32>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<u32>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): u32 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<u32>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<u32>(this.dataStart + (<usize>index << alignof<u32>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): u32 {\n return load<u32>(this.dataStart + (<usize>index << alignof<u32>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: u32): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<u32>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<u32>(this.dataStart + (<usize>index << alignof<u32>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: u32): void {\n store<u32>(this.dataStart + (<usize>index << alignof<u32>()), value);\n }\n\n includes(searchElement: u32, fromIndex: i32 = 0): bool {\n return INCLUDES<Uint32Array, u32>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: u32, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Uint32Array, u32>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: u32, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Uint32Array, u32>(this, searchElement, fromIndex);\n }\n\n fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint32Array {\n return FILL<Uint32Array, u32>(this, value, start, end);\n }\n\n sort(comparator: (a: u32, b: u32) => i32 = COMPARATOR<u32>()): Uint32Array {\n return SORT<Uint32Array, u32>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint32Array {\n return SLICE<Uint32Array, u32>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint32Array {\n return SUBARRAY<Uint32Array, u32>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Uint32Array {\n return COPY_WITHIN<Uint32Array, u32>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: u32, index: i32, array: Uint32Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Uint32Array, u32, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: u32, index: i32, array: Uint32Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Uint32Array, u32, T>(this, fn, initialValue);\n }\n\n map(fn: (value: u32, index: i32, self: Uint32Array) => u32): Uint32Array {\n return MAP<Uint32Array, u32>(this, fn);\n }\n\n filter(fn: (value: u32, index: i32, self: Uint32Array) => bool): Uint32Array {\n return FILTER<Uint32Array, u32>(this, fn);\n }\n\n findIndex(fn: (value: u32, index: i32, self: Uint32Array) => bool): i32 {\n return FIND_INDEX<Uint32Array, u32>(this, fn);\n }\n\n some(fn: (value: u32, index: i32, self: Uint32Array) => bool): bool {\n return SOME<Uint32Array, u32>(this, fn);\n }\n\n every(fn: (value: u32, index: i32, self: Uint32Array) => bool): bool {\n return EVERY<Uint32Array, u32>(this, fn);\n }\n\n forEach(fn: (value: u32, index: i32, self: Uint32Array) => void): void {\n FOREACH<Uint32Array, u32>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, u32>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<u32>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Uint32Array, u32, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Uint32Array {\n return WRAP<Uint32Array, u32>(buffer, byteOffset, length);\n }\n}\n\nexport class Int64Array extends ArrayBufferView {\n [key: number]: i64;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<i64>();\n\n constructor(length: i32) {\n super(length, alignof<i64>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<i64>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): i64 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<i64>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<i64>(this.dataStart + (<usize>index << alignof<i64>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): i64 {\n return load<i64>(this.dataStart + (<usize>index << alignof<i64>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: i64): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<i64>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<i64>(this.dataStart + (<usize>index << alignof<i64>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: i64): void {\n store<i64>(this.dataStart + (<usize>index << alignof<i64>()), value);\n }\n\n includes(searchElement: i64, fromIndex: i32 = 0): bool {\n return INCLUDES<Int64Array, i64>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: i64, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Int64Array, i64>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: i64, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Int64Array, i64>(this, searchElement, fromIndex);\n }\n\n fill(value: i64, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int64Array {\n return FILL<Int64Array, i64>(this, value, start, end);\n }\n\n sort(comparator: (a: i64, b: i64) => i32 = COMPARATOR<i64>()): Int64Array {\n return SORT<Int64Array, i64>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int64Array {\n return SLICE<Int64Array, i64>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Int64Array {\n return SUBARRAY<Int64Array, i64>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Int64Array {\n return COPY_WITHIN<Int64Array, i64>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: i64, index: i32, array: Int64Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Int64Array, i64, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: i64, index: i32, array: Int64Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Int64Array, i64, T>(this, fn, initialValue);\n }\n\n map(fn: (value: i64, index: i32, self: Int64Array) => i64): Int64Array {\n return MAP<Int64Array, i64>(this, fn);\n }\n\n filter(fn: (value: i64, index: i32, self: Int64Array) => bool): Int64Array {\n return FILTER<Int64Array, i64>(this, fn);\n }\n\n findIndex(fn: (value: i64, index: i32, self: Int64Array) => bool): i32 {\n return FIND_INDEX<Int64Array, i64>(this, fn);\n }\n\n some(fn: (value: i64, index: i32, self: Int64Array) => bool): bool {\n return SOME<Int64Array, i64>(this, fn);\n }\n\n every(fn: (value: i64, index: i32, self: Int64Array) => bool): bool {\n return EVERY<Int64Array, i64>(this, fn);\n }\n\n forEach(fn: (value: i64, index: i32, self: Int64Array) => void): void {\n FOREACH<Int64Array, i64>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, i64>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<i64>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Int64Array, i64, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Int64Array {\n return WRAP<Int64Array, i64>(buffer, byteOffset, length);\n }\n}\n\nexport class Uint64Array extends ArrayBufferView {\n [key: number]: u64;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<u64>();\n\n constructor(length: i32) {\n super(length, alignof<u64>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<u64>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): u64 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<u64>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<u64>(this.dataStart + (<usize>index << alignof<u64>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): u64 {\n return load<u64>(this.dataStart + (<usize>index << alignof<u64>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: u64): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<u64>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<u64>(this.dataStart + (<usize>index << alignof<u64>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: u64): void {\n store<u64>(this.dataStart + (<usize>index << alignof<u64>()), value);\n }\n\n includes(searchElement: u64, fromIndex: i32 = 0): bool {\n return INCLUDES<Uint64Array, u64>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: u64, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Uint64Array, u64>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: u64, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Uint64Array, u64>(this, searchElement, fromIndex);\n }\n\n fill(value: u64, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint64Array {\n return FILL<Uint64Array, u64>(this, value, start, end);\n }\n\n sort(comparator: (a: u64, b: u64) => i32 = COMPARATOR<u64>()): Uint64Array {\n return SORT<Uint64Array, u64>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint64Array {\n return SLICE<Uint64Array, u64>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Uint64Array {\n return SUBARRAY<Uint64Array, u64>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Uint64Array {\n return COPY_WITHIN<Uint64Array, u64>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: u64, index: i32, array: Uint64Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Uint64Array, u64, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: u64, index: i32, array: Uint64Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Uint64Array, u64, T>(this, fn, initialValue);\n }\n\n map(fn: (value: u64, index: i32, self: Uint64Array) => u64): Uint64Array {\n return MAP<Uint64Array, u64>(this, fn);\n }\n\n filter(fn: (value: u64, index: i32, self: Uint64Array) => bool): Uint64Array {\n return FILTER<Uint64Array, u64>(this, fn);\n }\n\n findIndex(fn: (value: u64, index: i32, self: Uint64Array) => bool): i32 {\n return FIND_INDEX<Uint64Array, u64>(this, fn);\n }\n\n some(fn: (value: u64, index: i32, self: Uint64Array) => bool): bool {\n return SOME<Uint64Array, u64>(this, fn);\n }\n\n every(fn: (value: u64, index: i32, self: Uint64Array) => bool): bool {\n return EVERY<Uint64Array, u64>(this, fn);\n }\n\n forEach(fn: (value: u64, index: i32, self: Uint64Array) => void): void {\n FOREACH<Uint64Array, u64>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, u64>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinIntegerArray<u64>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Uint64Array, u64, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Uint64Array {\n return WRAP<Uint64Array, u64>(buffer, byteOffset, length);\n }\n}\n\nexport class Float32Array extends ArrayBufferView {\n [key: number]: f32;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<f32>();\n\n constructor(length: i32) {\n super(length, alignof<f32>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<f32>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): f32 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<f32>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<f32>(this.dataStart + (<usize>index << alignof<f32>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): f32 {\n return load<f32>(this.dataStart + (<usize>index << alignof<f32>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: f32): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<f32>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<f32>(this.dataStart + (<usize>index << alignof<f32>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: f32): void {\n store<f32>(this.dataStart + (<usize>index << alignof<f32>()), value);\n }\n\n includes(searchElement: f32, fromIndex: i32 = 0): bool {\n return INCLUDES<Float32Array, f32>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: f32, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Float32Array, f32>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: f32, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Float32Array, f32>(this, searchElement, fromIndex);\n }\n\n fill(value: f32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Float32Array {\n return FILL<Float32Array, f32>(this, value, start, end);\n }\n\n sort(comparator: (a: f32, b: f32) => i32 = COMPARATOR<f32>()): Float32Array {\n return SORT<Float32Array, f32>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Float32Array {\n return SLICE<Float32Array, f32>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Float32Array {\n return SUBARRAY<Float32Array, f32>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Float32Array {\n return COPY_WITHIN<Float32Array, f32>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: f32, index: i32, array: Float32Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Float32Array, f32, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: f32, index: i32, array: Float32Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Float32Array, f32, T>(this, fn, initialValue);\n }\n\n map(fn: (value: f32, index: i32, self: Float32Array) => f32): Float32Array {\n return MAP<Float32Array, f32>(this, fn);\n }\n\n filter(fn: (value: f32, index: i32, self: Float32Array) => bool): Float32Array {\n return FILTER<Float32Array, f32>(this, fn);\n }\n\n findIndex(fn: (value: f32, index: i32, self: Float32Array) => bool): i32 {\n return FIND_INDEX<Float32Array, f32>(this, fn);\n }\n\n some(fn: (value: f32, index: i32, self: Float32Array) => bool): bool {\n return SOME<Float32Array, f32>(this, fn);\n }\n\n every(fn: (value: f32, index: i32, self: Float32Array) => bool): bool {\n return EVERY<Float32Array, f32>(this, fn);\n }\n\n forEach(fn: (value: f32, index: i32, self: Float32Array) => void): void {\n FOREACH<Float32Array, f32>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, f32>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinFloatArray<f32>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Float32Array, f32, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Float32Array {\n return WRAP<Float32Array, f32>(buffer, byteOffset, length);\n }\n}\n\nexport class Float64Array extends ArrayBufferView {\n [key: number]: f64;\n\n // @ts-ignore: decorator\n @lazy\n static readonly BYTES_PER_ELEMENT: i32 = sizeof<f64>();\n\n constructor(length: i32) {\n super(length, alignof<f64>());\n }\n\n get length(): i32 {\n return this.byteLength >>> alignof<f64>();\n }\n\n @operator(\"[]\")\n private __get(index: i32): f64 {\n if (<u32>index >= <u32>this.byteLength >>> alignof<f64>()) throw new RangeError(E_INDEXOUTOFRANGE);\n return load<f64>(this.dataStart + (<usize>index << alignof<f64>()));\n }\n\n @unsafe @operator(\"{}\")\n private __uget(index: i32): f64 {\n return load<f64>(this.dataStart + (<usize>index << alignof<f64>()));\n }\n\n @operator(\"[]=\")\n private __set(index: i32, value: f64): void {\n if (<u32>index >= <u32>this.byteLength >>> alignof<f64>()) throw new RangeError(E_INDEXOUTOFRANGE);\n store<f64>(this.dataStart + (<usize>index << alignof<f64>()), value);\n }\n\n @unsafe @operator(\"{}=\")\n private __uset(index: i32, value: f64): void {\n store<f64>(this.dataStart + (<usize>index << alignof<f64>()), value);\n }\n\n includes(searchElement: f64, fromIndex: i32 = 0): bool {\n return INCLUDES<Float64Array, f64>(this, searchElement, fromIndex);\n }\n\n indexOf(searchElement: f64, fromIndex: i32 = 0): i32 {\n return INDEX_OF<Float64Array, f64>(this, searchElement, fromIndex);\n }\n\n lastIndexOf(searchElement: f64, fromIndex: i32 = this.length): i32 {\n return LAST_INDEX_OF<Float64Array, f64>(this, searchElement, fromIndex);\n }\n\n fill(value: f64, start: i32 = 0, end: i32 = i32.MAX_VALUE): Float64Array {\n return FILL<Float64Array, f64>(this, value, start, end);\n }\n\n sort(comparator: (a: f64, b: f64) => i32 = COMPARATOR<f64>()): Float64Array {\n return SORT<Float64Array, f64>(this, comparator);\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Float64Array {\n return SLICE<Float64Array, f64>(this, begin, end);\n }\n\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Float64Array {\n return SUBARRAY<Float64Array, f64>(this, begin, end);\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Float64Array {\n return COPY_WITHIN<Float64Array, f64>(this, target, start, end);\n }\n\n reduce<T>(\n fn: (accumulator: T, value: f64, index: i32, array: Float64Array) => T,\n initialValue: T,\n ): T {\n return REDUCE<Float64Array, f64, T>(this, fn, initialValue);\n }\n\n reduceRight<T>(\n fn: (accumulator: T, value: f64, index: i32, array: Float64Array) => T,\n initialValue: T,\n ): T {\n return REDUCE_RIGHT<Float64Array, f64, T>(this, fn, initialValue);\n }\n\n map(fn: (value: f64, index: i32, self: Float64Array) => f64): Float64Array {\n return MAP<Float64Array, f64>(this, fn);\n }\n\n filter(fn: (value: f64, index: i32, self: Float64Array) => bool): Float64Array {\n return FILTER<Float64Array, f64>(this, fn);\n }\n\n findIndex(fn: (value: f64, index: i32, self: Float64Array) => bool): i32 {\n return FIND_INDEX<Float64Array, f64>(this, fn);\n }\n\n some(fn: (value: f64, index: i32, self: Float64Array) => bool): bool {\n return SOME<Float64Array, f64>(this, fn);\n }\n\n every(fn: (value: f64, index: i32, self: Float64Array) => bool): bool {\n return EVERY<Float64Array, f64>(this, fn);\n }\n\n forEach(fn: (value: f64, index: i32, self: Float64Array) => void): void {\n FOREACH<Float64Array, f64>(this, fn);\n }\n\n reverse(): this {\n return REVERSE<this, f64>(this);\n }\n\n join(separator: string = \",\"): string {\n return joinFloatArray<f64>(this.dataStart, this.length, separator);\n }\n\n set<U extends ArrayBufferView>(source: U, offset: i32 = 0): void {\n SET<Float64Array, f64, U, valueof<U>>(this, source, offset);\n }\n\n toString(): string {\n return this.join();\n }\n\n static wrap(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): Float64Array {\n return WRAP<Float64Array, f64>(buffer, byteOffset, length);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction FILL<TArray extends ArrayBufferView, T extends number>(\n array: TArray,\n value: native<T>,\n start: i32,\n end: i32\n): TArray {\n var dataStart = array.dataStart;\n var len = array.length;\n start = start < 0 ? max(len + start, 0) : min(start, len);\n end = end < 0 ? max(len + end, 0) : min(end, len);\n if (sizeof<T>() == 1) {\n if (start < end) memory.fill(dataStart + <usize>start, <u8>value, <usize>(end - start));\n } else {\n for (; start < end; ++start) {\n store<T>(dataStart + (<usize>start << alignof<T>()), value);\n }\n }\n return array;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction SORT<TArray extends ArrayBufferView, T>(\n array: TArray,\n comparator: (a: T, b: T) => i32\n): TArray {\n var len = array.length;\n if (len <= 1) return array;\n var base = array.dataStart;\n if (len == 2) {\n let a: T = load<T>(base, sizeof<T>()); // a = arr[1]\n let b: T = load<T>(base); // b = arr[0]\n if (comparator(a, b) < 0) {\n store<T>(base, b, sizeof<T>()); // arr[1] = b\n store<T>(base, a); // arr[0] = a\n }\n return array;\n }\n SORT_IMPL<T>(base, len, comparator);\n return array;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction SLICE<TArray extends ArrayBufferView, T>(\n array: TArray,\n start: i32,\n end: i32\n): TArray {\n var len = array.length;\n start = start < 0 ? max(start + len, 0) : min(start, len);\n end = end < 0 ? max(end + len, 0) : min(end , len);\n len = max(end - start, 0);\n var slice = instantiate<TArray>(len);\n memory.copy(\n slice.dataStart,\n array.dataStart + (<usize>start << alignof<T>()),\n <usize>len << alignof<T>()\n );\n return slice;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction SUBARRAY<TArray extends ArrayBufferView, T>(\n array: TArray,\n begin: i32,\n end: i32\n): TArray {\n var len = array.length;\n begin = begin < 0 ? max(len + begin, 0) : min(begin, len);\n end = end < 0 ? max(len + end, 0) : min(end, len);\n end = max(end, begin);\n\n var out = __alloc(offsetof<TArray>(), idof<TArray>());\n store<usize>(out, __retain(changetype<usize>(array.buffer)), offsetof<TArray>(\"buffer\"));\n store<usize>(out, array.dataStart + (<usize>begin << alignof<T>()), offsetof<TArray>(\"dataStart\"));\n store<u32>(out, (end - begin) << alignof<T>(), offsetof<TArray>(\"byteLength\"));\n return changetype<TArray>(out); // retains\n}\n\n// @ts-ignore: decorator\n@inline\nfunction COPY_WITHIN<TArray extends ArrayBufferView, T>(\n array: TArray,\n target: i32,\n start: i32,\n end: i32\n): TArray {\n var len = array.length;\n var dataStart = array.dataStart;\n\n end = min<i32>(end, len);\n var to = target < 0 ? max(len + target, 0) : min(target, len);\n var from = start < 0 ? max(len + start, 0) : min(start, len);\n var last = end < 0 ? max(len + end, 0) : min(end, len);\n var count = min(last - from, len - to);\n\n memory.copy(\n dataStart + (<usize>to << alignof<T>()),\n dataStart + (<usize>from << alignof<T>()),\n <usize>count << alignof<T>()\n );\n return array;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction REDUCE<TArray extends ArrayBufferView, T, TRet>(\n array: TArray,\n fn: (accumulator: TRet, value: T, index: i32, array: TArray) => TRet,\n initialValue: TRet\n): TRet {\n var dataStart = array.dataStart;\n for (let i = 0, k = array.length; i < k; i++) {\n initialValue = fn(initialValue, load<T>(dataStart + (<usize>i << alignof<T>())), i, array);\n }\n return initialValue;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction REDUCE_RIGHT<TArray extends ArrayBufferView, T, TRet>(\n array: TArray,\n fn: (accumulator: TRet, value: T, index: i32, array: TArray) => TRet,\n initialValue: TRet\n): TRet {\n var dataStart = array.dataStart;\n for (let i = array.length - 1; i >= 0; i--) {\n initialValue = fn(initialValue, load<T>(dataStart + (<usize>i << alignof<T>())), i, array);\n }\n return initialValue;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction MAP<TArray extends ArrayBufferView, T>(\n array: TArray,\n fn: (value: T, index: i32, self: TArray) => T,\n): TArray {\n var len = array.length;\n var dataStart = array.dataStart;\n\n var byteLength = len << alignof<T>();\n var out = __alloc(offsetof<TArray>(), idof<TArray>());\n var buffer = __alloc(byteLength, idof<ArrayBuffer>());\n for (let i = 0; i < len; i++) {\n store<T>(\n buffer + (<usize>i << alignof<T>()),\n fn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array)\n );\n }\n store<usize>(out, __retain(buffer), offsetof<TArray>(\"buffer\"));\n store<usize>(out, buffer, offsetof<TArray>(\"dataStart\"));\n store<u32>(out, byteLength, offsetof<TArray>(\"byteLength\"));\n return changetype<TArray>(out); // retains\n}\n\n// @ts-ignore: decorator\n@inline\nfunction FILTER<TArray extends ArrayBufferView, T>(\n array: TArray,\n fn: (value: T, index: i32, self: TArray) => bool,\n): TArray {\n var len = array.length;\n var out = __alloc(offsetof<TArray>(), idof<TArray>());\n var buffer = __alloc(len << alignof<T>(), idof<ArrayBuffer>());\n var dataStart = array.dataStart;\n var j: usize = 0;\n for (let i = 0; i < len; i++) {\n let value = load<T>(dataStart + (<usize>i << alignof<T>()));\n if (fn(value, i, array)) {\n store<T>(\n buffer + (j++ << alignof<T>()),\n value\n );\n }\n }\n // shrink output buffer\n var byteLength = j << alignof<T>();\n var data = __realloc(buffer, byteLength);\n store<usize>(out, __retain(data), offsetof<TArray>(\"buffer\"));\n store<u32>(out, byteLength, offsetof<TArray>(\"byteLength\"));\n store<usize>(out, data, offsetof<TArray>(\"dataStart\"));\n return changetype<TArray>(out); // retains\n}\n\n// @ts-ignore: decorator\n@inline\nfunction FIND_INDEX<TArray extends ArrayBufferView, T>(\n array: TArray,\n fn: (value: T, index: i32, array: TArray) => bool,\n): i32 {\n var dataStart = array.dataStart;\n for (let i = 0, k = array.length; i < k; i++) {\n if (fn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array)) return i;\n }\n return -1;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction INCLUDES<TArray extends ArrayBufferView, T>(\n array: TArray,\n searchElement: T,\n fromIndex: i32,\n): bool {\n if (isFloat<T>()) {\n let index: isize = fromIndex;\n let length: isize = array.length;\n if (length == 0 || index >= length) return false;\n if (index < 0) index = max(length + index, 0);\n let dataStart = array.dataStart;\n while (index < length) {\n let elem = load<T>(dataStart + (index << alignof<T>()));\n // @ts-ignore\n if (elem == searchElement || isNaN(elem) & isNaN(searchElement)) return true;\n ++index;\n }\n return false;\n } else {\n return INDEX_OF<TArray, T>(array, searchElement, fromIndex) >= 0;\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction INDEX_OF<TArray extends ArrayBufferView, T>(\n array: TArray,\n searchElement: T,\n fromIndex: i32,\n): i32 {\n var index: isize = fromIndex;\n var length: isize = array.length;\n if (length == 0 || index >= length) return -1;\n if (index < 0) index = max(length + index, 0);\n var dataStart = array.dataStart;\n while (index < length) {\n if (load<T>(dataStart + (index << alignof<T>())) == searchElement) return <i32>index;\n ++index;\n }\n return -1;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction LAST_INDEX_OF<TArray extends ArrayBufferView, T>(\n array: TArray,\n searchElement: T,\n fromIndex: i32,\n): i32 {\n var index: isize = fromIndex;\n var length: isize = array.length;\n if (length == 0) return -1;\n if (index < 0) index = length + index; // no need to clamp\n else if (index >= length) index = length - 1;\n var dataStart = array.dataStart;\n while (index >= 0) {\n if (load<T>(dataStart + (index << alignof<T>())) == searchElement) return <i32>index;\n --index;\n }\n return -1;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction SOME<TArray extends ArrayBufferView, T>(\n array: TArray,\n fn: (value: T, index: i32, array: TArray) => bool,\n): bool {\n var dataStart = array.dataStart;\n for (let i = 0, k = array.length; i < k; i++) {\n if (fn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array)) return true;\n }\n return false;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction EVERY<TArray extends ArrayBufferView, T>(\n array: TArray,\n fn: (value: T, index: i32, array: TArray) => bool,\n): bool {\n var dataStart = array.dataStart;\n for (let i = 0, k = array.length; i < k; i++) {\n if (fn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array)) continue;\n return false;\n }\n return true;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction FOREACH<TArray extends ArrayBufferView, T>(\n array: TArray,\n fn: (value: T, index: i32, array: TArray) => void,\n): void {\n var dataStart = array.dataStart;\n for (let i = 0, k = array.length; i < k; i++) {\n fn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction REVERSE<TArray extends ArrayBufferView, T>(array: TArray): TArray {\n var dataStart = array.dataStart;\n for (let front: usize = 0, back: usize = array.length - 1; front < back; ++front, --back) {\n let frontPtr = dataStart + (front << alignof<T>());\n let backPtr = dataStart + (back << alignof<T>());\n let temp = load<T>(frontPtr);\n store<T>(frontPtr, load<T>(backPtr));\n store<T>(backPtr, temp);\n }\n return array;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction WRAP<TArray extends ArrayBufferView, T>(buffer: ArrayBuffer, byteOffset: i32 = 0, length: i32 = -1): TArray {\n var byteLength: i32;\n var bufferByteLength = buffer.byteLength;\n const mask: u32 = sizeof<T>() - 1;\n if (i32(<u32>byteOffset > <u32>bufferByteLength) | (byteOffset & mask)) {\n throw new RangeError(E_INDEXOUTOFRANGE);\n }\n if (length < 0) {\n if (length == -1) {\n if (bufferByteLength & mask) {\n throw new RangeError(E_INVALIDLENGTH);\n }\n byteLength = bufferByteLength - byteOffset;\n } else {\n throw new RangeError(E_INVALIDLENGTH);\n }\n } else {\n byteLength = length << alignof<T>();\n if (byteOffset + byteLength > bufferByteLength) {\n throw new RangeError(E_INVALIDLENGTH);\n }\n }\n var out = __alloc(offsetof<TArray>(), idof<TArray>());\n store<usize>(out, __retain(changetype<usize>(buffer)), offsetof<TArray>(\"buffer\"));\n store<u32>(out, byteLength, offsetof<TArray>(\"byteLength\"));\n store<usize>(out, changetype<usize>(buffer) + <usize>byteOffset, offsetof<TArray>(\"dataStart\"));\n return changetype<TArray>(out); // retains\n}\n\n// @ts-ignore: decorator\n@inline\nfunction SET<TArray extends ArrayBufferView, T, UArray extends ArrayBufferView, U>(target: TArray, source: UArray, offset: i32 = 0): void {\n // need to assert at compile time that U is not a reference or a function\n if (isReference<U>()) {\n ERROR(E_NOTIMPLEMENTED);\n }\n\n // Uncaught RangeError: offset is out of bounds\n if (offset < 0) throw new RangeError(E_INDEXOUTOFRANGE);\n if (source.length + offset > target.length) throw new RangeError(E_INDEXOUTOFRANGE);\n\n // if the types align and match, use memory.copy() instead of manual loop\n if (isInteger<T>() == isInteger<U>() && alignof<T>() == alignof<U>() &&\n !(target instanceof Uint8ClampedArray && isSigned<U>())) {\n memory.copy(\n target.dataStart + (<usize>offset << alignof<T>()),\n source.dataStart,\n source.byteLength\n );\n } else {\n let targetDataStart = target.dataStart + (<usize>offset << alignof<T>());\n let sourceDataStart = source.dataStart;\n let count = source.length;\n for (let i = 0; i < count; i++) {\n // if TArray is Uint8ClampedArray, then values must be clamped\n if (target instanceof Uint8ClampedArray) {\n if (isFloat<U>()) {\n let value = load<U>(sourceDataStart + (<usize>i << alignof<U>()));\n store<T>(\n targetDataStart + (<usize>i << alignof<T>()),\n isFinite<U>(value) ? <T>max<U>(0, min<U>(255, value)) : 0\n );\n } else {\n let value = load<U>(sourceDataStart + (<usize>i << alignof<U>()));\n if (!isSigned<U>()) {\n store<T>(\n targetDataStart + (<usize>i << alignof<T>()),\n // @ts-ignore: cast to T is valid for numeric types here\n min<U>(255, value)\n );\n } else if (sizeof<T>() <= 4) {\n store<T>(\n targetDataStart + (<usize>i << alignof<T>()),\n // @ts-ignore: cast to T is valid for numeric types here\n ~(<i32>value >> 31) & (((255 - <i32>value) >> 31) | value)\n );\n } else {\n store<T>(\n targetDataStart + (<usize>i << alignof<T>()),\n // @ts-ignore: cast to T is valid for numeric types here\n ~(<i64>value >> 63) & (((255 - <i64>value) >> 63) | value)\n );\n }\n }\n // if U is a float, then casting float to int must include a finite check\n } else if (isFloat<U>() && !isFloat<T>()) {\n let value = load<U>(sourceDataStart + (<usize>i << alignof<U>()));\n // @ts-ignore: cast to T is valid for numeric types here\n store<T>(targetDataStart + (<usize>i << alignof<T>()), isFinite<U>(value) ? <T>value : 0);\n } else if (isFloat<T>() && !isFloat<U>()) {\n // @ts-ignore: In this case the <T> conversion is required\n store<T>(targetDataStart + (<usize>i << alignof<T>()), <T>load<U>(sourceDataStart + (<usize>i << alignof<U>())));\n } else {\n store<T>(targetDataStart + (<usize>i << alignof<T>()), load<U>(sourceDataStart + (<usize>i << alignof<U>())));\n }\n }\n }\n}\n"]}