/* * This file is Copyright (c) 2010 by the GPSD project * SPDX-License-Identifier: BSD-2-clause */ #include /* * Copyright (c) 2006 Chris Kuethe * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * this simple program tests to see whether your system can do proper * single and double precision floating point. This is apparently Very * Hard To Do(tm) on embedded systems, judging by the number of broken * ARM toolchains I've seen... :( * * Added in 2015 by ESR: Test for C99 behavior on negative operand(s) * of %, that is the result should have the sign of the left operand. * * compile with: gcc -O -o test_float test_float.c * (use whatever -O level you like) */ int main(void); int test_single(void); int test_double(void); int test_modulo(void); int main(void) { int i, j, k; if ((i = test_single())) printf("WARNING: Single-precision " "floating point math might be broken\n"); if ((j = test_double())) printf("WARNING: Double-precision " "floating point math might be broken\n"); if ((k = test_modulo())) printf("WARNING: Modular arithmetic is broken\n"); i += j; i += k; if (i == 0) printf("floating point and modular math appears to work\n"); return i; } int test_single(void) { static float f; static int i; static int e = 0; /* addition test */ f = 1.0; for(i = 0; i < 10; i++) f += (1<