示例#1
0
文件: myalleg.c 项目: 10crimes/code
void makesplitpalette(RGB (*fna)(float),RGB (*fnb)(float)) {
#ifdef ALLEGRO
  for (int i=0;i<=127;i++)
  set_color(i,&(fna((float)i/127.0)));
  for (int i=128;i<=255;i++)
  set_color(i,&(fnb((float)(i-128)/127.0)));
  #endif
}
示例#2
0
int
foo ()
{
  void (*fna) (void) = (void (*) (void)) a;
  void (*fnb) (void) = (void (*) (void)) b;
  fna ();
  fnb ();
  return a[1] == b[1];
}
int main()
{











//        E X T E N D I D O . . .



assert (        mtk::fnExt(mtk::fnDec(5), mtk::fnInc(5)   )
                !=
                mtk::fnExt(mtk::fnDec(2), mtk::fnInc(5)    )
    );

assert (        mtk::fnExt(mtk::fnDec(2), mtk::fnInc(10)   )
                !=
                mtk::fnExt(mtk::fnDec(1), mtk::fnInc(1)    )
    );




//---------------------------------------------------------------------------

//              f n D o u b l e

//---------------------------------------------------------------------------

//  the same..
mtk::fnDouble d1 (3.4);
mtk::fnDouble d2 (3.4, mtk::fnRoundArithmetic   );

mtk::fnDouble d3 (3.4, mtk::fnRoundFloor        );
mtk::fnDouble d4 (3.4, mtk::fnRoundCeil         );
mtk::fnDouble d5 (3.4, mtk::fnRoundNotAllowed   );








//---------------------------------------------------------------------------

//              F i x e d N u m b e r

//---------------------------------------------------------------------------


    //  CONSTRUCTORES   ____________________________________________________


//  double
assert  (
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535          ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (1                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (1                      )
            )
    );

assert  (
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535        ,
                                 mtk::fnRoundCeil   ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (1                  )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535        ,
                                 mtk::fnRoundCeil   ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (1                  )
            )

        );

//  integer
assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31416                 ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (1                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (1                      )
            )

        );



        //  error en tiempo de ejecución
        //  redondeo por defecto para enteros...   notallowed
        /*
            mtk::FixedNumber(
                mtk::fnIntCode  (31416              ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (5                  )
            );
      */

assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31415                 ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (5                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnIntCode   (31416                  ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (5                      )
            )

        );






//  fnExt
assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31416                 ),
                mtk::fnExt (
                            mtk::fnDec      (4         ),
                            mtk::fnInc      (1         )
                           )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnExt (
                            mtk::fnDec      (4          ),
                            mtk::fnInc      (1          )
                           )
            )

        );






    //  Métodos de acceso  ________________________________________________

    //  lectura
    assert  (
                mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
                .GetDouble()
                > 3.14
                //  == 3.15
            );


    {
    mtk::FixedNumber fn1 (mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5));

    assert (    fn1.GetExt().GetDec()       ==  2              );
    assert (    fn1.GetDouble()             >   3.14           );
    assert (    fn1.d()                     >   3.14           );
    assert (    fn1.GetExt().GetFormat()    ==  mtk::fnFNormal );



        //  escritura
    fn1.SetDouble(3.11);
    assert (    fn1.GetIntCode()            ==  310 );
    assert (    fn1.GetDouble ()            <   3.11);

    fn1.SetIntCode(39);
    assert (    fn1.GetIntCode()            ==  40 );
    assert (    fn1.GetDouble ()            >   0.39);


    mtk::FixedNumber  fn2 =  fn1;
    assert (    fn1.SetDouble(3.10)         ==  fn2.SetIntCode(310)  );


    assert  (
                mtk::FixedNumber(
                    mtk::fnIntCode  (0                      ),
                    mtk::fnDec      (4                      ),
                    mtk::fnInc      (5                      )
                ).SetIntCode (31415)
                ==
                mtk::FixedNumber(
                    mtk::fnIntCode  (0                      ),
                    mtk::fnDec      (4                      ),
                    mtk::fnInc      (5                      )
                ).SetIntCode (31416, mtk::fnRoundArithmetic )

            );


            //  error en tiempo de ejecución,
            //  default round for integers, not allowed
        /*
                mtk::FixedNumber fnp = mtk::FixedNumber(
                            mtk::fnIntCode  (0                  ),
                            mtk::fnDec      (4                  ),
                            mtk::fnInc      (5                  )
                    ).SetIntCode (31416);

                mtk::FixedNumber fnp2(
                            mtk::fnIntCode  (0                  ),
                            mtk::fnDec      (4                  ),
                            mtk::fnInc      (5                  )
                    );
                fnp2.SetIntCode (31416);
          */
    }









    //  OPERADORES      ____________________________________________________

        //  relacionales
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            >
            mtk::FixedNumber(mtk::fnDouble(3.0) , mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.0) , mtk::fnDec(2), mtk::fnInc(5))
            !=
            mtk::FixedNumber(mtk::fnDouble(3.14) , mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.14) , mtk::fnDec(2), mtk::fnInc(5))
            <
            mtk::FixedNumber(mtk::fnDouble(20.0) , mtk::fnDec(2), mtk::fnInc(5))
        );


            //  error en tiempo de ejecución, no son comparables
/*
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(1))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
        );
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(1), mtk::fnInc(5))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
        );
*/





        //  aritméticos

mtk::FixedNumber fna (mtk::fnDouble(3.20), mtk::fnDec(2), mtk::fnInc(1));
assert  (
            ++mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(1))
            ==
            mtk::FixedNumber  (mtk::fnDouble(3.15), mtk::fnDec(2), mtk::fnInc(1))

            &&

            mtk::FixedNumber  (mtk::fnDouble(3.15), mtk::fnDec(2), mtk::fnInc(1))
            ==
            --mtk::FixedNumber(mtk::fnDouble(3.16), mtk::fnDec(2), mtk::fnInc(1))

            &&

            --mtk::FixedNumber(mtk::fnDouble(3.16), mtk::fnDec(2), mtk::fnInc(1))
            ==
            mtk::FixedNumber  (mtk::fnDouble(3.10), mtk::fnDec(2), mtk::fnInc(1))
            +mtk::fnTicks(5)

            &&

            mtk::FixedNumber  (mtk::fnDouble(3.10), mtk::fnDec(2), mtk::fnInc(1))
            +mtk::fnTicks(5)
            ==
            (fna-=mtk::fnTicks(5))
        );






{
    mtk::FixedNumber         fn1(mtk::fnIntCode(0),   mtk::fnDec(3), mtk::fnInc(5) );
    fn1.SetDouble(3.14);
    mtk::FixedNumber         fn2(mtk::fnDouble(3.14), mtk::fnDec(3), mtk::fnInc(5) );
    mtk::FixedNumber         fn3(mtk::fnIntCode(0),   mtk::fnDec(3), mtk::fnInc(5) );
    fn3.SetIntCode(3140);

    assert          (fn1 == fn2    &&    fn2 == fn3);
    assert          (   fn3
                        ==
                        mtk::FixedNumber(
                                mtk::fnIntCode(0),
                                mtk::fnDec(3),
                                mtk::fnInc(5)
                               ).SetIntCode(3140)
                    );
}





    #include "support/release_on_exit.hpp"
    return 0;
}
示例#4
0
文件: catch6p.C 项目: 0day-ci/gcc
void check(E *e)
{
  int caught;
  
  // try with whole object
  caught = 0;
  try { fne(e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(D *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fne(e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(B *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fne(e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(C *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fne(e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(AA *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  // try with D oject
  caught = 0;
  try { fnd((D *)e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(D *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnd((D *)e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(B *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnd((D *)e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(C *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnd((D *)e); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(AA *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  // try with an A object
  caught = 0;
  try { fna((B *)e); }
  catch(B *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (B *)e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fna((C *)e); }
  catch(C *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (C *)e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fna((AA *)e); }
  catch(AA *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (AA *)e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  // try with B object
  caught = 0;
  try { fnb((B *)e); }
  catch(A *p) { caught = 1; if (p != (B *)e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnb((B *)e); }
  catch(B *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnb((B *)e); }
  catch(C *p) { abort(); }
  catch(D *p) { abort(); }
  catch(...) { caught =1; }
  if (!caught) abort();
  
  // try with C object
  caught = 0;
  try { fnc((C *)e); }
  catch(A *p) { caught = 1; if (p != (C *)e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnc((C *)e); }
  catch(C *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnc((C *)e); }
  catch(B *p) { abort(); }
  catch(D *p) { abort(); }
  catch(...) { caught =1; }
  if (!caught) abort();
  
  // try with AA object
  caught = 0;
  try { fnaa((AA *)e); }
  catch(A *p) { caught = 1; if (p != (AA *)e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnaa((AA *)e); }
  catch(AA *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnaa((AA *)e); }
  catch(C *p) { abort(); }
  catch(B *p) { abort(); }
  catch(D *p) { abort(); }
  catch(...) { caught =1; }
  if (!caught) abort();
  
  return;
}
示例#5
0
文件: catch7.C 项目: VargMon/dd-wrt
void check(F *f)
{
  int caught;
  
  // try with whole object
  caught = 0;
  try { fnf(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(F *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnf(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(E *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnf(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(D *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnf(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(B *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnf(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(C *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  // try with D object
  caught = 0;
  try { fnd(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(D *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnd(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(B *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnd(f); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(C *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  // try with E object
  caught = 0;
  try { fne(f); }
  catch(A *p) { caught = 1; if (p != (E *)f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fne(f); }
  catch(E *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fne(f); }
  catch(F *p) { abort(); }
  catch(...) { caught = 1; }
  if (!caught) abort();

  // try with an A object
  caught = 0;
  try { fna((B *)f); }
  catch(B *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (B *)f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fna((C *)f); }
  catch(C *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (C *)f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fna((E *)f); }
  catch(E *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (E *)f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  // try with B object
  caught = 0;
  try { fnb((B *)f); }
  catch(A *p) { caught = 1; if (p != (B *)f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnb((B *)f); }
  catch(B *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnb((B *)f); }
  catch(C *p) { abort(); }
  catch(D *p) { abort(); }
  catch(...) { caught =1; }
  if (!caught) abort();
  
  // try with C object
  caught = 0;
  try { fnc((C *)f); }
  catch(A *p) { caught = 1; if (p != (C *)f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnc((C *)f); }
  catch(C *p) { caught = 1; if (p != f) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnc((C *)f); }
  catch(B *p) { abort(); }
  catch(D *p) { abort(); }
  catch(...) { caught =1; }
  if (!caught) abort();
  
  return;
}
示例#6
0
文件: catch8.C 项目: 0day-ci/gcc
void check(D *d)
{
  int caught;
  
  // try with whole object
  caught = 0;
  try { fnd(d); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(D *p) { caught = 1; if (p != d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnd(d); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(B *p) { caught = 1; if (p != d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fnd(d); }
  catch(A *p) { abort(); } // A is ambiguous
  catch(C *p) { caught = 1; if (p != d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  // try with an A object
  caught = 0;
  try { fna((B *)d); }
  catch(B *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (B *)d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fna((A *)(C *)d); }
  catch(C *p) { abort(); } // throw type is static type
  catch(A *p) { caught = 1; if (p != (A *)(C *)d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  // try with B object
  caught = 0;
  try { fnb((B *)d); }
  catch(A *p) { caught = 1; if (p != (B *)d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnb((B *)d); }
  catch(B *p) { caught = 1; if (p != d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnb((B *)d); }
  catch(C *p) { abort(); }
  catch(D *p) { abort(); }
  catch(...) { caught =1; }
  if (!caught) abort();
  
  caught = 0;
  try { fnc((C *)d); }
  catch(A *p) { abort();}
  catch(C *p) { caught = 1; if (p != d) abort();}
  catch(...) { abort(); }
  if (!caught) abort();
  
  caught = 0;
  try { fnc((C *)d); }
  catch(B *p) { abort(); }
  catch(D *p) { abort(); }
  catch(...) { caught =1; }
  if (!caught) abort();

  return;
}