annotate tests/test-hypotf.c @ 16515:026ce065f317

Tests for module 'hypotf'. * modules/hypotf-tests: New file. * tests/test-hypotf.c: New file.
author Bruno Haible <bruno@clisp.org>
date Wed, 29 Feb 2012 13:24:23 +0100
parents
children 4acf461e0a81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16515
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of hypotf() function.
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2010-2012 Free Software Foundation, Inc.
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <math.h>
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "signature.h"
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 SIGNATURE_CHECK (hypotf, float, (float, float));
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <float.h>
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include "macros.h"
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 volatile float x;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 volatile float y;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 float z;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 int
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 main ()
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 /* A particular value. */
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 x = 0.4f;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 y = 0.6f;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 z = hypot (x, y);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 ASSERT (z >= 0.7211102f && z <= 0.7211103f);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 /* Overflow. */
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 x = FLT_MAX;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 y = FLT_MAX * 0.5f;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 z = hypotf (x, y);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 ASSERT (z == HUGE_VALF);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 /* No underflow. */
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 x = FLT_MIN;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 y = 0.0f;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 z = hypotf (x, y);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 ASSERT (z == FLT_MIN);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 /* No underflow. */
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 x = FLT_MIN * 2.0f;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 y = FLT_MIN * 3.0f;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 z = hypotf (x, y);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 ASSERT (z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f);
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 return 0;
026ce065f317 Tests for module 'hypotf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 }