Skip to content

Commit

Permalink
parse sqrt symbol (√) as a unary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 10, 2014
1 parent fe994bb commit 56e04cb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ New language features
| == | ≥ (>=) ≤ (<=) ≡ (===) ≠ (!=) ≢ (!==) .≥ (.>=) .≤ (.<=) .!= (.≠) ∈ (`in`) ∉ (`(x,y)->!in(x, y)`) ∋ (`(x,y)->in(y, x)`) ∌ (`(x,y)->!in(y, x)`) ⊆ (`issubset`) ⊈ (`(x,y)->!issubset(x, y)`) ⊊ (`(x,y)->x⊆y && x!=y`) ⊂ ⊄ |
| + | ⊕ ⊖ ⊞ ⊟ ∪ (`union`) ∨ ⊔ |
| * | ÷ (`div`) ⋅ (`dot`) ∘ × (`cross`) ∩ (`intersect`) ∧ ⊓ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ |
| unary ||

Library improvements
--------------------
Expand Down
3 changes: 1 addition & 2 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export sin, cos, tan, sinh, cosh, tanh, asin, acos, atan,
besselj0, besselj1, besselj, bessely0, bessely1, bessely,
hankelh1, hankelh2, besseli, besselk, besselh,
beta, lbeta, eta, zeta, polygamma, invdigamma, digamma, trigamma,
erfinv, erfcinv,
erfinv, erfcinv

import Base: log, exp, sin, cos, tan, sinh, cosh, tanh, asin,
acos, atan, asinh, acosh, atanh, sqrt, log2, log10,
Expand Down Expand Up @@ -284,7 +284,6 @@ sqrt(x::Float64) = box(Float64,sqrt_llvm(unbox(Float64,x)))
sqrt(x::Float32) = box(Float32,sqrt_llvm(unbox(Float32,x)))
sqrt(x::Real) = sqrt(float(x))
@vectorize_1arg Number sqrt
const =sqrt

for f in (:ceil, :trunc, :significand) # :rint, :nearbyint
@eval begin
Expand Down
5 changes: 3 additions & 2 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function ifelse(c::AbstractArray{Bool}, x, y::AbstractArray)
end

# some operators not defined yet
global //, .>>, .<<, >:, <|, |>, hcat, hvcat, , ×, , , , , , , , ,
global //, .>>, .<<, >:, <|, |>, hcat, hvcat, , ×, , , , , , , , , ,

module Operators

Expand Down Expand Up @@ -428,6 +428,7 @@ export
,
,
,
,
colon,
hcat,
vcat,
Expand All @@ -441,6 +442,6 @@ import Base: !, !=, $, %, .%, &, *, +, -, .!=, .+, .-, .*, ./, .<, .<=, .==, .>,
.>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>,
<|, |>, \, ^, |, ~, !==, >:, colon, hcat, vcat, hvcat, getindex, setindex!,
transpose, ctranspose,
, , , .≥, .≤, .≠, ÷, , ×, , , , , , , , ,
, , , .≥, .≤, .≠, ÷, , ×, , , , , , , , , ,

end
1 change: 1 addition & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ include("methodshow.jl")
include("floatfuncs.jl")
include("math.jl")
importall .Math
const ()=sqrt
include("float16.jl")

# multidimensional arrays
Expand Down
4 changes: 2 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
(define (kwarg? e)
(and (pair? e) (eq? (car e) 'kw)))

(define unary-ops '(+ - ! ~ |<:| |>:|))
(define unary-ops '(+ - ! ~ |<:| |>:|))

; operators that are both unary and binary
(define unary-and-binary-ops '(+ - $ & ~))
Expand All @@ -98,7 +98,7 @@
(define ctrans-op (string->symbol "'"))
(define vararg-op (string->symbol "..."))

(define operators (list* '~ '! '-> ctrans-op trans-op vararg-op
(define operators (list* '~ '! '-> '√ ctrans-op trans-op vararg-op
(delete-duplicates
(apply append (vector->list ops-by-prec)))))

Expand Down

0 comments on commit 56e04cb

Please sign in to comment.