iPhone/iPad 双精度数学 [英] iPhone/iPad double precision math

查看:24
本文介绍了iPhone/iPad 双精度数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此社区 Wiki 问题的公认答案:你在编写 Objective-C 和 Cocoa 时使用的最佳实践是什么? 说 iPhone 不能做双精度数学(或者更确切地说,他们可以,但只能在软件中模拟.)不幸的是它提供的 2009 年链接作为参考:Double vs float on the iPhone与该声明相矛盾.这两个都是旧的,都是3GS刚出来的时候写的.

The accepted answer to this Community Wiki question: What are best practices that you use when writing Objective-C and Cocoa? says that iPhones can't do double precision math (or rather, they can, but only emulated in software.) Unfortunately the 2009 link it provides as a reference: Double vs float on the iPhone directly contradicts that statement. Both of these are old, being written when the 3GS was just coming out.

那么最新的 arm7 架构有什么故事呢?我是否需要担心第二个链接引用的拇指"编译器标志?我可以安全地使用 double 变量吗?我对 386SX 和 DX 以及数学协处理器"的黑暗日子有令人讨厌的倒叙.告诉我现在是 2012 年,我们已经继续前进.

So what's the story with the latest arm7 architecture? Do I need to worry about the 'thumb' compiler flag the second link references? Can I safely use double variables? I am having nasty flashbacks to dark days of 386SXs and DXs and 'math coprocessors.' Tell me it's 2012 and we've moved on.

推荐答案

在所有 iPhone 中,没有理由不支持双精度.它们都使用带有 cp15 协处理器的 Cortex-A8 架构(在硬件上支持 IEEE 浮点和双精度计算).

In all of the iPhones, there is no reason double precision shouldn't be supported. They all use Cortex-A8 architecture with the cp15 coprocessor (which supports IEEE float and double calculations in hardware).

http://www.arm.com/products/处理器/技术/vector-floating-point.php

所以是的,您可以安全地使用双打,它不应该在 iPhone 上被软件模拟.尽管这是在硬件中完成的,但执行双数学运算与单(浮点数)运算仍可能需要更多的周期.除了使用 double 之外,我还会检查以确保精度适合您的应用程序.

So yes, you can safely use doubles and it shouldn't be software emulated on the iPhones. Although this is done in hardware, it may still take more cycles to perform double mathemtic arithmatic vs single (float). In addition to using double, I would check to make sure the precision is appropriate for your application.

附带说明,如果处理器支持 NEON 指令集,则双精度和浮点数的计算速度可能比使用协处理器快.

As a side note, if the processor supports NEON instruction set, doubles and floats may be calculated faster than using the coprocessor.

http://pandorawiki.org/Floating_Point_Optimization#Compiler_Support

虽然 VFP 和 Neon 是 ARM Core 的可选扩展,但大多数 cortex-A8 都有它们,而且 iPhone 和 iPad 中使用的所有这些也都有.

Though VFP and Neon are optional extensions to the ARM Core, most of the cortex-A8 have them and all of them ones used in the iPhone and iPad do as well.

这篇关于iPhone/iPad 双精度数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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