Skip to content

Commit

Permalink
Python: added 'Double.IsPositiveInfinity' (#3685)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreYvesR authored Jan 1, 2024
1 parent b7e1e9c commit 3fe0a39
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Python

* Fixed nested type with custom hashcode (by @dbrattli)
* Add 'Double.IsPositiveInfinity' (by @PierreYvesR)

#### Rust

Expand Down
11 changes: 11 additions & 0 deletions src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3850,6 +3850,17 @@ let parseNum
?loc = r
)
|> Some
| "IsPositiveInfinity", [ _ ] when isFloat ->
Helper.LibCall(
com,
"double",
"is_positive_inf",
t,
args,
i.SignatureArgTypes,
?loc = r
)
|> Some
| ("Parse" | "TryParse") as meth,
str :: NumberConst(:? int as style, _, _) :: _ ->
let hexConst = int System.Globalization.NumberStyles.HexNumber
Expand Down
18 changes: 17 additions & 1 deletion src/fable-library-py/fable_library/double.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def sqrt(x: float) -> float:
return float("nan")


def is_positive_inf(value: float) -> bool:
return math.isinf(value) and value > 0


def is_negative_inf(value: float) -> bool:
return math.isinf(value) and value < 0

Expand All @@ -68,4 +72,16 @@ def try_parse(string: str, def_value: FSharpRef[float]) -> bool:
return False


__all__ = ["abs", "sign", "max", "min", "parse", "try_parse", "divide", "log", "sqrt", "is_negative_inf"]
__all__ = [
"abs",
"sign",
"max",
"min",
"parse",
"try_parse",
"divide",
"log",
"sqrt",
"is_negative_inf",
"is_positive_inf",
]
8 changes: 8 additions & 0 deletions tests/Python/TestArithmetic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,5 +1118,13 @@ let ``test extreme values work`` () =
|> Double.IsNegativeInfinity
|> equal false

1.0 / 0.0
|> Double.IsPositiveInfinity
|> equal true

1.0 / (-0.0)
|> Double.IsPositiveInfinity
|> equal false

-infinity < infinity |> equal true
(-0.0) < 0.0 |> equal false

0 comments on commit 3fe0a39

Please sign in to comment.