Ldexp

Ldexp

In computing, ldexp is a function that multiplies a double precision floating point value by a specified integral power of two, returning the result if it is a valid floating point value for the representation used for double precision floating point values in the execution environment.

Location

It one of the the C programming language's math library routines and is declared in the header file math.h.

Definition

The function ldexp is defined in the C programming language standard, ISO/IEC 9899 [ [http://www.open-std.org/jtc1/sc22/wg14/www/standards.html ISO/IEC 9899 Standard for the C Programming Language] ] as follows:

7.12.6.6 The ldexp functions Synopsis
#include <math.h>
double ldexp(double x, int exp);
double ldexpf(float x, int exp);
long double ldexpl(long double x, int exp);

Description
The ldexp functions multiply a floating-point number by an integral power of 2. Arange error may occur.

Returns
The ldexp functions return x×2exp

The Open Group Single Unix Specification expands on the interface definition for ldexp in a Unixtm hosted environment. [ [http://www.opengroup.org/onlinepubs/009695399/functions/ldexp.html Open Group Base Specifications Issue 6, ldexp() definition] ]

:The Description section has the following additional information:::An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred.

:The "Returns" section is expanded with the following clauses::: If these functions would cause overflow, a range error shall occur and ldexp(), ldexpf(), and ldexpl() shall return ±HUGE_VAL, ±HUGE_VALF, and ±HUGE_VALL (according to the sign of x), respectively.:: If the correct value would cause underflow, and is not representable, a range error may occur, and either 0.0 (if supported), or an implementation-defined value shall be returned.:: If x is NaN, a NaN shall be returned.:: If x is ±0 or ±Inf, x shall be returned.:: If exp is 0, x shall be returned.:: If the correct value would cause underflow, and is representable, a range error may occur and the correct value shall be returned.

:It also adds an "Errors section", as follows:::These functions shall fail if::::Range Error::::The result overflows.:::::If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE] . If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow floating-point exception shall be raised.

Implementation

For binary exponent based floating point representations such as IEEE 754, ldexp can be implemented by simply extracting the exponent from the value of x and adding exp to it and if the result is within the valid exponent values for the representation, replacing x's exponent with the result. If the calculated exponent value is too high the function returns +∞ or -∞ (depending on the sign of x), and if the value is too low, the function returns 0.0.

References

ee also

*math.h
*exp (programming)
*pow (programming)
*log2 (programming)
*scalb (programming)
*Binary logarithm

External links

* [http://www.open-std.org/jtc1/sc22/wg14/www/standards.html ISO/IEC 9899 Standard for the C Programming Language]
* [http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap01.html IEEE Std 1003.1-2001 (POSIX.1)]
* [http://www.opengroup.org/onlinepubs/009695399 Open Group Base Specifications Issue 6]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Division by two — In mathematics, division by two or halving has also been called mediation or dimidiation.[1] The treatment of this as a different operation from multiplication and division by other numbers goes back to the ancient Egyptians, whose multiplication …   Wikipedia

  • List of C functions — This page aims to alphabetically list all the predefined functions used in the C standard library, and a few of the non standard functions. * assert.h ** (no functions) * ctype.h ** (non standard) digittoint ** isalnum ** isalpha ** (non… …   Wikipedia

  • C++0x — C++1x C++1x, anciennement connu sous le nom de C++0x, est la nouvelle norme prévue pour le langage C++ en informatique. Elle vise à remplacer la norme existante, ISO/IEC 14882, publiée en 1998 et mise à jour en 2003. Ces dernières sont plus… …   Wikipédia en Français

  • C++1x — C++1x, anciennement connu sous le nom de C++0x, est la nouvelle norme prévue pour le langage C++ en informatique. Elle vise à remplacer la norme existante, ISO/IEC 14882, publiée en 1998 et mise à jour en 2003. Ces dernières sont plus connues… …   Wikipédia en Français

  • Funciones de la biblioteca estándar de C — Anexo:Funciones de la biblioteca estándar de C Saltar a navegación, búsqueda El propósito de este artículo es proporcionar un listado alfabético de todas las funciones de la biblioteca estándar de C, y unas pocas funciones no estándar. Contenido… …   Wikipedia Español

  • Math.h — Saltar a navegación, búsqueda math.h es un archivo de cabecera de la biblioteca estándar del lenguaje de programación C diseñado para operaciones matemáticas básicas. Muchas de sus funciones incluyen el uso de números en coma flotante. C++… …   Wikipedia Español

  • Math.h — Стандартная библиотека языка программирования С assert.h complex.h ctype.h errno.h fenv.h float.h inttypes.h iso646.h limits.h locale.h math.h setjmp.h signal.h stdarg.h stdbool.h stddef.h stdint.h stdio.h stdlib.h …   Википедия

  • Список функций стандартной библиотеки Си — В этой статье в алфавитном порядке перечислены все предопределенные функции, используемые в стандартной библиотеке Си, а также несколько нестандартных функций. assert.h (нет функций) ctype.h (нестандартная) digittoint isalnum isalpha… …   Википедия

  • C mathematical functions — C Standard Library Data types Character classification Strings Mathematics File input/output Date/time Localizati …   Wikipedia

  • Anexo:Funciones de la biblioteca estándar de C — El propósito de este artículo es proporcionar un listado alfabético de todas las funciones de la biblioteca estándar de C, y unas pocas funciones no estándar. Contenido 1 assert.h 2 ctype.h 3 errno.h 4 float.h …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”