Skip to content

Commit e8e8542

Browse files
Priynshfingolfininkydragon
authored andcommitted
docs: fix edge case in rational number conversion float(a//b) (#56772)
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]> (cherry picked from commit fc9e7c4)
1 parent 2f3f27e commit e8e8542

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

doc/src/manual/complex-and-rational-numbers.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,30 @@ julia> float(3//4)
254254
```
255255

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

259259
```jldoctest
260260
julia> a = 1; b = 2;
261261
262262
julia> isequal(float(a//b), a/b)
263263
true
264+
265+
julia> a, b = 0, 0
266+
(0, 0)
267+
268+
julia> float(a//b)
269+
ERROR: ArgumentError: invalid rational: zero(Int64)//zero(Int64)
270+
Stacktrace:
271+
[...]
272+
273+
julia> a/b
274+
NaN
275+
276+
julia> a, b = 0, -1
277+
(0, -1)
278+
279+
julia> float(a//b), a/b
280+
(0.0, -0.0)
264281
```
265282

266283
Constructing infinite rational values is acceptable:

0 commit comments

Comments
 (0)