タグ

Tipsとfloatに関するundertheskyのブックマーク (2)

  • Encoding floats to RGBA - the final? · Aras' website

    The saga continues! In short, I need to pack a floating point number in [0..1) range into several channels of 8 bit/channel render texture. My previous approach is not ideal. Turns out some folks have figured out an approach that finally seems to work. Here it is for my own reference: gamedev.net forum post by gjaegy Suggestion right there on my previous blog post comments Repost gamerendering blo

  • 浮動小数点演算ではまった話 - 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

  • 1