Skip to content

Instantly share code, notes, and snippets.

View iskandr's full-sized avatar

Alex Rubinsteyn iskandr

View GitHub Profile
@iskandr
iskandr / hw3.adb
Created October 11, 2011 06:08
Polynomials specification
with Ada.Text_IO, Ada.Command_line, Ada.Assertions;
use Ada.Text_IO, Ada.Assertions;
with Polynomials;
use Polynomials;
-- Test file format:
-- # comments start with hash character
-- 1.0 X 1 Y 2 2.0 X 2 Y 0
-- +
-- 1.0 X 1 Y 2
@iskandr
iskandr / bigfloat.cpp
Created December 13, 2011 19:22
PL HW5: Arbitrary precision floats in C++
const int base = 10000;
class BigFloat {
public:
// default constructor, initialize to 0
BigFloat () : _sign(1), _exp(0) { }
// initialize with preallocated mantissa
BigFloat (char s, int e, const Mantissa& m) :_sign(s), _exp(e), _mantissa(m) {}
@iskandr
iskandr / 1.scm
Created December 14, 2011 18:49
PL HW6: Scheme
(define (weave xs ys zs)
(if
(or (null? xs) (null? ys) (null? zs))
'()
(cons (list (car xs) (car ys) (car zs))
(weave (cdr xs) (cdr ys) (cdr zs)))))
@iskandr
iskandr / iter.sml
Created December 14, 2011 23:34
logical operators
val rec iter = fn 0 => (fn f => fn x => x) | n => (fn f => fn x => (f o (iter (n-1) f)) x);
@iskandr
iskandr / twice.asm
Last active December 11, 2015 19:58
.globl twice.2
.align 16, 0x90
twice.2:
addsd %xmm0, %xmm0
ret
define double @twice.2(double %x.31) nounwind {
entry:
%multiply_result = fmul double %x.31, 2.000000e+00
ret double %multiply_result
}
def twice.2(x :: float64):
return mul<float64>(2.0 :: float64, x :: float64)
@iskandr
iskandr / twice.py
Last active December 11, 2015 19:58
@parakeet.jit
def twice(x):
return 2*x
def twice(x):
return mul(2, x)
@parakeet.jit
def count_thresh(vec, thresh):
"""
Given a vector of values, counts the number of
elements greater, less, or equal to a threshold
"""
n_less = 0
n_greater = 0
n_eq = 0
for elt in vec: