Skip to content

Commit 753513a

Browse files
committed
Merge branch 'master' of github.com:JuliaLang/julia
2 parents ede5772 + c75ac02 commit 753513a

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

j/intfuncs.j

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function power_by_squaring(x, p::Int)
7373
elseif p == 0
7474
return one(x)
7575
elseif p < 0
76-
return inv(x^(-p))
76+
error("power_by_squaring: exponent must be >= 0, got $p")
7777
elseif p == 2
7878
return x*x
7979
end
@@ -101,8 +101,8 @@ function power_by_squaring(x, p::Int)
101101
end
102102

103103
^(x, p::Int) = power_by_squaring(x,p)
104-
^(x::Int, p::Int) = power_by_squaring(float64(x),p)
105-
^{T<:Int}(x::T, p::T) = power_by_squaring(float64(x),p)
104+
^(x::Int, p::Int) = p < 0 ? inv(x^(-p)) : power_by_squaring(float64(x),p)
105+
^{T<:Int}(x::T, p::T) = p < 0 ? inv(x^(-p)) : power_by_squaring(float64(x),p)
106106

107107
# x^p mod m
108108
function powermod(x::Int, p::Int, m::Int)

j/operators.j

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ sizeof{T}(x::T) = sizeof(T)
9292
copy(x::ANY) = x
9393
foreach(f::Function, itr) = for x = itr; f(x); end
9494

95+
# function composition
96+
one(f::Function) = identity
97+
one(::Type{Function}) = identity
98+
*(f::Function, g::Function) = x->f(g(x))
99+
95100
# vectorization
96101

97102
macro vectorize_1arg(S,f)

j/rational.j

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ isequal(x::Rational, y::Rational) = x.num == y.num && x.den == y.den
8787
hash(x::Rational) = bitmix(hash(x.num),hash(x.den))
8888
8989
==(x::Rational, y::Rational) = !isnan(x) && x.num == y.num && x.den == y.den
90-
==(x::Rational, y::Int) = x.den == 1 && x.num == y
91-
==(y::Int, x::Rational) = x.den == 1 && x.num == y
90+
==(x::Rational, y::Int) = x.den == 1 && x.num == y
91+
==(y::Int, x::Rational) = x.den == 1 && x.num == y
9292
9393
<=(x::Rational, y::Rational) = float(x) <= float(y) # TODO: better comparison
9494
< (x::Rational, y::Rational) = float(x) < float(y) # TODO: better comparison

j/string.j

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,12 @@ end
219219
length(s::RepString) = length(s.string)*s.repeat
220220
strlen(s::RepString) = strlen(s.string)*s.repeat
221221

222-
repeat(s::String, r::Int) = r <= 0 ? "" :
223-
r == 1 ? s : RepString(s,r)
222+
function repeat(s::String, r::Int)
223+
r < 0 ? error("can't repeat a string ",r," times") :
224+
r == 0 ? "" :
225+
r == 1 ? s :
226+
RepString(s,r)
227+
end
224228

225229
## ropes for efficient concatenation, etc. ##
226230

j/sysimg.j

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ load("table.j")
3030

3131
# compiler
3232
load("inference.j")
33-
ccall(:jl_enable_inference,Void,())
33+
ccall(:jl_enable_inference, Void, ())
3434

3535
# strings & printing
3636
load("io.j")
3737
ccall(:jl_set_memio_func, Void, ())
38-
set_current_output_stream(make_stdout_stream()) # for error reporting
38+
set_current_output_stream(make_stdout_stream()) # for error reporting
3939
load("string.j")
4040
load("ascii.j")
4141
load("utf8.j")
4242
load("show.j")
43-
4443
load("env.j")
4544

4645
# core math functions

src/boot.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ end
269269

270270
append(xs...) = append_any(xs...)
271271

272-
identity = x->x
272+
identity(x) = x
273273

274274
macro thunk(ex); :(()->$ex); end
275275
macro L_str(s); s; end

0 commit comments

Comments
 (0)