value_nan.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Centre National de la Recherche Scientifique
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <config.h>
  17. #include <core/perfmodel/perfmodel.h>
  18. #include "../helper.h"
  19. #define STRING "booh"
  20. int _check_number(double val, int nan)
  21. {
  22. char *filename = tmpnam(NULL);
  23. /* write the double value in the file followed by a predefined string */
  24. FILE *f = fopen(filename, "w");
  25. fprintf(f, "%lf %s\n", val, STRING);
  26. fclose(f);
  27. /* read the double value and the string back from the file */
  28. f = fopen(filename, "r");
  29. double lat;
  30. char str[10];
  31. int x = _starpu_read_double(f, "%lf", &lat);
  32. int y = fscanf(f, "%s", str);
  33. fclose(f);
  34. /* check that what has been read is identical to what has been written */
  35. int pass;
  36. pass = (x == 1) && (y == 1);
  37. pass = pass && strcmp(str, STRING) == 0;
  38. if (nan)
  39. pass = pass && isnan(val) && isnan(lat);
  40. else
  41. pass = pass && lat == val;
  42. return pass?0:1;
  43. }
  44. int main(int argc, char **argv)
  45. {
  46. int ret;
  47. ret = _check_number(42.0, 0);
  48. FPRINTF(stderr, "%s when reading %lf\n", ret?"Success":"Error", 42.0);
  49. if (ret==0)
  50. {
  51. ret = _check_number(NAN, 1);
  52. FPRINTF(stderr, "%s when reading %lf\n", ret?"Success":"Error", NAN);
  53. }
  54. return ret;
  55. }