Index: src/libcfa/bits/defs.h
===================================================================
--- src/libcfa/bits/defs.h	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/bits/defs.h	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -1,16 +1,16 @@
-//
+// 
 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
 //
 // The contents of this file are covered under the licence agreement in the
 // file "LICENCE" distributed with Cforall.
-//
-// bits/defs.h --
-//
+// 
+// defs.h -- 
+// 
 // Author           : Thierry Delisle
-// Created On       : Thu Nov 09 13:24:10 2017
-// Last Modified By :
-// Last Modified On :
-// Update Count     :
-//
+// Created On       : Thu Nov  9 13:24:10 2017
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Tue Jan  2 09:17:06 2018
+// Update Count     : 2
+// 
 
 #pragma once
@@ -20,6 +20,6 @@
 #include <stdint.h>
 
-#define unlikely(x)    __builtin_expect(!!(x), 0)
-#define likely  (x)    __builtin_expect(!!(x), 1)
+#define likely(x)   __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(!!(x), 0)
 #define thread_local _Thread_local
 
Index: src/libcfa/concurrency/monitor.c
===================================================================
--- src/libcfa/concurrency/monitor.c	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/concurrency/monitor.c	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -534,5 +534,5 @@
 	__lock_size_t actual_count = aggregate( mon_storage, mask );
 
-	__cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
+	__cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %"PRIdFAST16" (s: %"PRIdFAST16", m: %"PRIdFAST16")\n", actual_count, mask.size, (__lock_size_t)max);
 
 	if(actual_count == 0) return;
@@ -575,5 +575,5 @@
 				monitor_save;
 
-				__cfaabi_dbg_print_buffer_local( "Kernel :  baton of %d monitors : ", count );
+				__cfaabi_dbg_print_buffer_local( "Kernel :  baton of %"PRIdFAST16" monitors : ", count );
 				#ifdef __CFA_DEBUG_PRINT__
 					for( int i = 0; i < count; i++) {
Index: src/libcfa/concurrency/preemption.c
===================================================================
--- src/libcfa/concurrency/preemption.c	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/concurrency/preemption.c	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -303,4 +303,6 @@
 	// Check if it is safe to preempt here
 	if( !preemption_ready() ) { return; }
+
+	// __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
 
 	preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
Index: src/libcfa/fstream
===================================================================
--- src/libcfa/fstream	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/fstream	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Dec  7 08:06:11 2017
-// Update Count     : 129
+// Last Modified On : Thu Dec  7 15:17:26 2017
+// Update Count     : 130
 //
 
@@ -52,4 +52,5 @@
 int flush( ofstream & );
 void open( ofstream &, const char * name, const char * mode );
+void open( ofstream &, const char * name );
 void close( ofstream & );
 ofstream & write( ofstream &, const char * data, unsigned long int size );
@@ -58,4 +59,5 @@
 void ?{}( ofstream & os );
 void ?{}( ofstream & os, const char * name, const char * mode );
+void ?{}( ofstream & os, const char * name );
 
 extern ofstream & sout, & serr;
@@ -69,4 +71,5 @@
 int fail( ifstream & is );
 int eof( ifstream & is );
+void open( ifstream & is, const char * name, const char * mode );
 void open( ifstream & is, const char * name );
 void close( ifstream & is );
@@ -76,4 +79,5 @@
 
 void ?{}( ifstream & is );
+void ?{}( ifstream & is, const char * name, const char * mode );
 void ?{}( ifstream & is, const char * name );
 
Index: src/libcfa/fstream.c
===================================================================
--- src/libcfa/fstream.c	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/fstream.c	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Dec  7 08:35:01 2017
-// Update Count     : 270
+// Last Modified On : Sat Dec  9 09:31:23 2017
+// Update Count     : 275
 //
 
@@ -46,8 +46,11 @@
 
 // public
-void ?{}( ofstream & os ) {}
+void ?{}( ofstream & os ) { os.file = 0; }
 
 void ?{}( ofstream & os, const char * name, const char * mode ) {
 	open( os, name, mode );
+}
+void ?{}( ofstream & os, const char * name ) {
+	open( os, name, "w" );
 }
 
@@ -84,5 +87,5 @@
 
 int fail( ofstream & os ) {
-	return ferror( (FILE *)(os.file) );
+	return os.file == 0 || ferror( (FILE *)(os.file) );
 } // fail
 
@@ -93,10 +96,14 @@
 void open( ofstream & os, const char * name, const char * mode ) {
 	FILE *file = fopen( name, mode );
-	if ( file == 0 ) {									// do not change unless successful
-		fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
-		perror( 0 );
-		exit( EXIT_FAILURE );
-	} // if
+	// if ( file == 0 ) {									// do not change unless successful
+	// 	fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
+	// 	perror( 0 );
+	// 	exit( EXIT_FAILURE );
+	// } // if
 	(os){ file, true, false, " ", ", " };
+} // open
+
+void open( ofstream & os, const char * name ) {
+	open( os, name, "w" );
 } // open
 
@@ -152,12 +159,15 @@
 
 // public
-void ?{}( ifstream & is ) {}
-
+void ?{}( ifstream & is ) {	is.file = 0; }
+
+void ?{}( ifstream & is, const char * name, const char * mode ) {
+	open( is, name, mode );
+}
 void ?{}( ifstream & is, const char * name ) {
-	open( is, name );
+	open( is, name, "r" );
 }
 
 int fail( ifstream & is ) {
-	return ferror( (FILE *)(is.file) );
+	return is.file == 0 || ferror( (FILE *)(is.file) );
 } // fail
 
@@ -166,12 +176,16 @@
 } // eof
 
+void open( ifstream & is, const char * name, const char * mode ) {
+	FILE *file = fopen( name, mode );
+	// if ( file == 0 ) {									// do not change unless successful
+	// 	fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
+	// 	perror( 0 );
+	// 	exit( EXIT_FAILURE );
+	// } // if
+	is.file = file;
+} // open
+
 void open( ifstream & is, const char * name ) {
-	FILE *file = fopen( name, "r" );
-	if ( file == 0 ) {									// do not change unless successful
-		fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
-		perror( 0 );
-		exit( EXIT_FAILURE );
-	} // if
-	is.file = file;
+	open( is, name, "r" );
 } // open
 
Index: src/libcfa/iostream
===================================================================
--- src/libcfa/iostream	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/iostream	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Dec  6 23:03:30 2017
-// Update Count     : 144
+// Last Modified On : Thu Dec 21 13:55:41 2017
+// Update Count     : 145
 //
 
@@ -55,4 +55,6 @@
 
 // implement writable for intrinsic types
+
+forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, _Bool );
 
 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, char );
Index: src/libcfa/iostream.c
===================================================================
--- src/libcfa/iostream.c	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/iostream.c	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Dec  6 23:03:43 2017
-// Update Count     : 426
+// Last Modified On : Thu Dec 21 13:55:09 2017
+// Update Count     : 427
 //
 
@@ -23,4 +23,11 @@
 #include <complex.h>									// creal, cimag
 }
+
+forall( dtype ostype | ostream( ostype ) )
+ostype & ?|?( ostype & os, _Bool b ) {
+	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+	fmt( os, "%s", b ? "true" : "false" );
+	return os;
+} // ?|?
 
 forall( dtype ostype | ostream( ostype ) )
Index: src/libcfa/stdlib
===================================================================
--- src/libcfa/stdlib	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/stdlib	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -10,9 +10,12 @@
 // Created On       : Thu Jan 28 17:12:35 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Oct 31 13:47:24 2017
-// Update Count     : 245
+// Last Modified On : Tue Jan  2 12:21:04 2018
+// Update Count     : 292
 //
 
 #pragma once
+
+//#define _XOPEN_SOURCE 600								// posix_memalign, *rand48
+#include <stdlib.h>										// strto*, *abs
 
 //---------------------------------------
@@ -77,5 +80,5 @@
 	//printf( "X8\n" );
 	T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );	// C malloc
-    return (T *)memset( ptr, (int)fill, sizeof(T) );			// initial with fill value
+    return (T *)memset( ptr, (int)fill, sizeof(T) );	// initial with fill value
 } // alloc
 
@@ -150,41 +153,77 @@
 //---------------------------------------
 
-int ato( const char * ptr );
-unsigned int ato( const char * ptr );
-long int ato( const char * ptr );
-unsigned long int ato( const char * ptr );
-long long int ato( const char * ptr );
-unsigned long long int ato( const char * ptr );
-float ato( const char * ptr );
-double ato( const char * ptr );
-long double ato( const char * ptr );
-float _Complex ato( const char * ptr );
-double _Complex ato( const char * ptr );
-long double _Complex ato( const char * ptr );
-
-int strto( const char * sptr, char ** eptr, int base );
-unsigned int strto( const char * sptr, char ** eptr, int base );
-long int strto( const char * sptr, char ** eptr, int base );
-unsigned long int strto( const char * sptr, char ** eptr, int base );
-long long int strto( const char * sptr, char ** eptr, int base );
-unsigned long long int strto( const char * sptr, char ** eptr, int base );
-float strto( const char * sptr, char ** eptr );
-double strto( const char * sptr, char ** eptr );
-long double strto( const char * sptr, char ** eptr );
+static inline int strto( const char * sptr, char ** eptr, int base ) { return (int)strtol( sptr, eptr, base ); }
+static inline unsigned int strto( const char * sptr, char ** eptr, int base ) { return (unsigned int)strtoul( sptr, eptr, base ); }
+static inline long int strto( const char * sptr, char ** eptr, int base ) { return strtol( sptr, eptr, base ); }
+static inline unsigned long int strto( const char * sptr, char ** eptr, int base ) { return strtoul( sptr, eptr, base ); }
+static inline long long int strto( const char * sptr, char ** eptr, int base ) { return strtoll( sptr, eptr, base ); }
+static inline unsigned long long int strto( const char * sptr, char ** eptr, int base ) { return strtoull( sptr, eptr, base ); }
+
+static inline float strto( const char * sptr, char ** eptr ) { return strtof( sptr, eptr ); }
+static inline double strto( const char * sptr, char ** eptr ) { return strtod( sptr, eptr ); }
+static inline long double strto( const char * sptr, char ** eptr ) { return strtold( sptr, eptr ); }
+
 float _Complex strto( const char * sptr, char ** eptr );
 double _Complex strto( const char * sptr, char ** eptr );
 long double _Complex strto( const char * sptr, char ** eptr );
 
-//---------------------------------------
-
-forall( otype T | { int ?<?( T, T ); } )
-T * bsearch( T key, const T * arr, size_t dim );
-
-forall( otype T | { int ?<?( T, T ); } )
-unsigned int bsearch( T key, const T * arr, size_t dim );
-
-
-forall( otype T | { int ?<?( T, T ); } )
-void qsort( const T * arr, size_t dim );
+static inline int ato( const char * sptr ) {return (int)strtol( sptr, 0, 10 ); }
+static inline unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }
+static inline long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }
+static inline unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0, 10 ); }
+static inline long long int ato( const char * sptr ) { return strtoll( sptr, 0, 10 ); }
+static inline unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0, 10 ); }
+
+static inline float ato( const char * sptr ) { return strtof( sptr, 0 ); }
+static inline double ato( const char * sptr ) { return strtod( sptr, 0 ); }
+static inline long double ato( const char * sptr ) { return strtold( sptr, 0 ); }
+
+static inline float _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
+static inline double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
+static inline long double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
+
+//---------------------------------------
+
+forall( otype E | { int ?<?( E, E ); } )
+E * bsearch( E key, const E * vals, size_t dim );
+
+forall( otype E | { int ?<?( E, E ); } )
+size_t bsearch( E key, const E * vals, size_t dim );
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+E * bsearch( K key, const E * vals, size_t dim );
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+size_t bsearch( K key, const E * vals, size_t dim );
+
+
+forall( otype E | { int ?<?( E, E ); } )
+E * bsearchl( E key, const E * vals, size_t dim );
+
+forall( otype E | { int ?<?( E, E ); } )
+size_t bsearchl( E key, const E * vals, size_t dim );
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+E * bsearchl( K key, const E * vals, size_t dim );
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+size_t bsearchl( K key, const E * vals, size_t dim );
+
+
+forall( otype E | { int ?<?( E, E ); } )
+E * bsearchu( E key, const E * vals, size_t dim );
+
+forall( otype E | { int ?<?( E, E ); } )
+size_t bsearchu( E key, const E * vals, size_t dim );
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+E * bsearchu( K key, const E * vals, size_t dim );
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+size_t bsearchu( K key, const E * vals, size_t dim );
+
+
+forall( otype E | { int ?<?( E, E ); } )
+void qsort( E * vals, size_t dim );
 
 //---------------------------------------
@@ -198,14 +237,27 @@
 //---------------------------------------
 
-unsigned char abs( signed char );
+static inline unsigned char abs( signed char v ) { return abs( (int)v ); }
 extern "C" { int abs( int ); }							// use default C routine for int
-unsigned long int abs( long int );
-unsigned long long int abs( long long int );
-float abs( float );
-double abs( double );
-long double abs( long double );
-float abs( float _Complex );
-double abs( double _Complex );
-long double abs( long double _Complex );
+static inline unsigned long int abs( long int v ) { return labs( v ); }
+static inline unsigned long long int abs( long long int v ) { return llabs( v ); }
+
+extern "C" {
+double fabs( double );
+float fabsf( float );
+long double fabsl( long double );
+} // extern "C"
+static inline float abs( float x ) { return fabsf( x ); }
+static inline double abs( double x ) { return fabs( x ); }
+static inline long double abs( long double x ) { return fabsl( x ); }
+
+extern "C" {
+double cabs( double _Complex );
+float cabsf( float _Complex );
+long double cabsl( long double _Complex );
+} // extern "C"
+static inline float abs( float _Complex x ) { return cabsf( x ); }
+static inline double abs( double _Complex x ) { return cabs( x ); }
+static inline long double abs( long double _Complex x ) { return cabsl( x ); }
+
 forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
 T abs( T );
@@ -213,12 +265,17 @@
 //---------------------------------------
 
-void random_seed( long int s );
+extern "C" { void srandom( unsigned int seed ); }		// override C version
 char random( void );
+char random( char u );
 char random( char l, char u );
 int random( void );
+int random( int u );
+int random( int l, int u );
 unsigned int random( void );
 unsigned int random( unsigned int u );
 unsigned int random( unsigned int l, unsigned int u );
-//long int random( void );
+extern "C" { long int random( void ); }					// override C version
+long int random( long int u );
+long int random( long int l, long int u );
 unsigned long int random( void );
 unsigned long int random( unsigned long int u );
@@ -233,14 +290,14 @@
 
 forall( otype T | { int ?<?( T, T ); } )
-T min( T t1, T t2 );
+static inline T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
 
 forall( otype T | { int ?>?( T, T ); } )
-T max( T t1, T t2 );
+static inline T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
 
 forall( otype T | { T min( T, T ); T max( T, T ); } )
-T clamp( T value, T min_val, T max_val );
+static inline T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
 
 forall( otype T )
-void swap( T & t1, T & t2 );
+static inline void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
 
 // Local Variables: //
Index: src/libcfa/stdlib.c
===================================================================
--- src/libcfa/stdlib.c	(revision b158d8f72e3080061893992480de9583b8368561)
+++ src/libcfa/stdlib.c	(revision b68382146bfc9aa68160d565370751e4f3074dd7)
@@ -10,6 +10,6 @@
 // Created On       : Thu Jan 28 17:10:29 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Oct 30 22:43:02 2017
-// Update Count     : 297
+// Last Modified On : Tue Jan  2 12:20:32 2018
+// Update Count     : 441
 //
 
@@ -19,9 +19,9 @@
 
 #define _XOPEN_SOURCE 600								// posix_memalign, *rand48
-#include <stdlib.h>										// malloc, free, calloc, realloc, memalign, posix_memalign, bsearch
 #include <string.h>										// memcpy, memset
 #include <malloc.h>										// malloc_usable_size
 #include <math.h>										// fabsf, fabs, fabsl
 #include <complex.h>									// _Complex_I
+#include <assert.h>
 
 // resize, non-array types
@@ -93,123 +93,12 @@
 //---------------------------------------
 
-int ato( const char * ptr ) {
-	int i;
-	if ( sscanf( ptr, "%d", &i ) == EOF ) {}
-	return i;
-} // ato
-
-unsigned int ato( const char * ptr ) {
-	unsigned int ui;
-	if ( sscanf( ptr, "%u", &ui ) == EOF ) {}
-	return ui;
-} // ato
-
-long int ato( const char * ptr ) {
-	long int li;
-	if ( sscanf( ptr, "%ld", &li ) == EOF ) {}
-	return li;
-} // ato
-
-unsigned long int ato( const char * ptr ) {
-	unsigned long int uli;
-	if ( sscanf( ptr, "%lu", &uli ) == EOF ) {}
-	return uli;
-} // ato
-
-long long int ato( const char * ptr ) {
-	long long int lli;
-	if ( sscanf( ptr, "%lld", &lli ) == EOF ) {}
-	return lli;
-} // ato
-
-unsigned long long int ato( const char * ptr ) {
-	unsigned long long int ulli;
-	if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {}
-	return ulli;
-} // ato
-
-
-float ato( const char * ptr ) {
-	float f;
-	if ( sscanf( ptr, "%f", &f ) == EOF ) {}
-	return f;
-} // ato
-
-double ato( const char * ptr ) {
-	double d;
-	if ( sscanf( ptr, "%lf", &d ) == EOF ) {}
-	return d;
-} // ato
-
-long double ato( const char * ptr ) {
-	long double ld;
-	if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {}
-	return ld;
-} // ato
-
-
-float _Complex ato( const char * ptr ) {
-	float re, im;
-	if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {}
-	return re + im * _Complex_I;
-} // ato
-
-double _Complex ato( const char * ptr ) {
-	double re, im;
-	if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {}
-	return re + im * _Complex_I;
-} // ato
-
-long double _Complex ato( const char * ptr ) {
-	long double re, im;
-	if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {}
-	return re + im * _Complex_I;
-} // ato
-
-
-int strto( const char * sptr, char ** eptr, int base ) {
-	return (int)strtol( sptr, eptr, base );
-} // strto
-
-unsigned int strto( const char * sptr, char ** eptr, int base ) {
-	return (unsigned int)strtoul( sptr, eptr, base );
-} // strto
-
-long int strto( const char * sptr, char ** eptr, int base ) {
-	return strtol( sptr, eptr, base );
-} // strto
-
-unsigned long int strto( const char * sptr, char ** eptr, int base ) {
-	return strtoul( sptr, eptr, base );
-} // strto
-
-long long int strto( const char * sptr, char ** eptr, int base ) {
-	return strtoll( sptr, eptr, base );
-} // strto
-
-unsigned long long int strto( const char * sptr, char ** eptr, int base ) {
-	return strtoull( sptr, eptr, base );
-} // strto
-
-
-float strto( const char * sptr, char ** eptr ) {
-	return strtof( sptr, eptr );
-} // strto
-
-double strto( const char * sptr, char ** eptr ) {
-	return strtod( sptr, eptr );
-} // strto
-
-long double strto( const char * sptr, char ** eptr ) {
-	return strtold( sptr, eptr );
-} // strto
-
-
 float _Complex strto( const char * sptr, char ** eptr ) {
 	float re, im;
-	re = strtof( sptr, eptr );
-	if ( sptr == *eptr ) return 0.0;
-	im = strtof( sptr, eptr );
-	if ( sptr == *eptr ) return 0.0;
+	char * eeptr;
+	re = strtof( sptr, &eeptr );
+	if ( sptr == *eeptr ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0f + 0.0f * _Complex_I; }
+	im = strtof( eeptr, &eeptr );
+	if ( sptr == *eeptr ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0f + 0.0f * _Complex_I; }
+	if ( *eeptr != 'i' ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0f + 0.0f * _Complex_I; }
 	return re + im * _Complex_I;
 } // strto
@@ -217,8 +106,10 @@
 double _Complex strto( const char * sptr, char ** eptr ) {
 	double re, im;
-	re = strtod( sptr, eptr );
-	if ( sptr == *eptr ) return 0.0;
-	im = strtod( sptr, eptr );
-	if ( sptr == *eptr ) return 0.0;
+	char * eeptr;
+	re = strtod( sptr, &eeptr );
+	if ( sptr == *eeptr ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0 + 0.0 * _Complex_I; }
+	im = strtod( eeptr, &eeptr );
+	if ( sptr == *eeptr ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0 + 0.0 * _Complex_I; }
+	if ( *eeptr != 'i' ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0 + 0.0 * _Complex_I; }
 	return re + im * _Complex_I;
 } // strto
@@ -226,8 +117,10 @@
 long double _Complex strto( const char * sptr, char ** eptr ) {
 	long double re, im;
-	re = strtold( sptr, eptr );
-	if ( sptr == *eptr ) return 0.0;
-	im = strtold( sptr, eptr );
-	if ( sptr == *eptr ) return 0.0;
+	char * eeptr;
+	re = strtold( sptr, &eeptr );
+	if ( sptr == *eeptr ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0L + 0.0L * _Complex_I; }
+	im = strtold( eeptr, &eeptr );
+	if ( sptr == *eeptr ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0L + 0.0L * _Complex_I; }
+	if ( *eeptr != 'i' ) { if ( eptr != 0 ) *eptr = eeptr; return 0.0L + 0.0L * _Complex_I; }
 	return re + im * _Complex_I;
 } // strto
@@ -235,20 +128,121 @@
 //---------------------------------------
 
-forall( otype T | { int ?<?( T, T ); } )
-T * bsearch( T key, const T * arr, size_t dim ) {
-	int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
-	return (T *)bsearch( &key, arr, dim, sizeof(T), comp );
-} // bsearch
-
-forall( otype T | { int ?<?( T, T ); } )
-unsigned int bsearch( T key, const T * arr, size_t dim ) {
-	T *result = bsearch( key, arr, dim );
-	return result ? result - arr : dim;					// pointer subtraction includes sizeof(T)
-} // bsearch
-
-forall( otype T | { int ?<?( T, T ); } )
-void qsort( const T * arr, size_t dim ) {
-	int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
-	qsort( arr, dim, sizeof(T), comp );
+forall( otype E | { int ?<?( E, E ); } )
+E * bsearch( E key, const E * vals, size_t dim ) {
+	int cmp( const void * t1, const void * t2 ) {
+		return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0;
+	} // cmp
+	return (E *)bsearch( &key, vals, dim, sizeof(E), cmp );
+} // bsearch
+
+forall( otype E | { int ?<?( E, E ); } )
+size_t bsearch( E key, const E * vals, size_t dim ) {
+	E * result = bsearch( key, vals, dim );
+	return result ? result - vals : dim;				// pointer subtraction includes sizeof(E)
+} // bsearch
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+E * bsearch( K key, const E * vals, size_t dim ) {
+	int cmp( const void * t1, const void * t2 ) {
+		return *(K *)t1 < getKey( *(E *)t2 ) ? -1 : getKey( *(E *)t2 ) < *(K *)t1 ? 1 : 0;
+	} // cmp
+	return (E *)bsearch( &key, vals, dim, sizeof(E), cmp );
+} // bsearch
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+size_t bsearch( K key, const E * vals, size_t dim ) {
+	E * result = bsearch( key, vals, dim );
+	return result ? result - vals : dim;				// pointer subtraction includes sizeof(E)
+} // bsearch
+
+
+forall( otype E | { int ?<?( E, E ); } )
+size_t bsearchl( E key, const E * vals, size_t dim ) {
+	size_t l = 0, m, h = dim;
+	while ( l < h ) {
+		m = (l + h) / 2;
+		if ( (E &)(vals[m]) < key ) {					// cast away const
+			l = m + 1;
+		} else {
+			h = m;
+		} // if
+	} // while
+	return l;
+} // bsearchl
+
+forall( otype E | { int ?<?( E, E ); } )
+E * bsearchl( E key, const E * vals, size_t dim ) {
+	size_t posn = bsearchl( key, vals, dim );
+	return (E *)(&vals[posn]);							// cast away const
+} // bsearchl
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+size_t bsearchl( K key, const E * vals, size_t dim ) {
+	size_t l = 0, m, h = dim;
+	while ( l < h ) {
+		m = (l + h) / 2;
+		if ( getKey( vals[m] ) < key ) {
+			l = m + 1;
+		} else {
+			h = m;
+		} // if
+	} // while
+	return l;
+} // bsearchl
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+E * bsearchl( K key, const E * vals, size_t dim ) {
+	size_t posn = bsearchl( key, vals, dim );
+	return (E *)(&vals[posn]);							// cast away const
+} // bsearchl
+
+
+forall( otype E | { int ?<?( E, E ); } )
+size_t bsearchu( E key, const E * vals, size_t dim ) {
+	size_t l = 0, m, h = dim;
+	while ( l < h ) {
+		m = (l + h) / 2;
+		if ( ! ( key < (E &)(vals[m]) ) ) {				// cast away const
+			l = m + 1;
+		} else {
+			h = m;
+		} // if
+	} // while
+	return l;
+} // bsearchu
+
+forall( otype E | { int ?<?( E, E ); } )
+E * bsearchu( E key, const E * vals, size_t dim ) {
+	size_t posn = bsearchu( key, vals, dim );
+	return (E *)(&vals[posn]);
+} // bsearchu
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+size_t bsearchu( K key, const E * vals, size_t dim ) {
+	size_t l = 0, m, h = dim;
+	while ( l < h ) {
+		m = (l + h) / 2;
+		if ( ! ( key < getKey( vals[m] ) ) ) {
+			l = m + 1;
+		} else {
+			h = m;
+		} // if
+	} // while
+	return l;
+} // bsearchu
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
+E * bsearchu( K key, const E * vals, size_t dim ) {
+	size_t posn = bsearchu( key, vals, dim );
+	return (E *)(&vals[posn]);
+} // bsearchu
+
+
+forall( otype E | { int ?<?( E, E ); } )
+void qsort( E * vals, size_t dim ) {
+	int cmp( const void * t1, const void * t2 ) {
+		return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0;
+	} // cmp
+	qsort( vals, dim, sizeof(E), cmp );
 } // qsort
 
@@ -263,56 +257,26 @@
 //---------------------------------------
 
-unsigned char abs( signed char v ) { return abs( (int)v ); }
-unsigned long int abs( long int v ) { return labs( v ); }
-unsigned long long int abs( long long int v ) { return llabs( v ); }
-float abs( float x ) { return fabsf( x ); }
-double abs( double x ) { return fabs( x ); }
-long double abs( long double x ) { return fabsl( x ); }
-float abs( float _Complex x ) { return cabsf( x ); }
-double abs( double _Complex x ) { return cabs( x ); }
-long double abs( long double _Complex x ) { return cabsl( x ); }
-
-//---------------------------------------
-
-void random_seed( long int s ) { srand48( s ); }
-char random( void ) { return mrand48(); }
-char random( char l, char u ) { return lrand48() % (u - l) + l; }
-int random( void ) { return mrand48(); }
-unsigned int random( void ) { return lrand48(); }
-unsigned int random( unsigned int u ) { return lrand48() % u; }
-unsigned int random( unsigned int l, unsigned int u ) { return lrand48() % (u - l) + l; }
-//long int random( void ) { return mrand48(); }
+extern "C" { void srandom( unsigned int seed ) { srand48( seed ); } } // override C version
+char random( void ) { return (unsigned long int)random(); }
+char random( char u ) { return random( (unsigned long int)u ); }
+char random( char l, char u ) { return random( (unsigned long int)l, (unsigned long int)u ); }
+int random( void ) { return (long int)random(); }
+int random( int u ) { return random( (long int)u ); }
+int random( int l, int u ) { return random( (long int)l, (long int)u ); }
+unsigned int random( void ) { return (unsigned long int)random(); }
+unsigned int random( unsigned int u ) { return random( (unsigned long int)u ); }
+unsigned int random( unsigned int l, unsigned int u ) { return random( (unsigned long int)l, (unsigned long int)u ); }
+extern "C" { long int random( void ) { return mrand48(); } } // override C version
+long int random( long int u ) { if ( u < 0 ) return random( u, 0 ); else return random( 0, u ); }
+long int random( long int l, long int u ) { assert( l < u ); return lrand48() % (u - l) + l; }
 unsigned long int random( void ) { return lrand48(); }
 unsigned long int random( unsigned long int u ) { return lrand48() % u; }
-unsigned long int random( unsigned long int l, unsigned long int u ) { return lrand48() % (u - l) + l; }
-float random( void ) { return (float)drand48(); }		// otherwise float uses lrand48
+unsigned long int random( unsigned long int l, unsigned long int u ) { assert( l < u ); return lrand48() % (u - l) + l; }
+float random( void ) { return (float)drand48(); }		// cast otherwise float uses lrand48
 double random( void ) { return drand48(); }
 float _Complex random( void ) { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
 double _Complex random( void ) { return drand48() + (double _Complex)(drand48() * _Complex_I); }
-long double _Complex random( void) { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
-
-//---------------------------------------
-
-forall( otype T | { int ?<?( T, T ); } )
-T min( T t1, T t2 ) {
-	return t1 < t2 ? t1 : t2;
-} // min
-
-forall( otype T | { int ?>?( T, T ); } )
-T max( T t1, T t2 ) {
-	return t1 > t2 ? t1 : t2;
-} // max
-
-forall( otype T | { T min( T, T ); T max( T, T ); } )
-T clamp( T value, T min_val, T max_val ) {
-	return max( min_val, min( value, max_val ) );
-} // clamp
-
-forall( otype T )
-void swap( T & t1, T & t2 ) {
-	T temp = t1;
-	t1 = t2;
-	t2 = temp;
-} // swap
+long double _Complex random( void ) { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
+
 
 // Local Variables: //
