xref: /netbsd-src/lib/libc/arch/vax/gen/fpclassifyf.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: fpclassifyf.c,v 1.3 2008/04/28 20:22:57 martin Exp $	*/
2d82e7323Skleink 
3d82e7323Skleink /*-
4d82e7323Skleink  * Copyright (c) 2004 The NetBSD Foundation, Inc.
5d82e7323Skleink  * All rights reserved.
6d82e7323Skleink  *
7d82e7323Skleink  * This code is derived from software contributed to The NetBSD Foundation
8d82e7323Skleink  * by Klaus Klein.
9d82e7323Skleink  *
10d82e7323Skleink  * Redistribution and use in source and binary forms, with or without
11d82e7323Skleink  * modification, are permitted provided that the following conditions
12d82e7323Skleink  * are met:
13d82e7323Skleink  * 1. Redistributions of source code must retain the above copyright
14d82e7323Skleink  *    notice, this list of conditions and the following disclaimer.
15d82e7323Skleink  * 2. Redistributions in binary form must reproduce the above copyright
16d82e7323Skleink  *    notice, this list of conditions and the following disclaimer in the
17d82e7323Skleink  *    documentation and/or other materials provided with the distribution.
18d82e7323Skleink  *
19d82e7323Skleink  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d82e7323Skleink  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d82e7323Skleink  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d82e7323Skleink  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d82e7323Skleink  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d82e7323Skleink  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d82e7323Skleink  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d82e7323Skleink  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d82e7323Skleink  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d82e7323Skleink  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d82e7323Skleink  * POSSIBILITY OF SUCH DAMAGE.
30d82e7323Skleink  */
31d82e7323Skleink 
32d82e7323Skleink #include <sys/cdefs.h>
33d82e7323Skleink #if defined(LIBC_SCCS) && !defined(lint)
34*ce099b40Smartin __RCSID("$NetBSD: fpclassifyf.c,v 1.3 2008/04/28 20:22:57 martin Exp $");
35d82e7323Skleink #endif
36d82e7323Skleink 
37d82e7323Skleink #include <machine/vaxfp.h>
38d82e7323Skleink #include <math.h>
39d82e7323Skleink 
40d82e7323Skleink /*
41d82e7323Skleink  * 7.12.3.1 fpclassify - classify real floating type
42d82e7323Skleink  *          VAX F_floating version
43d82e7323Skleink  *
44d82e7323Skleink  *          Implementation notes:
45d82e7323Skleink  *          Reserved operand -> FP_ROP
46d82e7323Skleink  *          True zero        -> FP_ZERO
47d82e7323Skleink  *          Dirty zero       -> FP_DIRTY_ZERO
48d82e7323Skleink  *          Finite           -> FP_NORMAL
49d82e7323Skleink  */
50d82e7323Skleink int
__fpclassifyf(float x)51d82e7323Skleink __fpclassifyf(float x)
52d82e7323Skleink {
53d82e7323Skleink 	union vax_ffloating_u u;
54d82e7323Skleink 
55d82e7323Skleink 	u.ffltu_f = x;
56d82e7323Skleink 
572758365eSmatt 	if (u.ffltu_fflt.fflt_exp == 0) {
582758365eSmatt 		if (u.ffltu_fflt.fflt_sign != 0)
59d82e7323Skleink 			return FP_ROP;
602758365eSmatt 		else if (u.ffltu_fflt.fflt_frach != 0 ||
612758365eSmatt 			 u.ffltu_fflt.fflt_fracl != 0)
62d82e7323Skleink 			return FP_DIRTYZERO;
63d82e7323Skleink 		else
64d82e7323Skleink 			return FP_ZERO;
65d82e7323Skleink 	} else {
66d82e7323Skleink 		return FP_NORMAL;
67d82e7323Skleink 	}
68d82e7323Skleink }
69