nuttx/libs/libc/math/lib_scalbnf.c
Nathan Hartman 6b89b6f945 Remove executable permissions from source files
* arch/arm/src/sama5/sam_flexcom_spi.h,
  arch/risc-v/src/mpfs/mpfs_ihc_sbi.c,
  drivers/usbdev/adb.c,
  libs/libc/math/lib_scalbn.c,
  libs/libc/math/lib_scalbnf.c,
  net/ipfrag/Make.defs,
  net/ipfrag/ipfrag.c,
  net/ipfrag/ipfrag.h,
  net/ipfrag/ipv4_frag.c,
  net/ipfrag/ipv6_frag.c: Remove executable permission.
2023-01-30 20:34:51 -03:00

84 lines
2.0 KiB
C

/****************************************************************************
* libs/libc/math/lib_scalbnf.c
* get a float number of x*2^n
*
* This file is copy from musl libc
* musl is an implementation of the C standard library built on top of the
* Linux system call API, including interfaces defined in the base language
* standard, POSIX, and widely agreed-upon extensions.
* musl is lightweight, fast, simple, free, and strives to be correct in
* the sense of standards-conformance and safety.
*
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <math.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor definitions
****************************************************************************/
#define FLT_MIN (0x1p-126f)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: scalbnf
*
* Description:
* get a float number of x*2^n
*
****************************************************************************/
float scalbnf(float x, int n)
{
union
{
float f;
uint32_t i;
}u;
float_t y = x;
if (n > 127)
{
y *= 0x1p127f;
n -= 127;
if (n > 127)
{
y *= 0x1p127f;
n -= 127;
if (n > 127)
{
n = 127;
}
}
}
else if (n < -126)
{
y *= FLT_MIN * 0x1p24f;
n += 126 - 24;
if (n < -126)
{
y *= FLT_MIN * 0x1p24f;
n += 126 - 24;
if (n < -126)
{
n = -126;
}
}
}
u.i = (uint32_t)(0x7f + n) << 23;
x = y * u.f;
return x;
}