Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add irrational constant ° = pi/180, for converting degrees to radians #16765

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ Library improvements
package provides the old-style `handler` functionality, for compatibility
with code that needs to support both Julia v0.4 and v0.5.

* New `°` constant (which can be typed by tab-completing `\degree`) equal
to `π/180`, useful for defining angles in degrees, e.g. `30°`, in a way
that is automatically converted to radians.

* The functions `remotecall`, `remotecall_fetch`, and `remotecall_wait` now have the
function argument as the first argument to allow for do-block syntax ([#13338]).

Expand Down
4 changes: 3 additions & 1 deletion base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5349,7 +5349,9 @@ readlink
"""
deg2rad(x)

Convert `x` from degrees to radians.
Convert `x` from degrees to radians. Note that the constant `°` is
also useful for this purpose: it is defined as ``π/180``, so multiplying
by it converts degrees to radians, e.g. `30°` gives the angle ``π/6``.
"""
deg2rad

Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export
γ, eulergamma,
catalan,
φ, golden,
°,
I,

# Operators
Expand Down
1 change: 1 addition & 0 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ big(x::Irrational) = convert(BigFloat,x)
@irrational γ 0.57721566490153286061 euler
@irrational catalan 0.91596559417721901505 catalan
@irrational φ 1.61803398874989484820 (1+sqrt(big(5)))/2
@irrational ° 0.0174532925199432957692 big(π)/180

# aliases
const pi = π
Expand Down
6 changes: 5 additions & 1 deletion doc/stdlib/numbers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ General Number Functions and Constants

The golden ratio

.. data:: °

The constant π/180, useful for converting degrees to radians.
For example, ``30°`` gives the angle π/6.

.. data:: Inf

Positive infinity of type ``Float64``
Expand Down Expand Up @@ -599,4 +604,3 @@ As ``BigInt`` represents unbounded integers, the interval must be specified (e.g
Create an array of the size ``jumps`` of initialized ``MersenneTwister`` RNG objects where the first RNG object given as a parameter and following ``MersenneTwister`` RNGs in the array initialized such that a state of the RNG object in the array would be moved forward (without generating numbers) from a previous RNG object array element on a particular number of steps encoded by the jump polynomial ``jumppoly``\ .

Default jump polynomial moves forward ``MersenneTwister`` RNG state by 10^20 steps.

2 changes: 2 additions & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -801,5 +801,7 @@ let A = [1 2; 3 4]; B = [5 6; 7 8]; C = [9 10; 11 12]
@test muladd(A,B,C) == A*B + C
end

@test sin(37°) ≈ sind(37)

@test Base.Math.f32(complex(1.0,1.0)) == complex(Float32(1.),Float32(1.))
@test Base.Math.f16(complex(1.0,1.0)) == complex(Float16(1.),Float16(1.))