You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-3Lines changed: 39 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,16 @@
7
7
8
8
# Introduction
9
9
10
-
This package introduces the type `PiTimes` that automatically uses the functions `sinpi` and `cospi` instead of `sin` and `cos` to produce accurate results by avoiding floating-point inaccuracies to some extent. It also provides the constant `Pi` for convenience, defined as `PiTimes(1)`, which behaves like `pi` except it produces results with higher accuracy in certain trigonometric contexts.
10
+
This package exports the type `PiExpTimes{N}` that behaves as a multipying factor of `π^N`, and the type `PiTimes` that is aliased to `PiExpTimes{1}`. It also provides the constant `Pi` for convenience, defined as `PiTimes(1)`, which behaves like `π` except it produces results with higher accuracy in certain trigonometric and algebraic contexts.
11
+
12
+
In most scenarios the numbers `Pi` and `pi` are interchangable.
13
+
14
+
```julia
15
+
julia> Pi^2== π^2
16
+
true
17
+
```
18
+
19
+
It's usually possible, and cleaner, to express mathematical relations in terms of `Pi` instead of the more cumbersome `PiExpTimes`, and is recommended unless it's specifically necessary.
We may also simplify algebraic expressions involving powers of `Pi` as
40
+
41
+
```julia
42
+
julia> (2Pi^2//3) // (4Pi//5)
43
+
(5//6)Pi
44
+
45
+
julia> Pi^-2/4Pi^3
46
+
0.25*Pi^-5
47
+
```
48
+
49
+
The powers of `Pi` cancel as expected, and `Pi^0` is automatically converted to an ordinary real number wherever possible.
50
+
51
+
```julia
52
+
julia> Pi^2/ Pi^2
53
+
1.0
54
+
```
55
+
56
+
Expressions involving `Pi` are automatically promoted to `Complex` as necessary, eg.
57
+
58
+
```julia
59
+
julia> (1+im)Pi^3/2Pi^2
60
+
0.5*Pi +0.5*Pi*im
61
+
62
+
julia> (1+im)Pi^3/2Pi^2*2/Pi
63
+
1.0+1.0im
64
+
```
65
+
30
66
## Trigonometric functions
31
67
32
-
The `PiTimes` type uses `sinpi` and `cospi` under the hood when it is used as an argument to `sin` and `cos`. This results in exact results in several contexts where the inaccuracies arise from floating-point conversions.
68
+
The type `PiTimes` uses `sinpi` and `cospi` under the hood when it is used as an argument to `sin` and `cos`. This results in exact results in several contexts where the inaccuracies arise from floating-point conversions.
33
69
34
70
```julia
35
71
julia>cos(3π/2)
@@ -51,7 +87,7 @@ julia> tan(Pi/2)
51
87
Inf
52
88
```
53
89
54
-
It automatically promotes to `Complex` as necessary, so we may compute complex exponentials exactly for some arguments:
0 commit comments