隐式转换在C ++中浮点数的整数计算 [英] Implicit casting Integer calculation to float in C++

查看:120
本文介绍了隐式转换在C ++中浮点数的整数计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何编译器有一个指令或参数来将整数计算隐式浮动。例如:

Is there any compiler that has a directive or a parameter to cast integer calculation to float implicitly. For example:

float f = (1/3)*5;
cout << f;

f为0,因为计算的常数(1,3,10) 。我想用编译器指令或参数转换整数计算。我的意思是,我不会使用显式转换或.f前缀:

the "f" is "0", because calculation's constants(1, 3, 10) are integer. I want to convert integer calculation with a compiler directive or parameter. I mean, I won't use explicit casting or ".f" prefix like that:

float f = ((float)1/3)*5;

float f = (1.0f/3.0f)*5.0f;



< .f的东西?

Do you know any c/c++ compiler which has any parameter to do this process without explicit casting or ".f" thing?

推荐答案

如果你不喜欢你提到的两种方法,运气。

If you don't like either of the two methods you mentioned, you're probably out of luck.

你希望用这个做什么?任何执行浮动划分的专门操作符都必须在标记化之后的某个时间将int转换为浮点,这意味着你不会在执行上获得任何性能上的优势。

What are you hoping to accomplish with this? Any specialized operator that did "float-division" would have to convert ints to floats at some point after tokenization, which means you're not going to get any performance benefit on the execution.

这篇关于隐式转换在C ++中浮点数的整数计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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