Skip to content

Instantly share code, notes, and snippets.

@karupanerura
Last active August 29, 2015 14:27
Show Gist options
  • Save karupanerura/f0dc5485de85c4c0f74e to your computer and use it in GitHub Desktop.
Save karupanerura/f0dc5485de85c4c0f74e to your computer and use it in GitHub Desktop.
GeoHexのテストケースの変更依頼

発生した問題

C99実装の浮動小数点演算の演算精度をチューニングした結果、一部のテストケースがFAILするようになった。

問題になるテストケース

  • 緯度:0
  • 経度:-60.46875

該当ファイル:

値のトレース

PI = 3.1415926535897932384L とした場合の結果:

h_pos_x = -122.4492187500000000277555756156289135105907917022705078125000000000
h_pos_y = 122.4492187499999999861222121921855432447046041488647460937500000000
h_x_0   = -123.0000000000000000000000000000000000000000000000000000000000000000
h_y_0   = 122.0000000000000000000000000000000000000000000000000000000000000000
h_x_q   = 0.5507812499999999722444243843710864894092082977294921875000000000
h_y_q   = 0.4492187499999999861222121921855432447046041488647460937500000000

h_x_q + h_y_q0.9999999999999999583666365765566297341138124465942382812500000000 となります。

PI = 3.14159265358979323846L とした場合の結果:

h_pos_x = -122.4492187500000000000000000000000000000000000000000000000000000000
h_pos_y = 122.4492187500000000069388939039072283776476979255676269531250000000
h_x_0   = -123.0000000000000000000000000000000000000000000000000000000000000000
h_y_0   = 122.0000000000000000000000000000000000000000000000000000000000000000
h_x_q   = 0.5507812500000000000000000000000000000000000000000000000000000000
h_y_q   = 0.4492187500000000069388939039072283776476979255676269531250000000

h_x_q + h_y_q1.0000000000000000069388939039072283776476979255676269531250000000 となります。 よってx/yが +1 補正されます。

このように、浮動小数点演算の精度により変わり得るデータがテストケースに用いられている為、 演算精度を向上した結果、テストがFAILする場合があります。

対応案

意図しているのは境界値テストであるという仮定のもと、入力値を以下のようにしては如何でしょうか?

  • 緯度:-0.00001
  • 経度:-60.46875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment