mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
Update rest of standard library for Numeric (#3063)
* Update rest of standard library for Numeric * Fix position of CPP pragma
This commit is contained in:
parent
78c2ec2f25
commit
125317cff0
@ -1,6 +1,8 @@
|
||||
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
|
||||
-- SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
daml 1.2
|
||||
-- | Math - Utility Math functions for `Decimal`
|
||||
-- The this library is designed to give good precision, typically giving 9 correct decimal places.
|
||||
@ -125,7 +127,13 @@ tan x = s / c
|
||||
(c, s) = cordic 34 x
|
||||
|
||||
-- | The number Pi
|
||||
pi = 3.1415926536
|
||||
#ifdef DAML_NUMERIC
|
||||
pi : Numeric n
|
||||
pi = 3.14159_26535_89793_23846_26433_83279_50288_41
|
||||
#else
|
||||
pi : Decimal
|
||||
pi = 3.14159_26536
|
||||
#endif
|
||||
|
||||
-- | `cordic` is an implementation of the CORDIC algorithm.
|
||||
-- See https://en.wikipedia.org/wiki/CORDIC
|
||||
|
@ -1,6 +1,8 @@
|
||||
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
|
||||
-- SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
daml 1.2
|
||||
-- | Functions for working with Text.
|
||||
module DA.Text
|
||||
@ -44,6 +46,9 @@ module DA.Text
|
||||
, DA.Text.isAlpha
|
||||
, DA.Text.isAlphaNum
|
||||
, DA.Text.parseInt
|
||||
#ifdef DAML_NUMERIC
|
||||
, DA.Text.parseNumeric
|
||||
#endif
|
||||
, DA.Text.parseDecimal
|
||||
, DA.Text.sha256
|
||||
, DA.Text.toCodePoints
|
||||
@ -257,6 +262,22 @@ isAlphaNum = isPred (\t -> t >= "0" && t <= "9" || t >= "a" && t <= "z" || t >=
|
||||
parseInt : Text -> Optional Int
|
||||
parseInt = primitive @"BEInt64FromText"
|
||||
|
||||
#ifdef DAML_NUMERIC
|
||||
-- | Attempt to parse a `Numeric` value from a given `Text`.
|
||||
-- To get `Some` value, the text must follow the regex
|
||||
-- `(-|\+)?[0-9]+(\.[0-9]+)?`
|
||||
-- In particular, the shorthands `".12"` and `"12."` do not work,
|
||||
-- but the value can be prefixed with `+`.
|
||||
-- Leading and trailing zeros are fine, however spaces are not.
|
||||
-- Examples:
|
||||
-- ```
|
||||
-- parseNumeric "3.14" == Some 3.14
|
||||
-- parseNumeric "+12.0" == Some 12
|
||||
-- ```
|
||||
parseNumeric : Text -> Optional (Numeric n)
|
||||
parseNumeric = primitive @"BENumericFromText"
|
||||
#endif
|
||||
|
||||
-- | Attempt to parse a `Decimal` value from a given `Text`.
|
||||
-- To get `Some` value, the text must follow the regex
|
||||
-- `(-|\+)?[0-9]+(\.[0-9]+)?`
|
||||
@ -269,7 +290,11 @@ parseInt = primitive @"BEInt64FromText"
|
||||
-- parseDecimal "+12.0" == Some 12
|
||||
-- ```
|
||||
parseDecimal : Text -> Optional Decimal
|
||||
#ifdef DAML_NUMERIC
|
||||
parseDecimal = parseNumeric
|
||||
#else
|
||||
parseDecimal = primitive @"BEDecimalFromText"
|
||||
#endif
|
||||
|
||||
-- | Computes the SHA256 of the UTF8 bytes of the `Text`, and returns it in its hex-encoded
|
||||
-- form. The hex encoding uses lowercase letters.
|
||||
|
Loading…
Reference in New Issue
Block a user