タグ

floatに関するdlive1のブックマーク (1)

  • 浮動小数点演算ではまった話 - bkブログ

    浮動小数点演算ではまった話 浮動小数点演算のありがちな問題ではまりました。 いろいろ調べているうちに x86 特有のちょっとおもしろい 現象に遭遇したので紹介したいと思います。 パーセンテージの計算 簡単な C のプログラムでパーセンテージを計算しようと思い、 次のようなコードを書きました。 int x, y; ... int a = (double)x / y * 100; int a = x * 100 / y としないのは、 x が大きい場合に x * 100 が オーバーフローを起こす (INT_MAX を越える) ためです。 このコードは一見、期待通りに動いていたのですが、 しばらく使っていると、手元の環境では x = 53, y = 100 のときに a は 53 ではなく 52 になることに気づきました。 これは次の理由によります。 式の最初の (double)53 / 10

    dlive1
    dlive1 2007/03/10
    %計算の切捨て問題。Overflowが起きる。
  • 1
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy