CEIL()和地板的执行情况() [英] Implementation of ceil() and floor()

查看:111
本文介绍了CEIL()和地板的执行情况()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是好奇如何这些实现​​的。我看不出在那里我将开始。难道他们直接在浮法工作的/ 双击的位?

Just curious how are these implemented. I can't see where I would start. Do they work directly on the float's/double's bits?

另外在哪里可以找到从math.h中函数的源$ C ​​$ C?所有我看到的是与原型或文件与调用其他函数从别的地方要么功能头。

Also where can I find the source code of functions from math.h? All I find are either headers with prototypes or files with functions that call other functions from somewhere else.

修改:消息的一部分被编辑在标题后丢失。我的意思,特别是在 CEIL()地板()功能。

EDIT: Part of the message was lost after editing the title. What I meant in particular were the ceil() and floor() functions.

推荐答案

如果你有兴趣看到源$ C ​​$ C的算法这种事情,那么的 fdlibm - 在自由分发的libm ,最初来自Sun和对Java的数学库的参考实现 - 可能是一个好开始的地方。 (对于随意浏览,它肯定是一个更好的地方开始比 GNU libc的,其中片散落在不同的子目录 - 数学/ sysdeps / IEEE754 / 等)

If you're interested in seeing source code for algorithms for this kind of thing, then fdlibm - the "Freely Distributable libm", originally from Sun, and the reference implementation for Java's math libraries - might be a good place to start. (For casual browsing, it's certainly a better place to start than GNU libc, where the pieces are scattered around various subdirectories - math/, sysdeps/ieee754/, etc.)

fdlibm假定它正在与一个IEEE 754格式双击,如果你看一下实现 - 例如,的日志的落实(核心) - 你会看到,他们利用各种聪明的把戏,常常同时使用标准的双算术和的位重presentation知识的双击

fdlibm assumes that it's working with an IEEE 754 format double, and if you look at the implementations - for example, the core of the implementation of log() - you'll see that they use all sorts of clever tricks, often using a mixture of both standard double arithmetic, and knowledge of the bit representation of a double.

(如果你有兴趣的算法来支持基础IEEE 754浮点运算,比如可以用于没有硬件处理器的浮点支持,看看约翰·豪瑟的的SoftFloat 。)

(And if you're interested in algorithms for supporting basic IEEE 754 floating point arithmetic, such as might be used for processors without hardware floating point support, take a look at John R. Hauser's SoftFloat.)

至于你的编辑:在一般情况下, CEIL()地板()很可能在硬件中实现;例如,在x86,海湾合作委员会(与最佳化启用)生成使用与FPU控制字来设置舍入模式的适当摆弄了 FRNDINT 指令code。但是fdlibm是纯粹的软件实现( s_ceil.c ,< A HREF =htt​​p://www.netlib.org/fdlibm/s_floor.c> s_floor.c )做使用位重新$ p工作$ psentation直接。

As for your edit: in general, ceil() and floor() might well be implemented in hardware; for example, on x86, GCC (with optimisations enabled) generates code using the frndint instruction with appropriate fiddling of the FPU control word to set the rounding mode. But fdlibm's pure software implementations (s_ceil.c, s_floor.c) do work using the bit representation directly.

这篇关于CEIL()和地板的执行情况()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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