On 5/12/11 11:21 AM, Abid H. Mujtaba wrote:
Section 5.5 Overloading on page 142 it defines the following example
of a "find" function which searches for slices within slices:

T1[] find( T1, T2 )( T1[] longer, T2[] shorter )
    if( is( typeof( longer[ 0 .. 1 ] == shorter ) : bool ) )
{
    while ( longer.length>= shorter.length ) {
       if ( longer[0 .. shorter.length] == shorter ) break ;
    }

    return longer ;
}

On page 143 it defines the following unittest :

unittest {

    double[] d1 = [ 6.0, 1.5, 2.4, 3 ] ;
    float[] d2 = [ 1.5, 2.4 ] ;

    assert( find(d1,d2) == d1[1 .. $] ;
}

It is the assert() that fails since the comparison longer[0 ..
shorter.length] == shorter fails because the comparison between the
double and float values fails due to bit precision and
representation issues.

I see. Thanks! I updated the errata with credit:

http://erdani.com/tdpl/errata


Andrei

Reply via email to