Last active
August 29, 2015 14:10
-
-
Save waTeim/4118fe8c6e96e14728bf to your computer and use it in GitHub Desktop.
Try/catch vs NaN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function t1(x::Float64) | |
if x == 100_000_000 throw(DomainError()); end | |
return x; | |
end | |
function t2(x::Float64) | |
if x == 100_000_000 | |
return NaN; | |
else | |
return x; | |
end | |
end | |
function ttc1() | |
x::Float64 = 1; | |
try | |
for i = 1:100_000_000 | |
x = x + t1(Float64(i)); | |
end | |
catch e | |
println(e); | |
end | |
println("x = ",x); | |
end | |
function ttc2() | |
x::Float64 = 1; | |
for i = 1:99_999_999 | |
x = x + t2(Float64(i)); | |
end | |
println("x = ",x); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> code_native(t1,(Float64,)) | |
.section __TEXT,__text,regular,pure_instructions | |
Filename: /Users/jeffw/src/errata/julia/tc.jl | |
Source line: 2 | |
push RBP | |
mov RBP, RSP | |
movabs RAX, 4379473120 | |
Source line: 2 | |
vucomisd XMM0, QWORD PTR [RAX] | |
jne L35 | |
jp L35 | |
jmpq L37 | |
Source line: 3 | |
L35: pop RBP | |
ret | |
Source line: 2 | |
L37: movabs RAX, jl_throw_with_superfluous_argument | |
movabs RDI, 140382533282848 | |
mov ESI, 2 | |
call RAX | |
julia> code_native(t2,(Float64,1)) | |
ERROR: `code_native` has no method matching code_native(::Function, ::(DataType,Int64)) | |
julia> code_native(t2,(Float64,)) | |
.section __TEXT,__text,regular,pure_instructions | |
Filename: /Users/jeffw/src/errata/julia/tc.jl | |
Source line: 7 | |
push RBP | |
mov RBP, RSP | |
movabs RAX, 4379476112 | |
Source line: 7 | |
vucomisd XMM0, QWORD PTR [RAX] | |
jne L44 | |
jp L44 | |
movabs RAX, 4379476120 | |
vmovsd XMM0, QWORD PTR [RAX] | |
Source line: 10 | |
L44: pop RBP | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment