Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢

Simon Byrne simonbyrne

🐢
View GitHub Profile
@simonbyrne
simonbyrne / test2.c
Created Jan 30, 2015
detect fma error
View test2.c
include <stdio.h>
#include <stdlib.h>
#include <math.h>
static double fct (double a)
{
double x = fma(a,a,-a);
return 1.0 - x;
}
View sincos.jl
function sincos(x::Float64)
s = Ref{Float64}()
c = Ref{Float64}()
ccall((:sincos,Base.Math.libm),Void,(Float64,Ref{Float64},Ref{Float64}),x,s,c)
return s.x, c.x
end
function test_sep(X)
t = 0.0
View jlug.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simonbyrne
simonbyrne / winenv.jl
Created May 10, 2015
Test windows ENV interfaces
View winenv.jl
function winenvs(var)
# Win: ansi
len = ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,C_NULL,0)
if len > 0
val=zeros(Uint8,len)
ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,val,len)
win_a = bytestring(val)
else
win_a = ""
@simonbyrne
simonbyrne / binary-parse.jl
Created May 26, 2015
Parsing of hex-float and bit-float strings
View binary-parse.jl
# converts bit-float and hex-float strings to floating point numbers
# assumes round-to-nearest
import Base: significand_mask, significand_bits, exponent_bias, tryparse
for B in (2,16)
@eval function tryparse{T<:Float64}(::Type{T}, s::String, ::Type{Val{$B}})
f_neg = false
r_ind = false # radix pt. indicator
r = 0 # no. of places after radix pt.
@simonbyrne
simonbyrne / interpolations_speed.jl
Created Jun 3, 2015
Test performance of interpolations
View interpolations_speed.jl
# based on https://github.com/tlycken/Interpolations.jl/pull/37
Pkg.checkout("Interpolations", "master")
Pkg.checkout("Ratios", "checked")
using Interpolations, Grid
A = rand(300,300,30);
itp = interpolate!(copy(A), BSpline(Quadratic(Flat)), OnCell);
yi = InterpGrid(copy(A), BCreflect, InterpQuadratic);
View svgfail.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View build 0.4.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@simonbyrne
simonbyrne / newparse.jl
Last active Apr 25, 2016
integer parsing
View newparse.jl
import Base: checked_add, checked_mul
function newparse{T}(::Type{T}, s, base=0)
0 <= base <= 62 || throw(ParseError("Invalid base"))
en = endof(s)
i = start(s)
done(s,i) && throw(ParseError("Invalid $T"))
c,i = next(s,i)