fix: negated number left as the last expression would fail
This commit is contained in:
parent
8b8c8b9d65
commit
2dbcd7c9eb
@ -1,5 +1,5 @@
|
|||||||
name: mathexpr
|
name: mathexpr
|
||||||
version: 0.2.0.0
|
version: 0.2.0.1
|
||||||
synopsis: Parse and evaluate math expressions with variables and functions
|
synopsis: Parse and evaluate math expressions with variables and functions
|
||||||
description: A simple tool to evaluate math expressions as strings with support for custom functions and operators
|
description: A simple tool to evaluate math expressions as strings with support for custom functions and operators
|
||||||
homepage: https://github.com/mdibaiee/mathexpr
|
homepage: https://github.com/mdibaiee/mathexpr
|
||||||
|
@ -80,6 +80,7 @@ module Data.MathExpr
|
|||||||
helper :: [String] -> [String] -> Double
|
helper :: [String] -> [String] -> Double
|
||||||
-- negative numbers come in the form ["num", "-"]
|
-- negative numbers come in the form ["num", "-"]
|
||||||
helper [] [o] = read o
|
helper [] [o] = read o
|
||||||
|
helper [n, "-"] [] = negate . read $ n
|
||||||
helper (c:cs) os
|
helper (c:cs) os
|
||||||
| c == "-" && length os < 2 =
|
| c == "-" && length os < 2 =
|
||||||
let result :: Double = negate . read . head $ cs
|
let result :: Double = negate . read . head $ cs
|
||||||
|
Loading…
Reference in New Issue
Block a user