Skip to content

Commit

Permalink
Update index.md
Browse files Browse the repository at this point in the history
  • Loading branch information
putianyi889 authored Mar 11, 2024
1 parent 04ea37a commit 8683ec6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ precisiontype(Set{Matrix{Vector{Matrix{Complex{Rational{Int}}}}}})
where `some` can be `el`, `base` and `precision`.

### On `precisionconvert`
Since some types (e.g. `BigFloat`) can have variable precision, `precisionconvert` accepts a third argument `prec` which specifies the precision. `prec` defaults to `precision(T)` and has no effect when `T` has a const precision.

When `T` is an integer, the conversion will dig into `Rational` as well. In contrast, since `Rational` as a whole is more "precise" than an integer, `precisiontype` doesn't unwrap `Rational`.
`precisionconvert` accepts an optional third argument `prec`.
- When `T` has static precision, `prec` has no effect.
- When `T` has dynamic precision, `prec` specifies the precision of conversion. When `prec` is not provided, the precision is decided by the external setup from `T`. The difference is significant when `precisionconvert` is called by another function:
```@repl
precision(BigFloat)
f(x) = precisionconvert(BigFloat, x, precision(BigFloat))
g(x) = precisionconvert(BigFloat, x)
setprecision(128)
f(π) # static precision
g(π) # precision varies with the global setting
```
- When `T` is an integer, the conversion will dig into `Rational` as well. In contrast, since `Rational` as a whole is more "precise" than an integer, `precisiontype` doesn't unwrap `Rational`.
```@repl
precisiontype(precisionconvert(Int128, Int8(1)//Int8(2)))
```

0 comments on commit 8683ec6

Please sign in to comment.