使用截断朝负无穷大到零的优点 [英] Advantages of using truncation towards minus infinity vs towards zero

查看:153
本文介绍了使用截断朝负无穷大到零的优点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用截断到负无穷大( Haskell ,Ruby)的好处是什么从编程语言/编译器实现的角度,截断到零(C,PHP)。

I was wondering which are the benefits of using truncation towards minus infinity (Haskell, Ruby) instead of truncation towards zero (C, PHP), from the perspective of programming languages/compilers implementation.

似乎向负无穷大截断是正确的方法,但我没有找到这样的声明的可靠来源,也不知道这样的决定如何影响实现编译器。

It seems that truncating towards minus infinity is the right way to go, but I haven’t found a reliable source for such claiming, nor how such decision impact the implementation of compilers. I’m particularly interested in possible compilers optimizations, but not exclusively.

相关来源:

Haskell部门

quotRem和divMod之间的区别何时有用?

推荐答案

这些实际上甚至不是唯一的选择,事实上,甚至通常不是最好的。我可以在这里总结,但也许更好的是链接到这个优秀的文件,对比截断,地板和欧几里得分,涵盖了理论和一些现实世界的应用程序,函数的欧几里得定义div和mod ,Raymond T. Boute。

These actually are not even the only choices and, in fact, maybe not even usually the best. I could summarize here, but it is perhaps better to just link to this excellent paper that contrasts truncate, floor, and Euclidean division, covering the theory and some real world applications, The Euclidean Definition of Functions div and mod, Raymond T. Boute.

这篇关于使用截断朝负无穷大到零的优点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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