浮点按位 [英] bitwise on float

查看:69
本文介绍了浮点按位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我现在不能直接在浮点数上执行任何按位操作

(双等等)。但是我想知道最简单/最好的方法是什么?

我在想我是否有浮动x = 1.1111所以我可以将它加倍1000到

得到11111并且预制棒按位<<<<<<<<<<<>得到88888然后将
除以1000再回到浮动8.8888。但这些似乎是令人讨厌的这样做的方式

做到了。那么也许你们中的一些人有很棒的建议?


提前谢谢你!

LR

Hi!
I now that I can''t do straight forward any bitwise operation on float
(double etc..). But I wondering what is the easiest/best way to do this?
I was thinking if I have float x=1.1111 so I can multiple it by 1000 to
get 11111 and the preform bitwise like <<2 to get 88888 and then divide
by 1000 to go back to float 8.8888. but these seem like "nasty" way to
do it. So maybe some of you have great tips?

Thank you in advance!
L R

推荐答案

5月18日上午7:15,Carramba< u ... @ example.netwrote:
On May 18, 7:15 am, Carramba <u...@example.netwrote:

嗨!

我现在我不能直接向浮点运行任何按位操作

(双等...)。但是我想知道最简单/最好的方法是什么?

我在想我是否有浮动x = 1.1111所以我可以将它加倍1000到

得到11111并且预制棒按位<<<<<<<<<<<>得到88888然后将
除以1000再回到浮动8.8888。但这些似乎是令人讨厌的这样做的方式

做到了。那么也许你们中有些人有很棒的建议?
Hi!
I now that I can''t do straight forward any bitwise operation on float
(double etc..). But I wondering what is the easiest/best way to do this?
I was thinking if I have float x=1.1111 so I can multiple it by 1000 to
get 11111 and the preform bitwise like <<2 to get 88888 and then divide
by 1000 to go back to float 8.8888. but these seem like "nasty" way to
do it. So maybe some of you have great tips?



如果你只是想用它做数学,那么所有这些都是一个完整的

浪费时间。

如果你想了解内部格式的内容,

然后看看:


7.12.6.4 frexp函数< br $>
概要

1 #include< math.h>

double frexp(double value,int * exp);

float frexpf(float value,int * exp);

long double frexpl(long double value,int * exp);

描述

2 frexp函数将浮点数分解为标准化的
分数和2的整数幂。它们将整数存储在exp指向的$

对象中。

返回

3如果值不是浮点数,结果是未指定的
。否则,frexp函数返回值x,例如,x具有区间[1/2,1]或零的幅度,值

等于x * 2 ^ * EXP。如果值为零,结果的两个部分都是

零。

7.12.6.6 ldexp函数

概要

1 #include< math.h>

double ldexp(double x,int exp);

float ldexpf(float x,int exp);

long double ldexpl(long double x,int exp);

描述

2 ldexp函数将浮点数乘以整数

功率为2.可能会出现范围错误。

返回

3 ldexp函数返回x * 2 ^ exp。


user923005 skrev:
user923005 skrev:

5月18日上午7:15,Carramba< u ... @ example。 netwrote:
On May 18, 7:15 am, Carramba <u...@example.netwrote:

>嗨!
我现在不能直接做任何按位操作浮动
(双等) )。但是我想知道最简单/最好的方法是什么?
我在考虑是否有浮动x = 1.1111所以我可以将它加倍1000以获得11111和预制棒按位<< ; 2得到88888然后除以1000再回到浮动8.8888。但这些似乎是令人讨厌的这样做的方式。那么也许你们中有些人有很棒的建议?
>Hi!
I now that I can''t do straight forward any bitwise operation on float
(double etc..). But I wondering what is the easiest/best way to do this?
I was thinking if I have float x=1.1111 so I can multiple it by 1000 to
get 11111 and the preform bitwise like <<2 to get 88888 and then divide
by 1000 to go back to float 8.8888. but these seem like "nasty" way to
do it. So maybe some of you have great tips?



如果你只是想用它做数学,那么所有这些都是完全的浪费时间。


If you just want to do math with it, then all of that is a complete
waste of time.



两者都没有......正如我之前所说,我需要在

float上执行按位操作。现在我的程序只适用于整数值,因此

precision是ok。但为了获得非常好的精度,我需要

浮点数,以及按位运算:)

neither or... as I stated earlier I need to perform bitwise operation on
float. right now I program works only on integer values, and thus
precision is "ok". but in order to get really nice precision I need
floats, and bitwise operations on them :)


如果你想了解什么是继续内部格式,

然后看看:


7.12.6.4 frexp函数

概要

1 #include< math.h>

double frexp(double value,int * exp);

float frexpf(float value,int * exp);

long double frexpl(long double value,int * exp);

描述

2 frexp函数打破浮点将数字转换为标准化的
分数和2的积分幂。它们将整数存储在exp指向的int

对象中。

返回

3如果值不是浮点数,则结果为

未指定。否则,frexp函数返回值x,例如,x具有区间[1/2,1]或零的幅度,值

等于x * 2 ^ * EXP。如果值为零,结果的两个部分都是

零。


7.12.6.6 ldexp函数

概要

1 #include< math.h>

double ldexp(double x,int exp);

float ldexpf(float x,int exp) ;

long double ldexpl(long double x,int exp);

描述

2 ldexp函数将浮点数乘以积分

功率为2.可能出现范围错误。

返回

3 ldexp函数返回x * 2 ^ exp。
If you want to understand what is going on with the internal format,
then take a look at:

7.12.6.4 The frexp functions
Synopsis
1 #include <math.h>
double frexp(double value, int *exp);
float frexpf(float value, int *exp);
long double frexpl(long double value, int *exp);
Description
2 The frexp functions break a floating-point number into a normalized
fraction and an integral power of 2. They store the integer in the int
object pointed to by exp.
Returns
3 If value is not a floating-point number, the results are
unspecified. Otherwise, the frexp functions return the value x, such
that x has a magnitude in the interval [1/2, 1) or zero, and value
equals x * 2^*exp. If value is zero, both parts of the result are
zero.
7.12.6.6 The ldexp functions
Synopsis
1 #include <math.h>
double ldexp(double x, int exp);
float ldexpf(float x, int exp);
long double ldexpl(long double x, int exp);
Description
2 The ldexp functions multiply a floating-point number by an integral
power of 2. A range error may occur.
Returns
3 The ldexp functions return x * 2^exp.


在文章< 46 *********************** @ news.luth.se> ;,

Carramba< us ** @ example.netwrote:
In article <46***********************@news.luth.se>,
Carramba <us**@example.netwrote:

> user923005 skrev:
>user923005 skrev:

> 5月18日上午7:15,Carramba< u ... @ example.netwrote:
>On May 18, 7:15 am, Carramba <u...@example.netwrote:

>>嗨!
我现在不能直接进行任何按位操作o n浮动
(双等...)。但是我想知道最简单/最好的方法是什么?
我在考虑是否有浮动x = 1.1111所以我可以将它加倍1000以获得11111和预制棒按位<< ; 2得到88888然后除以1000再回到浮动8.8888。但这些似乎是令人讨厌的这样做的方式。那么也许你们中有些人有很棒的建议?
>>Hi!
I now that I can''t do straight forward any bitwise operation on float
(double etc..). But I wondering what is the easiest/best way to do this?
I was thinking if I have float x=1.1111 so I can multiple it by 1000 to
get 11111 and the preform bitwise like <<2 to get 88888 and then divide
by 1000 to go back to float 8.8888. but these seem like "nasty" way to
do it. So maybe some of you have great tips?


如果你只是想用它做数学,那么所有这些都是完全的浪费时间。


If you just want to do math with it, then all of that is a complete
waste of time.


既不是......如前所述,我需要在

float上执行按位操作。现在我的程序只适用于整数值,因此精度是正常。但为了获得非常好的精度,我需要
浮点数,并对它们进行按位操作:)


neither or... as I stated earlier I need to perform bitwise operation on
float. right now I program works only on integer values, and thus
precision is "ok". but in order to get really nice precision I need
floats, and bitwise operations on them :)



你真的想做什么?


无论是什么,尝试对浮动进行按位操作可能是错误的方法。

dave


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca

如果您想送礼物,请告诉我您的银行信息,

我会选择合适的礼物。

- 埃里克施瓦茨在可怕的魔鬼修道院中

What Are You Really Trying To Do?

Whatever it is, trying to do bitwise operations on floats is probably
the wrong way to do it.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
If you wish to send gifts, just provide me with your banking information,
and I''ll select something suitable.
--Eric Schwartz in the scary devil monastery


这篇关于浮点按位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆