ç整数除法和地板 [英] C integer division and floor

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

问题描述

在C,是在它们之间的整数除法的a / b和地板(A / B),其中a和b是整数的差?
这两个过程中更具体地说,会发生什么?

In C, is there a difference between integer division a/b and floor(a/b) where both a and b are integers? More specifically what happens during both processes?

推荐答案

A / B 确实整数除法。如果 A B 为负时,结果取决于编译器(四舍五入可以去朝零或向负无穷大在pre-C99,C99的+,舍入云朝0)。结果类型 INT 楼(A / B)做同样的划分,将结果转换为加倍,丢弃(不存在)的小数部分,并返回结果为double。

a/b does integer division. If either a or b is negative, the result depends on the compiler (rounding can go toward zero or toward negative infinity in pre-C99; in C99+, the rounding goes toward 0). The result has type int. floor(a/b) does the same division, converts the result to double, discards the (nonexistent) fractional part, and returns the result as a double.

这篇关于ç整数除法和地板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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