X-Git-Url: https://scm.cri.ensmp.fr/git/Faustine.git/blobdiff_plain/1059e1cc0c2ecfa237406949aa26155b6a5b9154..66f23d4fabf89ad09adbd4dfc15ac6b5b2b7da83:/interpreter/lib/src/libsndfile-1.0.25/src/test_float.c diff --git a/interpreter/lib/src/libsndfile-1.0.25/src/test_float.c b/interpreter/lib/src/libsndfile-1.0.25/src/test_float.c new file mode 100644 index 0000000..9d0b09d --- /dev/null +++ b/interpreter/lib/src/libsndfile-1.0.25/src/test_float.c @@ -0,0 +1,104 @@ +/* +** Copyright (C) 2006-2011 Erik de Castro Lopo +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU Lesser General Public License as published by +** the Free Software Foundation; either version 2.1 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "sfconfig.h" + +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "test_main.h" + +void +test_float_convert (void) +{ static float data [] = + { 0.0, 1.0, -1.0, 1.0 * M_PI, -1.0 * M_PI, + 1e9, -1e9, 1e-9, -1e-9, 1e-10, -1e-10, + 1e-19, -1e-19, 1e19, -1e19, 1e-20, -1e-20, + } ; + + int k ; + + print_test_name (__func__) ; + + for (k = 0 ; k < ARRAY_LEN (data) ; k++) + { unsigned char bytes [4] ; + float test ; + + float32_le_write (data [k], bytes) ; + test = float32_le_read (bytes) ; + + if (fabs (data [k] - test) > 1e-20) + { printf ("\n\nLine %d : Test %d, little endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test ) ; + exit (1) ; + } ; + + float32_be_write (data [k], bytes) ; + test = float32_be_read (bytes) ; + + if (fabs (data [k] - test) > 1e-20) + { printf ("\n\nLine %d : Test %d, big endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test) ; + exit (1) ; + } ; + + } ; + + puts ("ok") ; +} /* test_float_convert */ + +void +test_double_convert (void) +{ static double data [] = + { 0.0, 1.0, -1.0, 1.0 * M_PI, -1.0 * M_PI, + 1e9, -1e9, 1e-9, -1e-9, 1e-10, -1e-10, + 1e-19, -1e-19, 1e19, -1e19, 1e-20, -1e-20, + } ; + + int k ; + + print_test_name (__func__) ; + + for (k = 0 ; k < ARRAY_LEN (data) ; k++) + { unsigned char bytes [8] ; + double test ; + + double64_le_write (data [k], bytes) ; + test = double64_le_read (bytes) ; + + if (fabs (data [k] - test) > 1e-20) + { printf ("\n\nLine %d : Test %d, little endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test ) ; + exit (1) ; + } ; + + double64_be_write (data [k], bytes) ; + test = double64_be_read (bytes) ; + + if (fabs (data [k] - test) > 1e-20) + { printf ("\n\nLine %d : Test %d, big endian error %.15g -> %.15g.\n\n", __LINE__, k, data [k], test) ; + exit (1) ; + } ; + + } ; + + puts ("ok") ; +} /* test_double_convert */ +