Document the difference between toFloat/toInt and type conversion (#17894)
This commit is contained in:
parent
d0485e326a
commit
34a09574ce
1 changed files with 3 additions and 2 deletions
|
|
@ -1472,7 +1472,7 @@ type # these work for most platforms:
|
||||||
PInt32* = ptr int32 ## An alias for `ptr int32`.
|
PInt32* = ptr int32 ## An alias for `ptr int32`.
|
||||||
|
|
||||||
proc toFloat*(i: int): float {.noSideEffect, inline.} =
|
proc toFloat*(i: int): float {.noSideEffect, inline.} =
|
||||||
## Converts an integer `i` into a `float`.
|
## Converts an integer `i` into a `float`. Same as `float(i)`.
|
||||||
##
|
##
|
||||||
## If the conversion fails, `ValueError` is raised.
|
## If the conversion fails, `ValueError` is raised.
|
||||||
## However, on most platforms the conversion cannot fail.
|
## However, on most platforms the conversion cannot fail.
|
||||||
|
|
@ -1494,7 +1494,8 @@ proc toInt*(f: float): int {.noSideEffect.} =
|
||||||
##
|
##
|
||||||
## Conversion rounds `f` half away from 0, see
|
## Conversion rounds `f` half away from 0, see
|
||||||
## `Round half away from zero
|
## `Round half away from zero
|
||||||
## <https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero>`_.
|
## <https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero>`_,
|
||||||
|
## as opposed to a type conversion which rounds towards zero.
|
||||||
##
|
##
|
||||||
## Note that some floating point numbers (e.g. infinity or even 1e19)
|
## Note that some floating point numbers (e.g. infinity or even 1e19)
|
||||||
## cannot be accurately converted.
|
## cannot be accurately converted.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue