fdlibmのsqrt実装を使用したい。
この実装では、(エンディアンに応じて)次の方法で(ダブルの下位/上位32ビットにアクセスするための)いくつかのマクロを定義します(ここでは、リトルエンディアンバージョンのみ)。
#define __HI(x) *(1+(int*)&x)
#define __LO(x) *(int*)&x
#define __HIp(x) *(1+(int*)x)
#define __LOp(x) *(int*)x
flibmのreadmeは、次のように言っています(少し短縮されています)
Each double precision floating-point number must be in IEEE 754
double format, and that each number can be retrieved as two 32-bit
integers through the using of pointer bashing as in the example
below:
Example: let y = 2.0
double fp number y: 2.0
IEEE double format: 0x4000000000000000
Referencing y as two integers:
*(int*)&y,*(1+(int*)&y) = {0x40000000,0x0} (on sparc)
{0x0,0x40000000} (on 386)
Note: Four macros are defined in fdlibm.h to handle this kind of
retrieving:
__HI(x) the high part of a double x
(sign,exponent,the first 21 significant bits)
__LO(x) the least 32 significant bits of x
__HIp(x) same as __HI except that the argument is a pointer
to a double
__LOp(x) same as __LO except that the argument is a pointer
to a double
If the behavior of pointer bashing is undefined, one may hack on the
macro in fdlibm.h.
この実装とこれらのマクロをcbmcモデルチェッカーで使用したいと思います。これはansi-cに準拠している必要があります。
何が問題なのか正確にはわかりませんが、次の例は、これらのマクロが機能していないことを示しています(リトルエンディアンが選択され、32ビットのマシンワードが選択されました)。
temp=24376533834232348.000000l (0100001101010101101001101001010100000100000000101101110010000111)
high=0 (00000000000000000000000000000000)
low=67296391 (00000100000000101101110010000111)
どちらも間違っているようです。tempのすべての値に対してHighは空のようです。
ansi-cで両方の32ワードにアクセスするための新しいアイデアはありますか?
更新:すべての回答とコメントをありがとう。あなたの提案はすべて私のために働いた。今のところ、「R ..」バージョンを使用することにし、エンディアンに関して私のツールで最も堅牢であると思われるため、これをお気に入りの回答としてマークしました。