Index: uspace/lib/softfloat/generic/conversion.c
===================================================================
--- uspace/lib/softfloat/generic/conversion.c	(revision 9539be6c880110557328e7e518cf276b94c1b07f)
+++ uspace/lib/softfloat/generic/conversion.c	(revision e0e922d523b4ec1bf5cfea5e330ce8ba19e59850)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2005 Josef Cejka
+ * Copyright (c) 2011 Petr Koupy
  * All rights reserved.
  *
@@ -30,11 +31,11 @@
  * @{
  */
-/** @file
- */
-
-#include "sftypes.h"
-#include "conversion.h"
-#include "comparison.h"
-#include "common.h"
+/** @file Conversion of precision and conversion between integers and floats.
+ */
+
+#include <sftypes.h>
+#include <conversion.h>
+#include <comparison.h>
+#include <common.h>
 
 float64 convertFloat32ToFloat64(float32 a) 
@@ -48,8 +49,8 @@
 	
 	if ((isFloat32Infinity(a)) || (isFloat32NaN(a))) {
-		result.parts.exp = 0x7FF;
+		result.parts.exp = FLOAT64_MAX_EXPONENT;
 		/* TODO; check if its correct for SigNaNs*/
 		return result;
-	};
+	}
 	
 	result.parts.exp = a.parts.exp + ((int) FLOAT64_BIAS - FLOAT32_BIAS);
@@ -57,6 +58,6 @@
 		/* normalize denormalized numbers */
 
-		if (result.parts.fraction == 0ll) { /* fix zero */
-			result.parts.exp = 0ll;
+		if (result.parts.fraction == 0) { /* fix zero */
+			result.parts.exp = 0;
 			return result;
 		}
@@ -64,15 +65,114 @@
 		frac = result.parts.fraction;
 		
-		while (!(frac & (0x10000000000000ll))) {
+		while (!(frac & FLOAT64_HIDDEN_BIT_MASK)) {
 			frac <<= 1;
 			--result.parts.exp;
-		};
+		}
 		
 		++result.parts.exp;
 		result.parts.fraction = frac;
-	};
-	
-	return result;
-	
+	}
+	
+	return result;
+}
+
+float128 convertFloat32ToFloat128(float32 a)
+{
+	float128 result;
+	uint64_t frac_hi, frac_lo;
+	uint64_t tmp_hi, tmp_lo;
+
+	result.parts.sign = a.parts.sign;
+	result.parts.frac_hi = 0;
+	result.parts.frac_lo = a.parts.fraction;
+	lshift128(result.parts.frac_hi, result.parts.frac_lo,
+	    (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE),
+	    &frac_hi, &frac_lo);
+	result.parts.frac_hi = frac_hi;
+	result.parts.frac_lo = frac_lo;
+
+	if ((isFloat32Infinity(a)) || (isFloat32NaN(a))) {
+		result.parts.exp = FLOAT128_MAX_EXPONENT;
+		/* TODO; check if its correct for SigNaNs*/
+		return result;
+	}
+
+	result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT32_BIAS);
+	if (a.parts.exp == 0) {
+		/* normalize denormalized numbers */
+
+		if (eq128(result.parts.frac_hi,
+		    result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */
+			result.parts.exp = 0;
+			return result;
+		}
+
+		frac_hi = result.parts.frac_hi;
+		frac_lo = result.parts.frac_lo;
+
+		and128(frac_hi, frac_lo,
+		    FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
+		    &tmp_hi, &tmp_lo);
+		while (!lt128(0x0ll, 0x0ll, tmp_hi, tmp_lo)) {
+			lshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
+			--result.parts.exp;
+		}
+
+		++result.parts.exp;
+		result.parts.frac_hi = frac_hi;
+		result.parts.frac_lo = frac_lo;
+	}
+
+	return result;
+}
+
+float128 convertFloat64ToFloat128(float64 a)
+{
+	float128 result;
+	uint64_t frac_hi, frac_lo;
+	uint64_t tmp_hi, tmp_lo;
+
+	result.parts.sign = a.parts.sign;
+	result.parts.frac_hi = 0;
+	result.parts.frac_lo = a.parts.fraction;
+	lshift128(result.parts.frac_hi, result.parts.frac_lo,
+	    (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE),
+	    &frac_hi, &frac_lo);
+	result.parts.frac_hi = frac_hi;
+	result.parts.frac_lo = frac_lo;
+
+	if ((isFloat64Infinity(a)) || (isFloat64NaN(a))) {
+		result.parts.exp = FLOAT128_MAX_EXPONENT;
+		/* TODO; check if its correct for SigNaNs*/
+		return result;
+	}
+
+	result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT64_BIAS);
+	if (a.parts.exp == 0) {
+		/* normalize denormalized numbers */
+
+		if (eq128(result.parts.frac_hi,
+		    result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */
+			result.parts.exp = 0;
+			return result;
+		}
+
+		frac_hi = result.parts.frac_hi;
+		frac_lo = result.parts.frac_lo;
+
+		and128(frac_hi, frac_lo,
+		    FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
+		    &tmp_hi, &tmp_lo);
+		while (!lt128(0x0ll, 0x0ll, tmp_hi, tmp_lo)) {
+			lshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
+			--result.parts.exp;
+		}
+
+		++result.parts.exp;
+		result.parts.frac_hi = frac_hi;
+		result.parts.frac_lo = frac_lo;
+	}
+
+	return result;
 }
 
@@ -86,32 +186,31 @@
 	
 	if (isFloat64NaN(a)) {
-		
-		result.parts.exp = 0xFF;
+		result.parts.exp = FLOAT32_MAX_EXPONENT;
 		
 		if (isFloat64SigNaN(a)) {
-			result.parts.fraction = 0x400000; /* set first bit of fraction nonzero */
+			/* set first bit of fraction nonzero */
+			result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1;
 			return result;
 		}
-	
-		result.parts.fraction = 0x1; /* fraction nonzero but its first bit is zero */
-		return result;
-	};
+
+		/* fraction nonzero but its first bit is zero */
+		result.parts.fraction = 0x1;
+		return result;
+	}
 
 	if (isFloat64Infinity(a)) {
 		result.parts.fraction = 0;
-		result.parts.exp = 0xFF;
-		return result;
-	};
-
-	exp = (int)a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS;
-	
-	if (exp >= 0xFF) {
-		/*FIXME: overflow*/
+		result.parts.exp = FLOAT32_MAX_EXPONENT;
+		return result;
+	}
+
+	exp = (int) a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS;
+	
+	if (exp >= FLOAT32_MAX_EXPONENT) {
+		/* FIXME: overflow */
 		result.parts.fraction = 0;
-		result.parts.exp = 0xFF;
-		return result;
-		
-	} else if (exp <= 0 ) {
-		
+		result.parts.exp = FLOAT32_MAX_EXPONENT;
+		return result;
+	} else if (exp <= 0) {
 		/* underflow or denormalized */
 		
@@ -119,14 +218,14 @@
 		
 		exp *= -1;	
-		if (exp > FLOAT32_FRACTION_SIZE ) {
+		if (exp > FLOAT32_FRACTION_SIZE) {
 			/* FIXME: underflow */
 			result.parts.fraction = 0;
 			return result;
-		};
+		}
 		
 		/* denormalized */
 		
 		frac = a.parts.fraction; 
-		frac |= 0x10000000000000ll; /* denormalize and set hidden bit */
+		frac |= FLOAT64_HIDDEN_BIT_MASK; /* denormalize and set hidden bit */
 		
 		frac >>= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1);
@@ -135,19 +234,179 @@
 			--exp;
 			frac >>= 1;
-		};
+		}
 		result.parts.fraction = frac;
 		
 		return result;
-	};
+	}
 
 	result.parts.exp = exp;
-	result.parts.fraction = a.parts.fraction >> (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE);
-	return result;
-}
-
-
-/** Helping procedure for converting float32 to uint32
- * @param a floating point number in normalized form (no NaNs or Inf are checked )
- * @return unsigned integer
+	result.parts.fraction =
+	    a.parts.fraction >> (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE);
+	return result;
+}
+
+float32 convertFloat128ToFloat32(float128 a)
+{
+	float32 result;
+	int32_t exp;
+	uint64_t frac_hi, frac_lo;
+
+	result.parts.sign = a.parts.sign;
+
+	if (isFloat128NaN(a)) {
+		result.parts.exp = FLOAT32_MAX_EXPONENT;
+
+		if (isFloat128SigNaN(a)) {
+			/* set first bit of fraction nonzero */
+			result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1;
+			return result;
+		}
+
+		/* fraction nonzero but its first bit is zero */
+		result.parts.fraction = 0x1;
+		return result;
+	}
+
+	if (isFloat128Infinity(a)) {
+		result.parts.fraction = 0;
+		result.parts.exp = FLOAT32_MAX_EXPONENT;
+		return result;
+	}
+
+	exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT32_BIAS;
+
+	if (exp >= FLOAT32_MAX_EXPONENT) {
+		/* FIXME: overflow */
+		result.parts.fraction = 0;
+		result.parts.exp = FLOAT32_MAX_EXPONENT;
+		return result;
+	} else if (exp <= 0) {
+		/* underflow or denormalized */
+
+		result.parts.exp = 0;
+
+		exp *= -1;
+		if (exp > FLOAT32_FRACTION_SIZE) {
+			/* FIXME: underflow */
+			result.parts.fraction = 0;
+			return result;
+		}
+
+		/* denormalized */
+
+		frac_hi = a.parts.frac_hi;
+		frac_lo = a.parts.frac_lo;
+
+		/* denormalize and set hidden bit */
+		frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
+
+		rshift128(frac_hi, frac_lo,
+		    (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1),
+		    &frac_hi, &frac_lo);
+
+		while (exp > 0) {
+			--exp;
+			rshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
+		}
+		result.parts.fraction = frac_lo;
+
+		return result;
+	}
+
+	result.parts.exp = exp;
+	frac_hi = a.parts.frac_hi;
+	frac_lo = a.parts.frac_lo;
+	rshift128(frac_hi, frac_lo,
+	    (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1),
+	    &frac_hi, &frac_lo);
+	result.parts.fraction = frac_lo;
+	return result;
+}
+
+float64 convertFloat128ToFloat64(float128 a)
+{
+	float64 result;
+	int32_t exp;
+	uint64_t frac_hi, frac_lo;
+
+	result.parts.sign = a.parts.sign;
+
+	if (isFloat128NaN(a)) {
+		result.parts.exp = FLOAT64_MAX_EXPONENT;
+
+		if (isFloat128SigNaN(a)) {
+			/* set first bit of fraction nonzero */
+			result.parts.fraction = FLOAT64_HIDDEN_BIT_MASK >> 1;
+			return result;
+		}
+
+		/* fraction nonzero but its first bit is zero */
+		result.parts.fraction = 0x1;
+		return result;
+	}
+
+	if (isFloat128Infinity(a)) {
+		result.parts.fraction = 0;
+		result.parts.exp = FLOAT64_MAX_EXPONENT;
+		return result;
+	}
+
+	exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT64_BIAS;
+
+	if (exp >= FLOAT64_MAX_EXPONENT) {
+		/* FIXME: overflow */
+		result.parts.fraction = 0;
+		result.parts.exp = FLOAT64_MAX_EXPONENT;
+		return result;
+	} else if (exp <= 0) {
+		/* underflow or denormalized */
+
+		result.parts.exp = 0;
+
+		exp *= -1;
+		if (exp > FLOAT64_FRACTION_SIZE) {
+			/* FIXME: underflow */
+			result.parts.fraction = 0;
+			return result;
+		}
+
+		/* denormalized */
+
+		frac_hi = a.parts.frac_hi;
+		frac_lo = a.parts.frac_lo;
+
+		/* denormalize and set hidden bit */
+		frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
+
+		rshift128(frac_hi, frac_lo,
+		    (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE + 1),
+		    &frac_hi, &frac_lo);
+
+		while (exp > 0) {
+			--exp;
+			rshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
+		}
+		result.parts.fraction = frac_lo;
+
+		return result;
+	}
+
+	result.parts.exp = exp;
+	frac_hi = a.parts.frac_hi;
+	frac_lo = a.parts.frac_lo;
+	rshift128(frac_hi, frac_lo,
+	    (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE + 1),
+	    &frac_hi, &frac_lo);
+	result.parts.fraction = frac_lo;
+	return result;
+}
+
+
+/** 
+ * Helping procedure for converting float32 to uint32.
+ *
+ * @param a Floating point number in normalized form
+ *     (NaNs or Inf are not checked).
+ * @return Converted unsigned integer.
  */
 static uint32_t _float32_to_uint32_helper(float32 a)
@@ -156,5 +415,5 @@
 	
 	if (a.parts.exp < FLOAT32_BIAS) {
-		/*TODO: rounding*/
+		/* TODO: rounding */
 		return 0;
 	}
@@ -175,5 +434,5 @@
 }
 
-/* Convert float to unsigned int32
+/* 
  * FIXME: Im not sure what to return if overflow/underflow happens 
  * 	- now its the biggest or the smallest int
@@ -194,5 +453,5 @@
 }
 
-/* Convert float to signed int32
+/* 
  * FIXME: Im not sure what to return if overflow/underflow happens 
  * 	- now its the biggest or the smallest int
@@ -214,22 +473,96 @@
 
 
-/** Helping procedure for converting float64 to uint64
- * @param a floating point number in normalized form (no NaNs or Inf are checked )
- * @return unsigned integer
+/**
+ * Helping procedure for converting float32 to uint64.
+ *
+ * @param a Floating point number in normalized form
+ *     (NaNs or Inf are not checked).
+ * @return Converted unsigned integer.
+ */
+static uint64_t _float32_to_uint64_helper(float32 a)
+{
+	uint64_t frac;
+
+	if (a.parts.exp < FLOAT32_BIAS) {
+		/*TODO: rounding*/
+		return 0;
+	}
+
+	frac = a.parts.fraction;
+
+	frac |= FLOAT32_HIDDEN_BIT_MASK;
+	/* shift fraction to left so hidden bit will be the most significant bit */
+	frac <<= 64 - FLOAT32_FRACTION_SIZE - 1;
+
+	frac >>= 64 - (a.parts.exp - FLOAT32_BIAS) - 1;
+	if ((a.parts.sign == 1) && (frac != 0)) {
+		frac = ~frac;
+		++frac;
+	}
+
+	return frac;
+}
+
+/* 
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+uint64_t float32_to_uint64(float32 a)
+{
+	if (isFloat32NaN(a))
+		return UINT64_MAX;
+
+
+	if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
+		if (a.parts.sign)
+			return UINT64_MIN;
+
+		return UINT64_MAX;
+	}
+
+	return _float32_to_uint64_helper(a);
+}
+
+/* 
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+int64_t float32_to_int64(float32 a)
+{
+	if (isFloat32NaN(a))
+		return INT64_MAX;
+
+	if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
+		if (a.parts.sign)
+			return INT64_MIN;
+
+		return INT64_MAX;
+	}
+
+	return _float32_to_uint64_helper(a);
+}
+
+
+/**
+ * Helping procedure for converting float64 to uint64.
+ *
+ * @param a Floating point number in normalized form
+ *     (NaNs or Inf are not checked).
+ * @return Converted unsigned integer.
  */
 static uint64_t _float64_to_uint64_helper(float64 a)
 {
 	uint64_t frac;
-	
+
 	if (a.parts.exp < FLOAT64_BIAS) {
 		/*TODO: rounding*/
 		return 0;
 	}
-	
+
 	frac = a.parts.fraction;
-	
+
 	frac |= FLOAT64_HIDDEN_BIT_MASK;
 	/* shift fraction to left so hidden bit will be the most significant bit */
-	frac <<= 64 - FLOAT64_FRACTION_SIZE - 1; 
+	frac <<= 64 - FLOAT64_FRACTION_SIZE - 1;
 
 	frac >>= 64 - (a.parts.exp - FLOAT64_BIAS) - 1;
@@ -238,9 +571,48 @@
 		++frac;
 	}
-	
+
 	return frac;
 }
 
-/* Convert float to unsigned int64
+/*
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+uint32_t float64_to_uint32(float64 a)
+{
+	if (isFloat64NaN(a))
+		return UINT32_MAX;
+
+	if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
+		if (a.parts.sign)
+			return UINT32_MIN;
+
+		return UINT32_MAX;
+	}
+
+	return (uint32_t) _float64_to_uint64_helper(a);
+}
+
+/*
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+int32_t float64_to_int32(float64 a)
+{
+	if (isFloat64NaN(a))
+		return INT32_MAX;
+
+	if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
+		if (a.parts.sign)
+			return INT32_MIN;
+
+		return INT32_MAX;
+	}
+
+	return (int32_t) _float64_to_uint64_helper(a);
+}
+
+
+/* 
  * FIXME: Im not sure what to return if overflow/underflow happens 
  * 	- now its the biggest or the smallest int
@@ -251,5 +623,4 @@
 		return UINT64_MAX;
 	
-	
 	if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
 		if (a.parts.sign)
@@ -262,5 +633,5 @@
 }
 
-/* Convert float to signed int64
+/* 
  * FIXME: Im not sure what to return if overflow/underflow happens 
  * 	- now its the biggest or the smallest int
@@ -271,5 +642,4 @@
 		return INT64_MAX;
 	
-	
 	if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
 		if (a.parts.sign)
@@ -283,119 +653,116 @@
 
 
-
-
-
-/** Helping procedure for converting float32 to uint64
- * @param a floating point number in normalized form (no NaNs or Inf are checked )
- * @return unsigned integer
- */
-static uint64_t _float32_to_uint64_helper(float32 a)
-{
-	uint64_t frac;
-	
-	if (a.parts.exp < FLOAT32_BIAS) {
+/**
+ * Helping procedure for converting float128 to uint64.
+ *
+ * @param a Floating point number in normalized form
+ *     (NaNs or Inf are not checked).
+ * @return Converted unsigned integer.
+ */
+static uint64_t _float128_to_uint64_helper(float128 a)
+{
+	uint64_t frac_hi, frac_lo;
+
+	if (a.parts.exp < FLOAT128_BIAS) {
 		/*TODO: rounding*/
 		return 0;
 	}
-	
-	frac = a.parts.fraction;
-	
-	frac |= FLOAT32_HIDDEN_BIT_MASK;
+
+	frac_hi = a.parts.frac_hi;
+	frac_lo = a.parts.frac_lo;
+
+	frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
 	/* shift fraction to left so hidden bit will be the most significant bit */
-	frac <<= 64 - FLOAT32_FRACTION_SIZE - 1; 
-
-	frac >>= 64 - (a.parts.exp - FLOAT32_BIAS) - 1;
-	if ((a.parts.sign == 1) && (frac != 0)) {
-		frac = ~frac;
-		++frac;
-	}
-	
-	return frac;
-}
-
-/* Convert float to unsigned int64
- * FIXME: Im not sure what to return if overflow/underflow happens 
- * 	- now its the biggest or the smallest int
- */ 
-uint64_t float32_to_uint64(float32 a)
-{
-	if (isFloat32NaN(a))
+	lshift128(frac_hi, frac_lo,
+	    (128 - FLOAT128_FRACTION_SIZE - 1), &frac_hi, &frac_lo);
+
+	rshift128(frac_hi, frac_lo,
+	    (128 - (a.parts.exp - FLOAT128_BIAS) - 1), &frac_hi, &frac_lo);
+	if ((a.parts.sign == 1) && !eq128(frac_hi, frac_lo, 0x0ll, 0x0ll)) {
+		not128(frac_hi, frac_lo, &frac_hi, &frac_lo);
+		add128(frac_hi, frac_lo, 0x0ll, 0x1ll, &frac_hi, &frac_lo);
+	}
+
+	return frac_lo;
+}
+
+/*
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+uint32_t float128_to_uint32(float128 a)
+{
+	if (isFloat128NaN(a))
+		return UINT32_MAX;
+
+	if (isFloat128Infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
+		if (a.parts.sign)
+			return UINT32_MIN;
+
+		return UINT32_MAX;
+	}
+
+	return (uint32_t) _float128_to_uint64_helper(a);
+}
+
+/*
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+int32_t float128_to_int32(float128 a)
+{
+	if (isFloat128NaN(a))
+		return INT32_MAX;
+
+	if (isFloat128Infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
+		if (a.parts.sign)
+			return INT32_MIN;
+
+		return INT32_MAX;
+	}
+
+	return (int32_t) _float128_to_uint64_helper(a);
+}
+
+
+/*
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+uint64_t float128_to_uint64(float128 a)
+{
+	if (isFloat128NaN(a))
 		return UINT64_MAX;
-	
-	
-	if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
+
+	if (isFloat128Infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
 		if (a.parts.sign)
 			return UINT64_MIN;
-		
+
 		return UINT64_MAX;
 	}
-	
-	return _float32_to_uint64_helper(a);
-}
-
-/* Convert float to signed int64
- * FIXME: Im not sure what to return if overflow/underflow happens 
- * 	- now its the biggest or the smallest int
- */ 
-int64_t float32_to_int64(float32 a)
-{
-	if (isFloat32NaN(a))
+
+	return _float128_to_uint64_helper(a);
+}
+
+/*
+ * FIXME: Im not sure what to return if overflow/underflow happens
+ * 	- now its the biggest or the smallest int
+ */
+int64_t float128_to_int64(float128 a)
+{
+	if (isFloat128NaN(a))
 		return INT64_MAX;
-	
-	if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
+
+	if (isFloat128Infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
 		if (a.parts.sign)
 			return INT64_MIN;
-		
+
 		return INT64_MAX;
 	}
-	
-	return _float32_to_uint64_helper(a);
-}
-
-
-/* Convert float64 to unsigned int32
- * FIXME: Im not sure what to return if overflow/underflow happens 
- * 	- now its the biggest or the smallest int
- */ 
-uint32_t float64_to_uint32(float64 a)
-{
-	if (isFloat64NaN(a))
-		return UINT32_MAX;
-	
-	
-	if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
-		if (a.parts.sign)
-			return UINT32_MIN;
-		
-		return UINT32_MAX;
-	}
-	
-	return (uint32_t) _float64_to_uint64_helper(a);
-}
-
-/* Convert float64 to signed int32
- * FIXME: Im not sure what to return if overflow/underflow happens 
- * 	- now its the biggest or the smallest int
- */ 
-int32_t float64_to_int32(float64 a)
-{
-	if (isFloat64NaN(a))
-		return INT32_MAX;
-	
-	
-	if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
-		if (a.parts.sign)
-			return INT32_MIN;
-		
-		return INT32_MAX;
-	}
-	
-	return (int32_t) _float64_to_uint64_helper(a);
-}
-
-/** Convert unsigned integer to float32
- *
- *
- */
+
+	return _float128_to_uint64_helper(a);
+}
+
+
 float32 uint32_to_float32(uint32_t i)
 {
@@ -424,5 +791,5 @@
 	roundFloat32(&exp, &i);
 
-	result.parts.fraction = i >> 7;
+	result.parts.fraction = i >> (32 - FLOAT32_FRACTION_SIZE - 2);
 	result.parts.exp = exp;
 
@@ -435,7 +802,7 @@
 
 	if (i < 0) {
-		result = uint32_to_float32((uint32_t)(-i));
+		result = uint32_to_float32((uint32_t) (-i));
 	} else {
-		result = uint32_to_float32((uint32_t)i);
+		result = uint32_to_float32((uint32_t) i);
 	}
 	
@@ -465,5 +832,5 @@
 	}
 	
-	/* Shift all to the first 31 bits (31. will be hidden 1)*/
+	/* Shift all to the first 31 bits (31st will be hidden 1) */
 	if (counter > 33) {
 		i <<= counter - 1 - 32;
@@ -472,8 +839,8 @@
 	}
 	
-	j = (uint32_t)i;
+	j = (uint32_t) i;
 	roundFloat32(&exp, &j);
 
-	result.parts.fraction = j >> 7;
+	result.parts.fraction = j >> (32 - FLOAT32_FRACTION_SIZE - 2);
 	result.parts.exp = exp;
 	return result;
@@ -485,7 +852,7 @@
 
 	if (i < 0) {
-		result = uint64_to_float32((uint64_t)(-i));
+		result = uint64_to_float32((uint64_t) (-i));
 	} else {
-		result = uint64_to_float32((uint64_t)i);
+		result = uint64_to_float32((uint64_t) i);
 	}
 	
@@ -495,8 +862,4 @@
 }
 
-/** Convert unsigned integer to float64
- *
- *
- */
 float64 uint32_to_float64(uint32_t i)
 {
@@ -523,5 +886,5 @@
 	roundFloat64(&exp, &frac);
 
-	result.parts.fraction = frac >> 10;
+	result.parts.fraction = frac >> (64 - FLOAT64_FRACTION_SIZE - 2);
 	result.parts.exp = exp;
 
@@ -534,7 +897,7 @@
 
 	if (i < 0) {
-		result = uint32_to_float64((uint32_t)(-i));
+		result = uint32_to_float64((uint32_t) (-i));
 	} else {
-		result = uint32_to_float64((uint32_t)i);
+		result = uint32_to_float64((uint32_t) i);
 	}
 	
@@ -571,5 +934,5 @@
 	roundFloat64(&exp, &i);
 
-	result.parts.fraction = i >> 10;
+	result.parts.fraction = i >> (64 - FLOAT64_FRACTION_SIZE - 2);
 	result.parts.exp = exp;
 	return result;
@@ -581,7 +944,7 @@
 
 	if (i < 0) {
-		result = uint64_to_float64((uint64_t)(-i));
+		result = uint64_to_float64((uint64_t) (-i));
 	} else {
-		result = uint64_to_float64((uint64_t)i);
+		result = uint64_to_float64((uint64_t) i);
 	}
 	
@@ -591,4 +954,108 @@
 }
 
+
+float128 uint32_to_float128(uint32_t i)
+{
+	int counter;
+	int32_t exp;
+	float128 result;
+	uint64_t frac_hi, frac_lo;
+
+	result.parts.sign = 0;
+	result.parts.frac_hi = 0;
+	result.parts.frac_lo = 0;
+
+	counter = countZeroes32(i);
+
+	exp = FLOAT128_BIAS + 32 - counter - 1;
+
+	if (counter == 32) {
+		result.binary.hi = 0;
+		result.binary.lo = 0;
+		return result;
+	}
+
+	frac_hi = 0;
+	frac_lo = i;
+	lshift128(frac_hi, frac_lo, (counter + 96 - 1), &frac_hi, &frac_lo);
+
+	roundFloat128(&exp, &frac_hi, &frac_lo);
+
+	rshift128(frac_hi, frac_lo,
+	    (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo);
+	result.parts.frac_hi = frac_hi;
+	result.parts.frac_lo = frac_lo;
+	result.parts.exp = exp;
+
+	return result;
+}
+
+float128 int32_to_float128(int32_t i)
+{
+	float128 result;
+
+	if (i < 0) {
+		result = uint32_to_float128((uint32_t) (-i));
+	} else {
+		result = uint32_to_float128((uint32_t) i);
+	}
+
+	result.parts.sign = i < 0;
+
+ 	return result;
+}
+
+
+float128 uint64_to_float128(uint64_t i)
+{
+	int counter;
+	int32_t exp;
+	float128 result;
+	uint64_t frac_hi, frac_lo;
+
+	result.parts.sign = 0;
+	result.parts.frac_hi = 0;
+	result.parts.frac_lo = 0;
+
+	counter = countZeroes64(i);
+
+	exp = FLOAT128_BIAS + 64 - counter - 1;
+
+	if (counter == 64) {
+		result.binary.hi = 0;
+		result.binary.lo = 0;
+		return result;
+	}
+
+	frac_hi = 0;
+	frac_lo = i;
+	lshift128(frac_hi, frac_lo, (counter + 64 - 1), &frac_hi, &frac_lo);
+
+	roundFloat128(&exp, &frac_hi, &frac_lo);
+
+	rshift128(frac_hi, frac_lo,
+	    (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo);
+	result.parts.frac_hi = frac_hi;
+	result.parts.frac_lo = frac_lo;
+	result.parts.exp = exp;
+
+	return result;
+}
+
+float128 int64_to_float128(int64_t i)
+{
+	float128 result;
+
+	if (i < 0) {
+		result = uint64_to_float128((uint64_t) (-i));
+	} else {
+		result = uint64_to_float128((uint64_t) i);
+	}
+
+	result.parts.sign = i < 0;
+
+ 	return result;
+}
+
 /** @}
  */
