@@ -237,7 +237,7 @@ let toFloat com (ctx: Context) r targetType (args: Expr list) : Expr =
237237 | String -> Helper.LibCall( com, " Double" , " parse" , targetType, args)
238238 | Number( kind, _) ->
239239 match kind with
240- | Decimal -> Helper.LibCall( com, " Decimal" , " toNumber " , targetType, args)
240+ | Decimal -> Helper.LibCall( com, " Decimal" , " toFloat64 " , targetType, args)
241241 | BigIntegers _ -> Helper.LibCall( com, " BigInt" , " toFloat64" , targetType, args)
242242 | _ -> TypeCast( args.Head, targetType)
243243 | _ ->
@@ -254,7 +254,7 @@ let toDecimal com (ctx: Context) r targetType (args: Expr list) : Expr =
254254 | Number( kind, _) ->
255255 match kind with
256256 | Decimal -> args.Head
257- | BigIntegers _ -> Helper.LibCall( com, " BigInt" , " toDecimal" , Float64.Number , args)
257+ | BigIntegers _ -> Helper.LibCall( com, " BigInt" , " toDecimal" , targetType , args)
258258 | _ -> makeDecimalFromExpr com r targetType args.Head
259259 | _ ->
260260 addWarning com ctx.InlinePath r " Cannot make conversion because source type is unknown"
@@ -281,8 +281,9 @@ let stringToInt com (ctx: Context) r targetType (args: Expr list) : Expr =
281281
282282let wrapLong com ( ctx : Context ) r t ( arg : Expr ) : Expr =
283283 match t with
284+ | Number( BigInt, _) -> arg
284285 | Number( kind, _) ->
285- let toMeth = " to" + kind.ToString()
286+ let toMeth = " to" + kind.ToString() + " _unchecked "
286287 Helper.LibCall( com, " BigInt" , toMeth, t, [ arg ])
287288 | _ ->
288289 addWarning com ctx.InlinePath r " Unexpected conversion to long"
@@ -297,10 +298,18 @@ let toLong com (ctx: Context) r targetType (args: Expr list) : Expr =
297298 |> wrapLong com ctx r targetType
298299 | String, _ -> stringToInt com ctx r targetType args |> wrapLong com ctx r targetType
299300 | Number( fromKind, _), Number( toKind, _) ->
300- let fromMeth = " from" + fromKind.ToString()
301+ match fromKind with
302+ | BigInt ->
303+ let toMeth = " to" + toKind.ToString()
304+ Helper.LibCall( com, " BigInt" , toMeth, targetType, args)
305+ | Decimal ->
306+ let toMeth = " to" + toKind.ToString()
307+ Helper.LibCall( com, " Decimal" , toMeth, targetType, args)
308+ | _ ->
309+ let fromMeth = " from" + fromKind.ToString()
301310
302- Helper.LibCall( com, " BigInt" , fromMeth, BigInt.Number, args, ?loc = r)
303- |> wrapLong com ctx r targetType
311+ Helper.LibCall( com, " BigInt" , fromMeth, BigInt.Number, args, ?loc = r)
312+ |> wrapLong com ctx r targetType
304313 | _ ->
305314 addWarning com ctx.InlinePath r " Cannot make conversion because source type is unknown"
306315 TypeCast( args.Head, targetType)
@@ -327,10 +336,15 @@ let toInt com (ctx: Context) r targetType (args: Expr list) =
327336 | Number( fromKind, _), Number( toKind, _) ->
328337 if needToCast fromKind toKind then
329338 match fromKind with
339+ | BigInt ->
340+ let toMeth = " to" + toKind.ToString()
341+ Helper.LibCall( com, " BigInt" , toMeth, targetType, args)
330342 | BigIntegers _ ->
331- let meth = " to" + toKind.ToString()
332- Helper.LibCall( com, " BigInt" , meth, targetType, args)
333- | Decimal -> Helper.LibCall( com, " Decimal" , " toNumber" , targetType, args)
343+ let toMeth = " to" + toKind.ToString() + " _unchecked"
344+ Helper.LibCall( com, " BigInt" , toMeth, targetType, args)
345+ | Decimal ->
346+ let toMeth = " to" + toKind.ToString()
347+ Helper.LibCall( com, " Decimal" , toMeth, targetType, args)
334348 | _ -> args.Head
335349 |> emitIntCast toKind
336350 else
@@ -342,14 +356,10 @@ let toInt com (ctx: Context) r targetType (args: Expr list) =
342356let round com ( args : Expr list ) =
343357 match args.Head.Type with
344358 | Number( Decimal, _) ->
345- let n = Helper.LibCall( com, " Decimal" , " toNumber" , Float64.Number, [ args.Head ])
346-
347- let rounded = Helper.LibCall( com, " Util" , " round" , Float64.Number, [ n ])
348-
359+ let rounded = Helper.LibCall( com, " Decimal" , " round" , Decimal.Number, [ args.Head ])
349360 rounded :: args.Tail
350361 | Number( Floats _, _) ->
351362 let rounded = Helper.LibCall( com, " Util" , " round" , Float64.Number, [ args.Head ])
352-
353363 rounded :: args.Tail
354364 | _ -> args
355365
0 commit comments