this repo has no description
1/* This module implements the C standard math functions nanf and nan.
2
3 $Revision: 1.3 $, $Date: 2005/06/23 18:26:55 $
4*/
5
6
7/*
8 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
9 *
10 * @APPLE_LICENSE_HEADER_START@
11 *
12 * The contents of this file constitute Original Code as defined in and
13 * are subject to the Apple Public Source License Version 1.1 (the
14 * "License"). You may not use this file except in compliance with the
15 * License. Please obtain a copy of the License at
16 * http://www.apple.com/publicsource and read it before using this file.
17 *
18 * This Original Code and all software distributed under the License are
19 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
23 * License for the specific language governing rights and limitations
24 * under the License.
25 *
26 * @APPLE_LICENSE_HEADER_END@
27 */
28
29
30/* This module implements:
31
32 float nanf(const char *tagp);
33 double nan(const char *tagp);
34
35 as defined in the C standard. The specific NaN returned is
36 implementation-defined, and we define it:
37
38 The significand's "quiet" bit (its most significant bit) is set.
39
40 If tagp points to a numeral, the remaining bits of the significand are
41 set to the numeral's value (modulo the width available). The numeral
42 may be an octal numeral beginning with "0", a decimal numeral not
43 beginning with "0", or a hexadecimal numeral beginning with "0x" or
44 "0X". Hexadecimal digits may be in uppercase or lowercase. The string
45 may not contain a sign or any characters other than the digits and a
46 "0x" or "0X" prefix, and it may not contain any characters not forming
47 part of a numeral, even as a trailing portion. The value is intended
48 to be the same as would be provided by strtoumax with zero for the
49 base.
50
51 Otherwise, the remaining bits are set to zero. This may change in the
52 future.
53
54 The result is intended to match GCC's __builtin_nanf and __builtin_nan.
55
56 Additional information is in nan.h.
57*/
58
59
60#include "nan.h"
61
62
63// Here is nanf, as defined in the C standard and above.
64float nanf(const char *tagp)
65{
66 // Parse tagp, initialize result, and move our significand into it.
67 Float result =
68 {
69 .s.sign = 0,
70 .s.exponent = ~0,
71 .s.quiet = 1,
72 .s.significand = ConstructSignificand(tagp)
73 };
74
75 return result.f;
76}
77
78
79// Here is nan, as defined in the C standard and above.
80double nan(const char *tagp)
81{
82 // Parse tagp, initialize result, and move our significand into it.
83 Double result =
84 {
85 .s.sign = 0,
86 .s.exponent = ~0,
87 .s.quiet = 1,
88 .s.significand = ConstructSignificand(tagp)
89 };
90
91 return result.d;
92}