Skip to content

Commit

Permalink
docs: fix edge case in rational number conversion float(a//b) (#56772)
Browse files Browse the repository at this point in the history
Fixes #56726 added the changes that were suggested. fixing the mistake.

---------

Co-authored-by: Max Horn <[email protected]>
Co-authored-by: Chengyu Han <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent 31ace71 commit fc9e7c4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion doc/src/manual/complex-and-rational-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,30 @@ julia> float(3//4)
```

Conversion from rational to floating-point respects the following identity for any integral values
of `a` and `b`, with the exception of the two cases `b == 0` and `a == 0 && b < 0`:
of `a` and `b`, except when `a==0 && b <= 0`:

```jldoctest
julia> a = 1; b = 2;
julia> isequal(float(a//b), a/b)
true
julia> a, b = 0, 0
(0, 0)
julia> float(a//b)
ERROR: ArgumentError: invalid rational: zero(Int64)//zero(Int64)
Stacktrace:
[...]
julia> a/b
NaN
julia> a, b = 0, -1
(0, -1)
julia> float(a//b), a/b
(0.0, -0.0)
```

Constructing infinite rational values is acceptable:
Expand Down

0 comments on commit fc9e7c4

Please sign in to comment.