14b6b5744SDavid Schultz /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni *
44b6b5744SDavid Schultz * Copyright (c) 2007 David Schultz
54b6b5744SDavid Schultz * All rights reserved.
64b6b5744SDavid Schultz *
74b6b5744SDavid Schultz * Redistribution and use in source and binary forms, with or without
84b6b5744SDavid Schultz * modification, are permitted provided that the following conditions
94b6b5744SDavid Schultz * are met:
104b6b5744SDavid Schultz * 1. Redistributions of source code must retain the above copyright
114b6b5744SDavid Schultz * notice, this list of conditions and the following disclaimer.
124b6b5744SDavid Schultz * 2. Redistributions in binary form must reproduce the above copyright
134b6b5744SDavid Schultz * notice, this list of conditions and the following disclaimer in the
144b6b5744SDavid Schultz * documentation and/or other materials provided with the distribution.
154b6b5744SDavid Schultz *
164b6b5744SDavid Schultz * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174b6b5744SDavid Schultz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184b6b5744SDavid Schultz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194b6b5744SDavid Schultz * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
204b6b5744SDavid Schultz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214b6b5744SDavid Schultz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224b6b5744SDavid Schultz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234b6b5744SDavid Schultz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244b6b5744SDavid Schultz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254b6b5744SDavid Schultz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264b6b5744SDavid Schultz * SUCH DAMAGE.
274b6b5744SDavid Schultz */
284b6b5744SDavid Schultz
294b6b5744SDavid Schultz #include <math.h>
304b6b5744SDavid Schultz
314b6b5744SDavid Schultz #include "fpmath.h"
327cd4a832SDavid Schultz #include "../src/math_private.h"
334b6b5744SDavid Schultz
344b6b5744SDavid Schultz long double
nanl(const char * s)354b6b5744SDavid Schultz nanl(const char *s)
364b6b5744SDavid Schultz {
377cd4a832SDavid Schultz union {
387cd4a832SDavid Schultz union IEEEl2bits ieee;
397cd4a832SDavid Schultz uint32_t bits[3];
407cd4a832SDavid Schultz } u;
414b6b5744SDavid Schultz
427cd4a832SDavid Schultz _scan_nan(u.bits, 3, s);
437cd4a832SDavid Schultz u.ieee.bits.exp = 0x7fff;
447cd4a832SDavid Schultz u.ieee.bits.manh |= 0xc0000000; /* make it a quiet NaN */
457cd4a832SDavid Schultz return (u.ieee.e);
464b6b5744SDavid Schultz }
47