Skip to content

Commit

Permalink
Add √ as synonym for sqrt
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahao committed Apr 19, 2014
1 parent 0625671 commit 2a26899
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ export
unsigned,
widemul,
zero,
,

# specfun
airy,
Expand Down
3 changes: 2 additions & 1 deletion 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 @@ -279,6 +279,7 @@ 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

1 comment on commit 2a26899

@jiahao
Copy link
Member Author

@jiahao jiahao commented on 2a26899 Apr 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried to add the infix version for other surds (e.g. 3 √ x for the cube root) but it seems to unilaterally overwrite this other definition for sqrt.

diff --git a/base/math.jl b/base/math.jl
index d9e79dc..39eb758 100644
--- a/base/math.jl
+++ b/base/math.jl
@@ -20,7 +20,7 @@ export sin, cos, tan, sinh, cosh, tanh, asin, acos, atan,

 import Base: log, exp, sin, cos, tan, sinh, cosh, tanh, asin,
              acos, atan, asinh, acosh, atanh, sqrt, log2, log10,
-             max, min, minmax, ceil, floor, trunc, round, ^, exp2, exp10
+             max, min, minmax, ceil, floor, trunc, round, ^, exp2, exp10, √

 import Core.Intrinsics: nan_dom_err, sqrt_llvm, box, unbox, powi_llvm

diff --git a/base/operators.jl b/base/operators.jl
index c9f9382..de8682e 100644
--- a/base/operators.jl
+++ b/base/operators.jl
@@ -111,6 +111,7 @@ fld{T<:Real}(x::T, y::T) = convert(T,round((x-mod(x,y))/y))
 const % = rem
 .%(x::Real, y::Real) = x%y
 const ⊗ = kron
+√{T<:Number}(x::Number, y::T) = x^(one(T)/y)

 # mod returns in [0,y) whereas mod1 returns in (0,y]
 mod1{T<:Real}(x::T, y::T) = y-mod(y-x,y)
@@ -398,6 +399,7 @@ export
     <|,
     ~,
     ⊗,
+    √,
     colon,
     hcat,
     vcat,
diff --git a/src/julia-parser.scm b/src/julia-parser.scm
index 55c391c..7e366cd 100644
--- a/src/julia-parser.scm
+++ b/src/julia-parser.scm
@@ -14,7 +14,7 @@
      (<< >> >>> |.<<| |.>>| |.>>>|)
      (* / |./| % |.%| & ⊗ |.*| |\\| |.\\|)
      (// .//)
-     (^ |.^|)
+     (^ √ |.^|)
      (|::|)
      (|.|)))

Please sign in to comment.