本文介绍了使用浮点数的基础位表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道是否有一种方法可以使用基础位

表示浮点数。我有兴趣在

MISRA C:2004规则中创建违规行为基础位表示不得使用

使用


我使用按位运算符进行了treid但这些不可编译。


有没有办法可以使用浮点数位表示?

Hi

I am wondering if there is a way of using the underlying bit
representations of floats. I am interested in creating a violation in
MISRA C:2004 of rule "The underlying bit representations shall not be
used"

I have treid using bitwise operators but these are not compilable.

Is there a way I can use bit representations of floats?

推荐答案



如果您使用IEEE754我们有:


typedef struct {

unsigned int mantissa1;

unsigned int mantissa0:31;

unsigned int one:1;

unsigned int exponent:15;

unsigned int negative:1;

unsigned int empty:16;

} _longDouble; // 80位英特尔长双

typedef结构{

unsigned int mantissa1;

unsigned int mantissa0:20;

unsigned int exponent:11;

unsigned int sign:1;

} _Double; // 64位双


typedef struct {

unsigned int尾数:23;

unsigned int exponent:8;

unsigned int sign:1;

} _Float; // 32位浮动


If you use IEEE754 we have:

typedef struct {
unsigned int mantissa1;
unsigned int mantissa0:31;
unsigned int one:1;
unsigned int exponent:15;
unsigned int negative:1;
unsigned int empty:16;
} _longDouble; // 80 bits intel long double
typedef struct {
unsigned int mantissa1;
unsigned int mantissa0:20;
unsigned int exponent:11;
unsigned int sign:1;
} _Double; // 64 bit double

typedef struct {
unsigned int mantissa:23;
unsigned int exponent:8;
unsigned int sign:1;
} _Float; // 32 bit float




这篇关于使用浮点数的基础位表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:42