eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ieee80.c 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2022 Ulrich Müller <[email protected]>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see: <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * Alternatively, at your option, you can distribute this file under
  19. * the terms of the 2-clause BSD license.
  20. */
  21. #include "config.h"
  22. #include "test_assert.h"
  23. #include <math.h>
  24. #include <stdlib.h>
  25. #include "ieee80.h"
  26. int
  27. main(int argc, char **argv)
  28. {
  29. (void)argc; (void)argv; /* unused */
  30. /* Define only constants that can be exactly represented both in
  31. decimal and in binary, in order to avoid rounding errors */
  32. unsigned char in[][10] = {
  33. { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 0 */
  34. { 0x3f,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 1 */
  35. { 0xbf,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* -1 */
  36. { 0x40,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 2 */
  37. { 0x3f,0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 0.5 */
  38. { 0x3f,0xf7,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 0.005859375 */
  39. { 0x40,0x22,0x98,0x76,0x54,0x32,0x10,0x00,0x00,0x00 }, /* 40926266145 */
  40. { 0x7f,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* inf */
  41. { 0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* -inf */
  42. { 0x7f,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } /* nan */
  43. };
  44. TEST_ASSERT(ieee_extended_to_double(in[0]) == 0.);
  45. TEST_ASSERT(ieee_extended_to_double(in[1]) == 1.);
  46. TEST_ASSERT(ieee_extended_to_double(in[2]) == -1.);
  47. TEST_ASSERT(ieee_extended_to_double(in[3]) == 2.);
  48. TEST_ASSERT(ieee_extended_to_double(in[4]) == 0.5);
  49. TEST_ASSERT(ieee_extended_to_double(in[5]) == 0.005859375);
  50. TEST_ASSERT(ieee_extended_to_double(in[6]) == 40926266145.);
  51. #ifdef INFINITY
  52. TEST_ASSERT(ieee_extended_to_double(in[7]) == INFINITY);
  53. TEST_ASSERT(ieee_extended_to_double(in[8]) == -INFINITY);
  54. #endif
  55. #ifdef NAN
  56. TEST_ASSERT(isnan(ieee_extended_to_double(in[9])));
  57. #endif
  58. return EXIT_SUCCESS;
  59. }