以64位获得中间结果 [英] Getting intermediate results in 64 bits

查看:54
本文介绍了以64位获得中间结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在我的G4上使用GCC,如果我有这样的计算:


#include< stdint.h> ;


uint64_t a = 0xffff * 0xffff;


结果将被破坏为32位,因为这是一个<的长度br />
整数。如何将所有中间步骤保持在64位而不用

用(uint64_t)转换来操作我的操作数?


如果我的默认sizeof(int将会有所帮助我猜是8岁。我怎么能获得这个呢?

Hi,

Using GCC on my G4, if I have a calculation like this:

#include <stdint.h>

uint64_t a = 0xffff * 0xffff ;

the result will be clobbered to 32 bits because that''s the length of an
integer. How do I keep all the intermediate steps at 64 bits without
peppering my operands with (uint64_t) casts?

It would help if my default sizeof(int) were 8, I guess. How can I
obtain this?

推荐答案

文章< d3 ********** @ nnrp.waia.asn.au>,

Richard Cavell< ri *********** @ mail.com>写道:
In article <d3**********@nnrp.waia.asn.au>,
Richard Cavell <ri***********@mail.com> wrote:
在我的G4上使用GCC,如果我有这样的计算:
#include< stdint.h>
uint64_t a = 0xffff * 0xffff;


明确指定的积分值默认为''int''除非

是类型修饰符或上下文提供使用更广泛的理由

类型。


结果将被破坏为32位,因为这是一个
整数的长度。如何保持所有中间步骤为64位而不用(uint64_t)强制转换我的操作数?


在代码更改方面,您可以使用:


uint64_t a = 0xffff *(unit64_t)0xffff;


或者你可以使用


uint64_t a = 0xffffLU * 0xffffLU;


如果我的默认sizeof(int会有帮助)我猜是8岁。我怎样才能获得这个?
Using GCC on my G4, if I have a calculation like this: #include <stdint.h> uint64_t a = 0xffff * 0xffff ;
Integral values explicitly specified default to ''int'' unless there
is a type modifier or the context provides reason to use a wider
type.

the result will be clobbered to 32 bits because that''s the length of an
integer. How do I keep all the intermediate steps at 64 bits without
peppering my operands with (uint64_t) casts?
In terms of code changes, you could use:

uint64_t a = 0xffff * (unit64_t) 0xffff ;

or you could use

uint64_t a = 0xffffLU * 0xffffLU;

It would help if my default sizeof(int) were 8, I guess. How can I
obtain this?




这是具体的瑕疵。我方便的gcc版本

没有列出G4的选项;我建议你检查你的gcc

手册页下的配置相关选项部分;

如果你在那里找不到它,那么试试看.info文件

很多真实文档都适用于FSF产品。


例如,在MIPS系统(例如SGI)上,有-mint64


-

我想确保[一位用户]无法通过...在线
$ b没有点击微软广告的$ b体验

- 史蒂夫鲍尔默[微软首席执行官]



That is implimentation specific. The version of gcc that I have handy
does not list options for the G4; I suggest you check your gcc
man page under the section "Configuration Dependent Options";
and if you do not find it there then try looking at the .info files
that a lot of the real documentation is in for FSF products.

As an example, on MIPS systems (e.g., SGI), there is -mint64

--
"I want to make sure [a user] can''t get through ... an online
experience without hitting a Microsoft ad"
-- Steve Ballmer [Microsoft Chief Executive]


Richard Cavell< ri **** *******@mail.com>写道:
Richard Cavell <ri***********@mail.com> writes:
在我的G4上使用GCC,如果我有这样的计算:

#include< stdint.h>

uint64_t a = 0xffff * 0xffff;

结果将被破坏为32位,因为这是整数的长度。如何将所有中间步骤保持为64位
而不用(uint64_t)强制转换我的操作数?
Using GCC on my G4, if I have a calculation like this:

#include <stdint.h>

uint64_t a = 0xffff * 0xffff ;

the result will be clobbered to 32 bits because that''s the length of
an integer. How do I keep all the intermediate steps at 64 bits
without peppering my operands with (uint64_t) casts?




将一个操作数指定为`unsigned long long类型'':

uint64_t a = 0xffffULL * 0xffff;

-

int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz. \

\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \

);}返回0;}



Designate one operand as type `unsigned long long'':
uint64_t a = 0xffffULL * 0xffff;
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}


ro ****** @ ibd.nrc-cnrc.gc.ca (Walter Roberson)写道:
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
文章< d3 ** ********@nnrp.waia.asn.au>,
Richard Cavell< ri *********** @ mail.com>写道:
In article <d3**********@nnrp.waia.asn.au>,
Richard Cavell <ri***********@mail.com> wrote:
在我的G4上使用GCC,如果我有这样的计算:
Using GCC on my G4, if I have a calculation like this:


#include< stdint.h>
#include <stdint.h>


uint64_t a = 0xffff * 0xffff;
uint64_t a = 0xffff * 0xffff ;



明确指定的积分值默认为''int''除非有
是一个类型修饰符或上下文提供了使用更宽的类型的理由。



Integral values explicitly specified default to ''int'' unless there
is a type modifier or the context provides reason to use a wider
type.




表达式的类型不受其中的上下文的影响

出现。 (指针上下文中的空指针常量是我能想到的唯一的

异常。)如果是,0xffff和

乘法的结果将继承uint64_t类型由

上下文提供。


表达式的结果通常会隐式转换为某种类型的

类型上下文。例如(假设32位int),

给出:


uint64_t a = 0xffff;


常量0xffff的类型为int,但结果是在用于初始化a之前隐式地将
转换为uint64_t。但是这些

上下文驱动的隐式转换只发生在一个层次上;

uint64_t上下文

uint64_t a = 0xffff * 0xffff;


仅影响乘法的结果,而不影响操作数。


这使得在<中使用固定宽度类型stdint.h>棘手。你可以

声明一切都是固定大小的,并且从不参考

预定义类型short,int,long等,但是
预定义类型仍然会影响代码的语义。

语言为有符号和无符号long和long long提供后缀,

但不适用于固定宽度类型。演员阵容可能是最好的

方法(其中一种罕见的情况是演员阵容在便携式场景中很有用

代码)。


- -

Keith Thompson(The_Other_Keith) ks***@mib.org < http:// www .ghoti.net / ~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



The type of an expression is not affected by the context in which it
appears. (A null pointer constant in a pointer context is the only
exception I can think of.) If it were, 0xffff and the result of the
multiplication would inherit the uint64_t type provided by the
context.

Very often the result of an expression is implicitly converted to some
type imposed by its context. For example (assuming 32-bit int),
given:

uint64_t a = 0xffff;

the constant 0xffff is of type int, but the result is implicitly
converted to uint64_t before being used to initialize a. But these
context-driven implicit conversions happen only on a single level;
the uint64_t context in

uint64_t a = 0xffff * 0xffff;

affects only the result of the multiplication, not the operands.

This makes using the fixed-width types in <stdint.h> tricky. You can
declare everything to be of some fixed size, and never refer to the
predefined types short, int, long, et al, but the ranges of the
predefined types can still affect the semantics of your code. The
language provides suffixes for signed and unsigned long and long long,
but not for the fixed-width types. Casts are probably the best
approach (one of the rare cases where casts are useful in portable
code).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于以64位获得中间结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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