什么是div()函数库的目的是什么? [英] What is purpose of the div() library function?

查看:146
本文介绍了什么是div()函数库的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C有 / 运算符分隔两个数字,什么是具有的 DIV()库函数

When c has the / operator to divide two numbers, what is the purpose of having the div() library function?

有什么方案,其中 / 不能使用,但 DIV()可以吗?

Is there any scenario where / can't be used but div() can?

推荐答案

从C99理由文档:

(7.20.6.2的DIV,LDIV和lldiv功能)因为C89为过负时操作数参与,DIV和LDIV,并在C99 lldiv签署整数的除法实现定义语义,被发明,提供良好的规范语义符号整数除法和余数运算。的语义被采纳为一样的Fortran。由于这些函数返回商和余数两者,它们也可作为有效的建模底层硬件的一种方便的方法即
  计算两个结果作为相同的操作的一部分。 [...]
  现在,C99需要除法运算符相似的语义,主要原因为新
  程序使用DIV,LDIV或lldiv是同时获得商和余数。

(7.20.6.2 The div, ldiv, and lldiv functions) Because C89 had implementation-defined semantics for division of signed integers when negative operands were involved, div and ldiv, and lldiv in C99, were invented to provide well-specified semantics for signed integer division and remainder operations. The semantics were adopted to be the same as in Fortran. Since these functions return both the quotient and the remainder, they also serve as a convenient way of efficiently modeling underlying hardware that computes both results as part of the same operation. [...] Now that C99 requires similar semantics for the division operator, the main reason for new programs to use div, ldiv or lldiv is to simultaneously obtain quotient and remainder.

这篇关于什么是div()函数库的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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