this repo has no description
1/* This module implements the C standard math function nanl.
2
3 $Revision: 1.4 $, $Date: 2006/02/01 18:36:35 $
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 long double nanl(const char *tagp);
33
34 as defined in the C standard. The specific NaN returned is
35 implementation-defined, and we define it:
36
37 The significand's "quiet" bit (its most significant bit) is set.
38
39 If tagp points to a numeral, the remaining bits of the significand are
40 set to the numeral's value (modulo the width available). The numeral
41 may be an octal numeral beginning with "0", a decimal numeral not
42 beginning with "0", or a hexadecimal numeral beginning with "0x" or
43 "0X". Hexadecimal digits may be in uppercase or lowercase. The string
44 may not contain a sign or any characters other than the digits and a
45 "0x" or "0X" prefix, and it may not contain any characters not forming
46 part of a numeral, even as a trailing portion. The value is intended
47 to be the same as would be provided by strtoumax with zero for the
48 base.
49
50 Otherwise, the remaining bits are set to zero. This may change in the
51 future.
52
53 The result is intended to match GCC's __builtin_nanl.
54
55 A previous implementation did not set the "quiet" bit if the hexadecimal
56 numeral did not indicate it and did set the significand to one if it were
57 zero. The former does not conform to the C standard; a quiet NaN must be
58 returned. The latter is unneeded. It was needed only to avoid returning
59 infinity (all significand bits are zero) instead of a NaN (significand is
60 not zero).
61
62 Additional information is in nan.h.
63*/
64
65
66#include "nan.h"
67
68
69/* Here is nanl, as defined in the C standard and above.
70
71 Note that the declaration of nanl in math.h includes some GCC mechanisms to
72 control the name of nanl in the object file, with the result that what we
73 call nanl here appears as _nanl$LDBL128 on PowerPC compiled with
74 -mlong-double-128 (the default on PowerPC), or _nanl otherwise.
75*/
76long double nanl(const char *tagp)
77{
78 /* Parse tagp, initialize result, and move our significand into it.
79
80 Setting .ld to zero initializes the entire long double. This
81 accomplishes the result of setting the second double to zero, if
82 present, without requiring conditional code. (It is not necessary to
83 set the second double to zero; it may have any value in a NaN.)
84
85 We could eliminate the conditional code for .s.integer by merging it
86 with the quiet and/or exponent bits in the definition of LongDouble
87 above, but that might be more confusing than the conditional code.
88 */
89 LongDouble result =
90 {
91 .ld = 0,
92 .s.sign = 0,
93 .s.exponent = ~0,
94 #if defined( __i386__ ) || defined( __x86_64__ )
95 .s.integer = 1, // Set integer bit on IA-32.
96 #endif
97 .s.quiet = 1,
98 .s.significand = ConstructSignificand(tagp)
99 };
100
101 return result.ld;
102}