www.delorie.com/djgpp/doc/libc/libc_782.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

_strtold

Syntax

 
#include <stdlib.h>

long double _strtold(const char *s, char **endp);

Description

This function converts as many characters of s that look like a floating point number into that number. It also recognises (case-insensitively) "Inf", "Infinity", "NaN", "NaN(optional decimal-number)", "NaN(optional octal-number)" and "NaN(optional hex-number)". If endp is not a null pointer, a pointer to the first unconverted character will be stored in the location pointed to by endp.

There is also a standardised version of this function: strtold (see section strtold).

Return Value

The value representedby s.

If s is "Inf" or "Infinity", with any variations of case and optionally prefixed with "+" or "-", the return value is INFINITY (if no prefix or a "+" prefix) or -INFINITY (if the prefix is "-").

If s is "NaN" or "NaN()", with any variations of case and optionally prefixed with "+" or "-", the return value is (long double)NAN. If the prefix is "-" the sign bit in the NaN will be set to 1.

If s is "NaN(decimal-number)", "NaN(octal-number)" or "NaN(hex-number)", with any variations of case and optionally prefixed with "+" or "-", the return value is a NaN with the mantissa bits set to the lower 63 bits of decimal-number, octal-number or hex-number and the most significant bit to 1 (the mantissa for long doubles consists of 64 bits where the most significant bit is the integer bit which must be set for NaNs). Use at most 16 hexadecimal digits in hex-number or the internal conversion will overflow, which results in a mantissa with all bits set. If the bit pattern given is 0 (which won't work as a representation of a NaN) (long double)NAN will be returned. If the prefix is "-" the sign bit in the NaN will be set to 1. Testing shows that SNaNs might be converted into QNaNs (the second most significant bit will be set in the mantissa).

Portability

ANSI/ISO C No
POSIX No

Example

 
char buf[] = "123ret";
char buf2[] = "0x123ret";
char buf3[] = "NAN(123)";
char buf4[] = "NAN(0x123)";
char *bp;
long double x, x2, x3, x4;

x = _strtold(buf, &bp);
x2 = _strtold(buf2, &bp);
x3 = _strtold(buf3, &bp);
x4 = _strtold(buf4, &bp);


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004