Skip to content

Instantly share code, notes, and snippets.

View simonbyrne's full-sized avatar
🦘

Simon Byrne simonbyrne

🦘
View GitHub Profile
@simonbyrne
simonbyrne / test2.c
Created January 30, 2015 11:16
detect fma error
include <stdio.h>
#include <stdlib.h>
#include <math.h>
static double fct (double a)
{
double x = fma(a,a,-a);
return 1.0 - x;
}
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
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 08:54
Test windows ENV interfaces
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 15:07
Parsing of hex-float and bit-float strings
# 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 June 3, 2015 10:51
Test performance of interpolations
# 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);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 April 25, 2016 16:12
integer parsing
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)