| /*
|
| Compiling design (CSG Tree generation)...
|
| ECHO: ff1 = 0.01
|
| ECHO: "should be true ", false
|
| ERROR: Assertion '(float_fraction("01", 0) == 0.01)' failed in file relativity.scad, line 6
|
| TRACE: called by 'assert' in file relativity.scad, line 6
|
|
|
| */
|
|
|
| ff1 = float_fraction( "01", 0 );
|
| echo( ff1=ff1 );
|
| assert( float_fraction( "01", 0 ) == ff1 );
|
| assert( float_fraction( "01", 0 ) == 0.01 );
|
| echo( "should be true ", 0.01 == ff1 );
|
|
|
|
|
| function float_fraction( string, start, pow=-1 ) =
|
| let( laststr = len(string)-1 )
|
| start > laststr ?
|
| 0
|
| : start == laststr ?
|
| char_to_digit( string[laststr] ) * 10 ^ pow
|
|
|
| : char_to_digit( string[start] ) * 10 ^ pow +
|
| float_fraction( string, start+1, pow=pow-1 );
|
| ;
|
|
|
| function char_to_digit( char ) =
|
| ( ord( char ) - ord("0") ) ;
|