import type { Maybe } from "Maybe" import {} from "Scan" #iftarget js import { Just, Nothing } from "Maybe" _scanShort :: (Short -> Maybe Short) -> Maybe Short -> String -> Maybe Short _scanShort = (just, nothing, str) => ( #- { const intPattern = /^[+-]?\d+$/ if (str.trim() !== str || !intPattern.test(str)) { return nothing } const n = Number(str) return Number.isSafeInteger(n) && n >= -2147483648 && n <= 2147483647 ? just(n) : nothing } -# ) scanShort = _scanShort(Just, Nothing) #elseif llvm scanShort :: String -> Maybe Short scanShort = extern "madlib__number__scanShort" #endif instance Scan Short { scan = scanShort } #iftarget js toInteger :: Short -> Integer export toInteger = (a) => #- { return a } -# toByte :: Short -> Byte export toByte = (a) => #- { return Uint8Array.from([a])[0] } -# toFloat :: Short -> Float export toFloat = (a) => #- { return a } -# fromInteger :: Integer -> Short export fromInteger = (a) => #- { return Int32Array.from([a])[0] } -# fromByte :: Byte -> Short export fromByte = (a) => #- { return Int32Array.from([a])[0] } -# fromFloat :: Float -> Short export fromFloat = (a) => #- { return Int32Array.from([Math.trunc(a)])[0] } -# #elseif llvm toInteger :: Short -> Integer export toInteger = extern "madlib__number__shortToInt" toByte :: Short -> Byte export toByte = extern "madlib__number__shortToByte" toFloat :: Short -> Float export toFloat = extern "madlib__number__shortToFloat" fromInteger :: Integer -> Short export fromInteger = extern "madlib__number__intToShort" fromByte :: Byte -> Short export fromByte = extern "madlib__number__byteToShort" fromFloat :: Float -> Short export fromFloat = extern "madlib__number__floatToShort" #endif