UVA 11809 Floating-point numbers

本文探讨了计算机中浮点数的表示方式,通过给定的最大可表示浮点数值来确定用于尾数和指数的位数。介绍了如何通过数学运算找到匹配的位数配置,并提供了一个实现该功能的C++程序示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Floating-point numbers are represented differently in computers than
integers. That is why a 32-bit floating-point number can represent
values in the magnitude of 1038 while a 32-bit integer can only
represent values as high as 232 . Although there are variations in the
ways floating-point numbers are stored in Computers, in this problem
we will assume that floating-point numbers are stored in the following
way:
Floating-point numbers have two parts mantissa and exponent.
M-bits are allotted for mantissa and E bits are allotted for exponent.
There is also one bit that denotes the sign of number (If this bit is
0 then the number is positive and if it is 1 then the number is
negative) and another bit that denotes the sign of exponent (If this
bit is 0 then exponent is positive otherwise negative). The value of
mantissa and exponent together make the value of the floating-point
number. If the value of mantissa is m then it maintains the
constraints 1 2 ≤ m < 1. The left most digit of mantissa must always
be 1 to maintain the constraint 1 2 ≤ m < 1. So this bit is not stored
as it is always 1. So the bits in mantissa actually denote the digits
at the right side of decimal point of a binary number (Excluding the
digit just to the right of decimal point) In the figure above we can
see a floating-point number where M = 8 and E = 6. The largest value
this floating-point number can represent is (in binary) 0.1111111112
×2 1111112 . The decimal equivalent to this number is: 0.998046875 × 2
63 = 920535763834529382410. Given the maximum possible value
represented by a certain floating point type, you will have to find
how many bits are allotted for mantissa (M) and how many bits are
allotted for exponent (E) in that certain type.
Input
The input file contains around 300 line of input. Each line contains a floating-point
number F that denotes the maximum value that can be represented by a
certain floating-point type. The floating point number is expressed in
decimal exponent format. So a number AeB actually denotes the value
A×10B. A line containing ‘0e0’ terminates input. The value of A will
satisfy the constraint 0 < A < 10 and will have exactly 15 digits
after the decimal point.
Output
For each line of input produce one
line of output. This line contains the value of M and E. You can
assume that each of the inputs (except the last one) has a possible
and unique solution. You can also assume that inputs will be such that
the value of M and E will follow the constraints: 9 ≥ M ≥ 0 and 30 ≥ E
Sample Input
5.699141892149156e76
9.205357638345294e18
0e0
Sample Output
5 8
8 6

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
double M[11][33];   //存储对应尾数
long long E[11][33];    //存储对应指数
const double min_differ=1e-5;   //设置误差
void solve(double m,long long e)
//把匹配过程放到函数中,匹配后可以及时中断
{
    int i,j;
    for(i=0;i<=9;i++)
        for(j=1;j<=30;j++)
        if(e==E[i][j]&&fabs(m-M[i][j])<min_differ)
        //当指数等于表中所给并且尾数差值绝对值小于误差时即匹配,输出答案,跳出函数
        {
            cout<<i<<" "<<j<<endl;
            return;
        }
}
int main()
{
    int i,j;
    double m,t;
    long long e;
    char str[22];
    for(i=0;i<=9;i++)
        for(j=1;j<=30;j++)
        {
            e=(1<<j)-1;     //根据上述公式打表,每一个对应位的尾数和指数分别存储
            m=1-1.0/(1<<(i+1));
            t=log10(m)+e*log10(2);  //10^t=m*2^e,取反函数得此式
            E[i][j]=t/1;//取整
            M[i][j]=pow(10,t-E[i][j]);//相当于取得科学计数法的前面的浮点数
        }
        while(cin>>str,strcmp(str,"0e0"))
        {
            *(strchr(str,'e'))=' ';     //将字符串中的e替换成空格
            sscanf(str,"%lf %lld",&m,&e);   //运用sscanf巧妙分割尾数和指数
            solve(m,e);
        }
        return 0;
}
JFM7VX690T型SRAM型现场可编程门阵列技术手册主要介绍的是上海复旦微电子集团股份有限公司(简称复旦微电子)生产的高性能FPGA产品JFM7VX690T。该产品属于JFM7系列,具有现场可编程特性,集成了功能强大且可以灵活配置组合的可编程资源,适用于实现多种功能,如输入输出接口、通用数字逻辑、存储器、数字信号处理和时钟管理等。JFM7VX690T型FPGA适用于复杂、高速的数字逻辑电路,广泛应用于通讯、信息处理、工业控制、数据中心、仪表测量、医疗仪器、人工智能、自动驾驶等领域。 产品特点包括: 1. 可配置逻辑资源(CLB),使用LUT6结构。 2. 包含CLB模块,可用于实现常规数字逻辑和分布式RAM。 3. 含有I/O、BlockRAM、DSP、MMCM、GTH等可编程模块。 4. 提供不同的封装规格和工作温度范围的产品,便于满足不同的使用环境。 JFM7VX690T产品系列中,有多种型号可供选择。例如: - JFM7VX690T80采用FCBGA1927封装,尺寸为45x45mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T80-AS同样采用FCBGA1927封装,但工作温度范围更广,为-55°C到+125°C,同样使用锡银焊球。 - JFM7VX690T80-N采用FCBGA1927封装和铅锡焊球,工作温度范围与JFM7VX690T80-AS相同。 - JFM7VX690T36的封装规格为FCBGA1761,尺寸为42.5x42.5mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T36-AS使用锡银焊球,工作温度范围为-55°C到+125°C。 - JFM7VX690T36-N使用铅锡焊球,工作温度范围与JFM7VX690T36-AS相同。 技术手册中还包含了一系列详细的技术参数,包括极限参数、推荐工作条件、电特性参数、ESD等级、MSL等级、重量等。在产品参数章节中,还特别强调了封装类型,包括外形图和尺寸、引出端定义等。引出端定义是指对FPGA芯片上的各个引脚的功能和接线规则进行说明,这对于FPGA的正确应用和电路设计至关重要。 应用指南章节涉及了FPGA在不同应用场景下的推荐使用方法。其中差异说明部分可能涉及产品之间的性能差异;关键性能对比可能包括功耗与速度对比、上电浪涌电流测试情况说明、GTH Channel Loss性能差异说明、GTH电源性能差异说明等。此外,手册可能还提供了其他推荐应用方案,例如不使用的BANK接法推荐、CCLK信号PCB布线推荐、JTAG级联PCB布线推荐、系统工作的复位方案推荐等,这些内容对于提高系统性能和稳定性有着重要作用。 焊接及注意事项章节则针对产品的焊接过程提供了指导,强调焊接过程中的注意事项,以确保产品在组装过程中的稳定性和可靠性。手册还明确指出,未经复旦微电子的许可,不得翻印或者复制全部或部分本资料的内容,且不承担采购方选择与使用本文描述的产品和服务的责任。 上海复旦微电子集团股份有限公司拥有相关的商标和知识产权。该公司在中国发布的技术手册,版权为上海复旦微电子集团股份有限公司所有,未经许可不得进行复制或传播。 技术手册提供了上海复旦微电子集团股份有限公司销售及服务网点的信息,方便用户在需要时能够联系到相应的服务机构,获取最新信息和必要的支持。同时,用户可以访问复旦微电子的官方网站(***以获取更多产品信息和公司动态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值