{ "version": 3, "sourceRoot": "Source", "sources": ["WebSharper.MathJS.Extensions/Decimal.fs"], "sourcesContent": ["// $begin{copyright}\n//\n// This file is part of WebSharper\n//\n// Copyright (c) 2008-2018 IntelliFactory\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\"); you\n// may not use this file except in compliance with the License. You may\n// obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n// implied. See the License for the specific language governing\n// permissions and limitations under the License.\n//\n// $end{copyright}\n\nnamespace WebSharper\n\nopen System.Runtime.InteropServices\nopen WebSharper\nopen WebSharper.JavaScript\nopen WebSharper.MathJS\n\nmodule M = WebSharper.Core.Macros\n\n[)>]\nmodule internal Decimal =\n []\n let WSDecimalMath: MathJS.MathInstance =\n MathJS.Math.Create(Config(Number = \"BigNumber\", Precision = 29., Predictable = true, Epsilon = 1e-60))\n\n []\n let CreateDecimal(lo: int32, mid: int32, hi: int32, isNegative: bool, scale: byte) : decimal =\n let n(x:int) = (WSDecimalMath.Bignumber x) |> As\n if lo = 0 && hi = 0 && mid = 0 then\n n 0\n else\n let uint_sup =\n System.Decimal.Add(System.Decimal.Multiply((n 429496729), (n 10)), (n 6))\n let reinterpret (x: int) = \n if x >= 0 then\n n(x)\n else\n uint_sup + (n x)\n let quotient =\n WSDecimalMath.Pow((n 10 |> As), WSDecimalMath.UnaryMinus((n <| int scale )|>As)) |> As\n let value =\n (((reinterpret hi) * uint_sup + reinterpret mid) * uint_sup + reinterpret lo)\n let sign = if isNegative then (n -1) else (n 1)\n sign * value * quotient\n\n []\n let CreateDecimalBits (bits : int32[]) =\n if bits.Length = 4 then\n let sign = (bits.[3] &&& 0x80000000) <> 0\n let scale = As ((bits.[3] >>> 16) &&& 0x7F)\n CreateDecimal(bits.[0], bits.[1], bits.[2], sign, scale) \n else\n invalidArg \"bits\" \"The length of the bits array is not 4\"\n\nopen Decimal\n\n[)>]\n[)>]\n[]\ntype internal DecimalProxy =\n\n []\n static member CtorProxy(lo: int32, mid: int32, hi: int32, isNegative: bool, scale: byte) : decimal =\n CreateDecimal(lo, mid, hi, isNegative, scale) \n\n []\n static member CtorProxy(bits: int32[]): decimal =\n CreateDecimalBits bits\n\n []\n static member private mathn (v: decimal): MathNumber = As v\n\n []\n static member private un (op: MathNumber -> MathNumber) (v: decimal) = \n DecimalProxy.mathn v\n |> op\n |> As\n\n []\n static member private bin (op: (MathNumber * MathNumber) -> MathNumber) (v1: decimal) (v2: decimal) = \n op (DecimalProxy.mathn v1, DecimalProxy.mathn v2)\n |> As\n\n []\n static member private mul (op: (MathNumber * MathNumber * MathNumber []) -> MathNumber) (v1: decimal) (v2: decimal) = \n op (DecimalProxy.mathn v1, DecimalProxy.mathn v2, [||])\n |> As\n\n []\n static member CtorProxy(v : double) : decimal = WSDecimalMath.Bignumber(MathNumber(v)) |> As\n\n []\n static member CtorProxy(v : int32) : decimal = WSDecimalMath.Bignumber(MathNumber(v)) |> As\n\n []\n static member CtorProxy(v : int64) : decimal = WSDecimalMath.Bignumber(MathNumber(v)) |> As\n\n []\n static member CtorProxy(v : single) : decimal = WSDecimalMath.Bignumber(MathNumber(v)) |> As\n\n []\n static member CtorProxy(v : uint32) : decimal = WSDecimalMath.Bignumber(MathNumber(v)) |> As\n\n []\n static member CtorProxy(v : uint64) : decimal = WSDecimalMath.Bignumber(MathNumber(v)) |> As\n\n []\n static member internal Abs(n : decimal) : decimal = DecimalProxy.un WSDecimalMath.Abs n\n\n []\n static member Add(n1 : decimal, n2 : decimal) : decimal = DecimalProxy.mul WSDecimalMath.Add n1 n2\n\n []\n static member Ceiling(d: decimal) : decimal = DecimalProxy.un WSDecimalMath.Ceil d\n\n []\n static member Compare(n1 : decimal, n2 : decimal) : int = DecimalProxy.bin WSDecimalMath.Compare n1 n2 |> float |> As\n\n []\n member this.CompareTo(n : decimal) : int = DecimalProxy.bin WSDecimalMath.Compare (this |> As) n |> float |> As\n\n []\n member this.CompareTo(n : obj) : int = DecimalProxy.bin WSDecimalMath.Compare (this |> As) (n |> As) |> float |> As\n\n []\n static member Divide(n1 : decimal, n2 : decimal): decimal = DecimalProxy.bin WSDecimalMath.Divide n1 n2\n\n []\n member this.Equals(n : decimal): bool = DecimalProxy.bin WSDecimalMath.Equal (this |> As) n |> As\n\n []\n static member Equals(a: decimal, b : decimal): bool = DecimalProxy.bin WSDecimalMath.Equal a b |> As\n\n []\n static member GreaterThan(a: decimal, b: decimal): bool = DecimalProxy.bin WSDecimalMath.Larger a b |> As\n\n []\n static member LessThan(a: decimal, b: decimal): bool = DecimalProxy.bin WSDecimalMath.Smaller a b |> As\n\n []\n static member Floor(d: decimal) : decimal = DecimalProxy.un WSDecimalMath.Floor d\n\n []\n static member internal Max(n1 : decimal, n2 : decimal): decimal =\n if n1 >= n2 then\n n1\n else\n n2\n\n []\n static member internal Min(n1 : decimal, n2 : decimal): decimal =\n if n1 <= n2 then\n n1\n else\n n2\n\n []\n static member Multiply(n1 : decimal, n2 : decimal): decimal = DecimalProxy.mul WSDecimalMath.Multiply n1 n2\n\n []\n static member Pow(n1 : decimal, n2 : decimal): decimal = DecimalProxy.bin WSDecimalMath.Pow n1 n2\n\n []\n static member Parse(s : string) = WSDecimalMath.Bignumber(MathNumber(s)) |> As\n\n []\n static member TryParse(s: string, [] v: decimal byref) =\n try\n let x = WSDecimalMath.Bignumber(MathNumber(s)) |> As\n v <- x\n true\n with _ ->\n false\n\n []\n static member Remainder(n1 : decimal, n2 : decimal): decimal = DecimalProxy.bin WSDecimalMath.Mod n1 n2\n\n []\n static member Subtract(n1 : decimal, n2 : decimal): decimal = DecimalProxy.bin WSDecimalMath.Subtract n1 n2\n\n []\n member internal this.Sign = DecimalProxy.un WSDecimalMath.Sign (this |> As) |> float |> As\n\n []\n static member Zero: decimal = 0m\n \n []\n static member op_Addition(n1 : decimal, n2 : decimal): decimal = DecimalProxy.Add (n1, n2)\n\n []\n static member op_Division(n1 : decimal, n2 : decimal): decimal = DecimalProxy.bin WSDecimalMath.Divide n1 n2\n\n []\n static member op_Equality(n1 : decimal, n2 : decimal): bool = DecimalProxy.Equals (n1,n2)\n\n []\n static member op_Inequality(n1 : decimal, n2 : decimal): bool = not <| DecimalProxy.Equals (n1,n2)\n\n []\n static member op_GreaterThan(n1:decimal, n2:decimal): bool = DecimalProxy.GreaterThan (n1, n2)\n\n []\n static member op_LessThan(n1:decimal, n2:decimal): bool = DecimalProxy.LessThan (n1, n2)\n\n []\n static member op_GreaterThanOrEqual(n1:decimal, n2:decimal): bool = not <| DecimalProxy.LessThan (n1, n2)\n\n []\n static member op_LessThanOrEqual(n1:decimal, n2:decimal): bool = not <| DecimalProxy.GreaterThan (n1, n2)\n\n []\n static member op_Modulus(n1 : decimal, n2 : decimal): decimal = DecimalProxy.bin WSDecimalMath.Mod n1 n2\n\n []\n static member op_Multiply(n1 : decimal, n2 : decimal): decimal = DecimalProxy.Multiply (n1, n2)\n\n []\n static member op_Exponentiation(n1 : decimal, n2 : decimal): decimal = DecimalProxy.Pow (n1, n2)\n\n []\n static member op_Subtraction(n1 : decimal, n2 : decimal) = DecimalProxy.Subtract (n1,n2)\n\n []\n static member op_UnaryNegation(n : decimal): decimal = DecimalProxy.un WSDecimalMath.UnaryMinus n\n\n []\n static member op_UnaryPlus(n : decimal) : decimal = DecimalProxy.un WSDecimalMath.UnaryPlus n\n\n[]\nmodule internal IntrinsicFunctionProxy =\n\n []\n let MakeDecimal lo med hi isNegative scale = System.Decimal(lo,med,hi,isNegative,scale)\n\n[)>]\ntype private MathProxyForDecimals =\n\n []\n static member Abs(value: decimal) = DecimalProxy.Abs value\n\n []\n static member Sign(value: decimal) = (As value).Sign\n\n []\n static member Max(n1 : decimal, n2 : decimal): decimal = DecimalProxy.Max(n1, n2)\n\n []\n static member Min(n1 : decimal, n2 : decimal): decimal = DecimalProxy.Min(n1, n2)\n\n []\n static member Cei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