首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::frexp

Defined in header <cmath>

float frexp( float arg, int* exp );

(1)

double frexp( double arg, int* exp );

(2)

long double frexp( long double arg, int* exp );

(3)

double frexp( Integral arg, int* exp );

(4)

(since C++11)

1-3%29分解给定的浮点值arg变成一个正规化的分数和整数的二次方。

4%29一组过载或接受任意参数的函数模板积分型等效于%282%29%28的参数转换为double29%。

参数

arg

-

floating point value

exp

-

pointer to integer value to store the exponent to

返回值

如果arg为零,返回零,并将零存储在*exp...

否则,%28arg不是零%29,如果没有发生错误,则返回值。x在范围内(-1;-0.5], [0.5; 1)中存储整数值。*expx×2%28%2Aexp%29

=Arg.

中存储的值*exp超出了...的范围int,行为未指定。

如果arg不是浮点数,行为是未指定的.

错误处理

中指定的任何错误均不受此函数的影响。数学[医]错误处理...

如果实现支持ieee浮点算法%28IEC 60559%29,

  • 如果arg为±0,则返回、未修改和0存储在*exp...
  • 如果arg是±∞,则返回,并将未指定的值存储在*exp...
  • 如果arg是nan,则返回nan,并将未指定的值存储在*exp...
  • 不引发浮点异常。
  • 如果FLT_RADIX是2%28或者是2%29的幂,返回的值是精确的,当前舍入模式被忽略

注记

在二进制系统%28上FLT_RADIX2%29,frexp可以作为。

二次

代码语言:javascript
复制
{
    *exp = (value == 0) ? 0 : (int)(1 + std::logb(value));
    return std::scalbn(value, -(*exp));
}

二次

功能std::frexp再加上它的双重性,std::ldexp,可用于操纵浮点数的表示,而不需要直接的位操作。

比较了不同的浮点分解函数。

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <limits>
 
int main()
{
    double f = 123.45;
    std::cout << "Given the number " << f << " or " << std::hexfloat
              << f << std::defaultfloat << " in hex,\n";
 
    double f3;
    double f2 = std::modf(f, &f3);
    std::cout << "modf() makes " << f3 << " + " << f2 << '\n';
 
    int i;
    f2 = std::frexp(f, &i);
    std::cout << "frexp() makes " << f2 << " * 2^" << i << '\n';
 
    i = std::ilogb(f);
    std::cout << "logb()/ilogb() make " << f/std::scalbn(1.0, i) << " * "
              << std::numeric_limits<double>::radix
              << "^" << std::ilogb(f) << '\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
Given the number 123.45 or 0x1.edccccccccccdp+6 in hex,
modf() makes 123 + 0.45
frexp() makes 0.964453 * 2^7
logb()/ilogb() make 1.92891 * 2^6

二次

另见

ldexp

multiplies a number by 2 raised to a power (function)

logb (C++11)

extracts exponent of the number (function)

ilogb (C++11)

extracts exponent of the number (function)

modf

decomposes a number into integer and fractional parts (function)

c FREXP文件

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券