轮数错了

时间:2015-11-09 08:13:27

标签: excel excel-2010 excel-2007 precision

我的一位朋友在MS Excel中发现了一件非常奇怪的事情。 Excel以错误的方式对某些特定数字进行舍入,实际上它会向下舍入一个不需要舍入的数字。

据我测试,它发生在大多数版本的MS Excel 2007 +

EG。数字10358.1657899999将向下舍入为8192.165790 - 65535.165790

显然它只发生在这个时间间隔内:.165890

这真的很奇怪 - 例如,它不会发生。 .165690.165790,仅限classMPCManager:NSObject,MCSessionDelegate,MCNearbyServiceBrowserDelegate, MCNearbyServiceAdvertiserDelegate { var delegate: MPCManagerDelegate? var session: MCSession! var sessionList: [MCSession]! = [] var peer: MCPeerID! var browser: MCNearbyServiceBrowser! var advertiser: MCNearbyServiceAdvertiser! var foundPeers:[NSDictionary]! = [] var invitationHandler: ((Bool, MCSession!)->Void)! var discoveryInfo:[String: String]! init(discoveryInfo:[String:String]!, peer:MCPeerID!) { super.init() self.discoveryInfo = discoveryInfo self.peer = peer session = MCSession(peer: self.peer) session.delegate = self browser = MCNearbyServiceBrowser(peer: peer, serviceType: "myservicetype") browser.delegate = self advertiser = MCNearbyServiceAdvertiser(peer: self.peer, discoveryInfo: self.discoveryInfo, serviceType: "myservicetype") advertiser.delegate = self } /////some other methods ///the problematic method func setAdvertising(discoveryInfo:[String:String]!){ print("setting advertising") self.discoveryInfo = discoveryInfo advertiser.stopAdvertisingPeer() advertiser = nil self.advertiser = MCNearbyServiceAdvertiser(peer: self.peer, discoveryInfo: self.discoveryInfo, serviceType: "myservicetype") self.advertiser.delegate = self print("advertising from set advertising") advertiser.startAdvertisingPeer() }

你们中的任何人都知道为什么会发生这种情况吗?为什么它只能说明某些数字?

1 个答案:

答案 0 :(得分:0)

Excel使用IEEE754 64位双精度浮点类型来表示数值数据;使用一些聪明的格式和综合技巧来获得1/3 + 1/3 + 1/3正确的总和。

您所观察到的是数字方案的自然结果,只能精确到15位有效数字。除非数字恰好是二元理性,在这种情况下它可以精确存储,最接近的可表示数字将被选择为您真正想要的数字。这可能低于或高于舍入截止值。

除了您引用的范围之外,还会出现在其他范围内。