int,float [英] int, float

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

问题描述

我必须将浮点数转换为int而不使用强制转换i =(int)f,

不使用printf等。我只能使用int,char和structs。任何人都可以帮助吗?

谢谢

Juerg

I have to convert an float number to int without using casting i= (int) f,
without printf and others. I can only use int, char and structs. Can anyone
help?

Thanks
Juerg

推荐答案

2004年2月10日星期二17:07:56 +0100 comp.lang.c ++,链接

< ju ******** @ lilasystem .CH>据称写了:
On Tue, 10 Feb 2004 17:07:56 +0100 in comp.lang.c++, "Link"
<ju********@lilasystem.ch> was alleged to have written:
我必须将浮点数转换为int而不使用强制转换i =(int)f,
而不使用printf等。我只能使用int,char和structs。
I have to convert an float number to int without using casting i= (int) f,
without printf and others. I can only use int, char and structs.




什么是从float到int的标准内置转换

(什么你打电话给铸造这会使它不适合你的应用吗?

其他任何事情都是这样做的。



What is it about the standard built-in conversion from float to int
(what you call "casting") that makes it unsuitable for your application?
Anything else is doing it the hard way.


链接写道:
Link writes:
我必须将浮点数转换为int而不使用强制转换i =(int)f,
而不使用printf等。我只能使用int,char和structs。可以
有人帮忙吗?
I have to convert an float number to int without using casting i= (int) f,
without printf and others. I can only use int, char and structs. Can anyone help?




我认为这是学生作业。第一步是找出你的平台如何编码一个浮动的

。查看编译器附带的文档

。几乎可以肯定的是,int被编码为两个'
补码二进制数,并且它的大小将在< limits.h>中。你确定

禁止工会吗?它们可能也会变得很方便。


听起来像是一个有趣且信息丰富的练习。



I assume this is a student assignment. The first step is to find out how
your platform encodes a float. Look at the documentation that came with
your compiler. It is almost certain that an int is encoded as a two''s
complement binary number and it''s size will be in <limits.h>. Are you sure
that unions are forbidden? They might turn out to be handy, too.

Sounds like a fun and informative exercise.


是的,我有它以艰难的方式做 - 它只是一个小盒子(不是电脑)所以

我不能使用所有的库(减少内存,......)

你知道如何处理exp,尾数等,只有int和

struct?


David Harmon <所以**** @ netcom.com> schrieb im Newsbeitrag

news:40 *************** @ news.west.earthlink.net ...
Yes, I have it to do in the hard way - Its only a little box (not pc) and so
I can''t use all libs (reduced memory, ...)
You know someting about working with exp, mantissa and so, only with int and
struct?

"David Harmon" <so****@netcom.com> schrieb im Newsbeitrag
news:40***************@news.west.earthlink.net...
On Tue ,2004年2月10日17:07:56 +0100 in comp.lang.c ++,Link
< ju ******** @ lilasystem.ch>据称写了:
On Tue, 10 Feb 2004 17:07:56 +0100 in comp.lang.c++, "Link"
<ju********@lilasystem.ch> was alleged to have written:
我必须将浮点数转换为int而不使用强制转换i =(int)
f,不使用printf等。我只能使用int,char和structs。
I have to convert an float number to int without using casting i= (int) f,without printf and others. I can only use int, char and structs.



从float到int
(你称之为cast)的标准内置转换是什么使它不适合您的应用程序?
其他任何事情都是这样做的。



What is it about the standard built-in conversion from float to int
(what you call "casting") that makes it unsuitable for your application?
Anything else is doing it the hard way.



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

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