ref: 3c7cf598f83d27ac3b98e0061075052f9f9baaf1
dir: /lib/math/test/log-overkill.myr/
use std use math use testr /* Test the extra-precision log() function of log-overkill.myr. We only test inputs in a reasonable range, because this function is only used by the various pow* functions, so its input should already be normalized. */ const main = { testr.run([ [.name="log-overkill-01", .fn = log01], [.name="log-overkill-02", .fn = log02], ][:]) } /* Commented-out entries are off by one or two ulps. */ const log01 = {c var inputs : (uint32, uint32, uint32)[:] = [ (0x3e064666, 0xc0020570, 0xb31d3367), (0x41a210cc, 0x40408c3e, 0x32d67b14), (0x3d4179b1, 0xc0435e10, 0x33ddd9f2), (0x41f80c99, 0x405bc9b2, 0x33e2ee76), (0x3bf31225, 0xc09cec61, 0x34666578), (0x7fc5acf4, 0xffc00000, 0xffc00000), (0x3d951adb, 0xc027ad92, 0x329b2b14), (0x406c0805, 0x3fa70ce9, 0xb317a93b), //(0x3dc554d4, 0xc015be36, 0xb3b98877), (0x4168b510, 0x402b5720, 0xb3a1b4f0), (0x40de6245, 0x3ff8264f, 0x32ca972e), (0x3f3e70d0, 0xbe9777e9, 0xb1abc5cb), (0x3ce907fb, 0xc063d2cc, 0xb3c0b1e5), (0x42620a10, 0x408119ed, 0xb46e5f23), //(0x3d66c8cb, 0xc0381503, 0x30678ced), (0x3d9b70a7, 0xc02503d5, 0x32985d8e), (0xffa9f86b, 0xffc00000, 0xffc00000), (0xffb90a0e, 0xffc00000, 0xffc00000), (0x3ac5e138, 0xc0cfddf1, 0xb3183fc3), (0x3e4d6b8e, 0xbfcd9efd, 0xb34112b5), (0x41c68585, 0x404d887f, 0x33ec7a86), (0x3e1ff255, 0xbfeda61c, 0x32a4597e), (0x40212290, 0x3f6c614a, 0xb260dbed), (0x3ffef4dc, 0x3f306668, 0x3251ff94), (0x3c2acf70, 0xc0920840, 0x3423757f), (0x3eca034d, 0xbf6e1407, 0xb1e20a45), (0x401f1faa, 0x3f692a1b, 0xb0e6f386), (0xff924ed6, 0xffc00000, 0xffc00000), (0x3dde9a94, 0xc00e07ca, 0x32cac4f6), (0x3f5a3ea5, 0xbe2363d5, 0x31d40c16), (0x3d0d721e, 0xc0576a15, 0xb3267b54), (0x4096bb03, 0x3fc65e76, 0xb35d04c9), (0x3c286893, 0xc0927c42, 0x3452ed38), (0x409d6c90, 0x3fcbee38, 0xb0812022), (0x410e42f3, 0x400bd853, 0xb34ea1b1), (0x3c83eeb8, 0xc0841dae, 0x3361e7f0), (0x3ec6be28, 0xbf724193, 0xb2e12e9f), //(0x42a04df2, 0x408c4923, 0xb3123a17), (0x3dae72a5, 0xc01da1ae, 0xb3ef93ad), (0x40a564e7, 0x3fd24092, 0xb2b04b3a), (0xffdf964f, 0xffc00000, 0xffc00000), (0x3efbab20, 0xbf35d075, 0x30c29d03), (0x3bd1c6ca, 0xc0a1a325, 0x34346c03), (0x420b22d1, 0x40632566, 0xb3d096e6), (0x427215df, 0x40834bbf, 0xb26b7be4), (0x3cfe7d24, 0xc05e2f9e, 0xb3a67d1c), (0x7ff7c700, 0xffc00000, 0xffc00000), //(0x3b6d287b, 0xc0b3e460, 0x332811e1), (0x3da95f09, 0xc01f858c, 0x3203e75d), (0x40550116, 0x3f99e932, 0xb37c7f51), (0x3ab855e3, 0xc0d222c6, 0x343b7062), (0x3eb3b944, 0xbf8600f3, 0xb2aa74ad), (0x3a832581, 0xc0dd07ad, 0xb392c172), (0x3dededb8, 0xc009c4fe, 0x333fcc75), (0x4241474c, 0x40782e7f, 0xb3b85075), (0x3b51550e, 0xc0b7e2c6, 0x33c8ea73), (0x3feb708b, 0x3f1c033a, 0xb16315be), (0x4109dcd1, 0x4009d5b5, 0xb3bc8763), (0x3f608f42, 0xbe062e61, 0x31df27bb), (0x402b87ff, 0x3f7c62c8, 0x32400557), (0x3c5161c6, 0xc08b844e, 0xb38b064e), (0x3abdaffc, 0xc0d13851, 0x34226ee0), (0x3e0a9b16, 0xbffffab0, 0x33153c0a), (0x3f86422e, 0x3d4387c2, 0xb09e0810), (0x3c4943fe, 0xc08cc82c, 0xb3b272a4), (0x3c09995c, 0xc098f370, 0x337aae82), (0x3dcc9670, 0xc0136e8d, 0xb2fa279c), (0x3b4a5d8c, 0xc0b8f80d, 0xb44e2bdd), (0x3b10ef54, 0xc0c3a677, 0x330fe58e), (0x40a4299a, 0x3fd14ba4, 0x3373219b), //(0x4174c7f5, 0x402e93e0, 0xb2e8d1a7), (0x7fdafcd0, 0xffc00000, 0xffc00000), (0x4141df1c, 0x401fa7a4, 0xb293e445), (0x3eb7f2cc, 0xbf830798, 0x3326b7a4), (0x3c4f0693, 0xc08be104, 0x33457d70), (0x3a996967, 0xc0d80316, 0xb2f994c1), (0x3f0b1dc5, 0xbf1c2043, 0x3255d211), (0x7fa77367, 0xffc00000, 0xffc00000), (0x42091ff2, 0x406236d6, 0x33aaeb0c), //(0x3f9075dd, 0x3df7c1d6, 0x2b437f70), (0x3ec76138, 0xbf716fdf, 0xb1cf4b2a), (0x411e876a, 0x4012c639, 0x32cdf984), (0x3e3435cb, 0xbfde616d, 0xb36a44c5), (0x7fde9793, 0xffc00000, 0xffc00000), (0x41903949, 0x4039154b, 0xb3e93b77), (0x418a88de, 0x403681e8, 0xb1c35fed), (0x42195823, 0x40695e79, 0x33da2247), (0x3e23b534, 0xbfeaac7a, 0x333b9184), (0x3f38811c, 0xbea7aeab, 0xb2035974), (0x4149bb60, 0x402232cf, 0xb3a796da), (0x41f1eb7a, 0x405a2fc2, 0xb36edf06), (0x3d4581d4, 0xc0420c26, 0x3371bdc3), (0x4167d2ce, 0x402b18c7, 0x33e01e7d), //(0x414b2e8b, 0x4022a824, 0xb2d79adf), (0x3ab71624, 0xc0d25a78, 0x3407187d), (0xffc0330b, 0xffc00000, 0xffc00000), (0x3bf24b92, 0xc09d0690, 0x34428dae), (0x3b649052, 0xc0b512c2, 0x3364cef1), (0x3d9075aa, 0xc029b420, 0x32fff057), (0x4207cfdd, 0x40619939, 0xb190080f), ][:] for (x, y1, y2) : inputs var xf : flt32 = std.flt32frombits(x) var y1f : flt32 = std.flt32frombits(y1) var y2f : flt32 = std.flt32frombits(y2) var r1f, r2f (r1f, r2f) = math.logoverkill32(xf) testr.check(c, r1f == y1f && r2f == y2f, "log(0x{b=16,w=8,p=0}) should be (0x{b=16,w=8,p=0}, 0x{b=16,w=8,p=0}), was (0x{b=16,w=8,p=0}, 0x{b=16,w=8,p=0})", x, y1, y2, std.flt32bits(r1f), std.flt32bits(r2f)) ;; } const log02 = {c var inputs : (uint64, uint64, uint64)[:] = [ (0x3f8a92cfe4c879dd, 0xc01160fa5e8a9274, 0xbc917bec31c59733), (0x3fdcbde7752d4339, 0xbfe99df158595cd2, 0x3c5e051326211e5f), (0x4049c21ac69da8fb, 0x400f890367199d9f, 0x3ca3c7bc43b3a7bf), (0x3fdf7df87f170e95, 0xbfe6b15582a8021a, 0x3c59170acc3a93ac), (0x3fa33efe56ef1925, 0xc00a3f8645c8921d, 0xbcab31ca72888736), (0x3f8eb16a31ea9437, 0xc010cd65c2f67333, 0xbcb05fe9a1ef1357), (0x3f974b5311aeae57, 0xc00e4420e231d7f0, 0xbc9d614ed9b94484), (0x3fe28aed659dab73, 0xbfe1760d162fed7e, 0xbc64a0ff30250148), (0x403273d9892e62d3, 0x40075255633e0533, 0xbc91eb9834046d7b), /* This one catches naive catastrophic cancellation */ (0x3fee1d239d2061d7, 0xbfaf1ad3961ab8ba, 0xbbc9bff82ae3fde7), (0x3fbc0666ebc60265, 0xc001b257198142d0, 0xbca1cf93360a27f6), (0x3f53267a24ceab6a, 0xc01b01c8ad09c3c1, 0xbca0d85af74df975), (0x3fd2005446cb268e, 0xbff44b879f2ec561, 0x3c66e8eff64f40a1), (0x404c495cb7ea6e6b, 0x401024631de2a59a, 0xbcb0dc3bd3a88f14), (0x3fc37680a1b7c852, 0xbffe22e609516976, 0xbc9b49bc37601215), (0x3fe26c01523f67a8, 0xbfe1ab96ed675629, 0xbc8cb9b8209aac7c), (0x3facd27e97d8c4b3, 0xc007047576bb7dae, 0xbc8e4a38613d1b43), (0x400f56fb7037ba7d, 0x3ff5d8de6ad03a3d, 0x3c8c1c5a6d1511a9), (0x3fc570f145460d05, 0xbffc966460e1709c, 0x3c94af6de9212790), (0x3fa809e6ed829a68, 0xc0087822f56ac395, 0x3c8678342157ac85), (0x3f55823e1e200f42, 0xc01a8adac8967a45, 0x3cb7be1b6b7dd05e), (0x405784744f92d247, 0x40122d177db51497, 0xbcb68ecdab1f3e8a), (0x3fab4cbea9976254, 0xc0077399de5b1e6c, 0x3cab9184e0d9f693), (0x3fdea414a2b5f667, 0xbfe791c90d39b559, 0x3c7fccdcd93c8396), (0x4058c25cbee955fc, 0x401261c8d103d77f, 0x3cbb3825321123b7), (0x3ff30000aa9a48c0, 0x3fc5ff34edfa415b, 0x3c05ef4da5cc3d05), (0x3fccce5d53963f87, 0xbff7dcf30350acb1, 0x3c9f40d3134e3ad5), (0x3fc670550e615cc0, 0xbffbdc1d2b8a9b59, 0xbc919aeccfafca2c), (0x3f85b54e302d0f6a, 0xc012300dd72719c1, 0xbc89f5a3d1cdb2e1), (0x402386e5450b51a7, 0x40023aab9fb1da19, 0x3ca2c7af66ae419b), (0x3ff6959f36e58464, 0x3fd60f20e1496691, 0xbc6018ad87980799), (0x3f600e959bdc4215, 0xc018f067a04992e6, 0xbc9e3fe4581527a9), (0x3f568e6f133c989b, 0xc01a5a27ce23b3c6, 0x3ca06da90a0ee1a3), (0x402c19721717a0ed, 0x4005240bf65143ae, 0x3cae244b763ae814), (0x3fbb13aebb1a4839, 0xc001f8d370035c97, 0x3ca0b45e0003fc1b), (0x4033102153118b25, 0x400794fdcf559b7e, 0xbc96afebbfc675de), (0x3f537adaddec30d9, 0xc01af04f3bdc1d51, 0x3cb11840ac75087e), (0x3f60bfa935803114, 0xc018c537670bd5fd, 0x3cbffed98ba70ea0), (0x40359fdaa8225f24, 0x40089730e1a85732, 0x3c5a95afca1885f9), (0x3fc175000ebd1ad0, 0xbfffe06913afd5fe, 0xbc987c68046a4b2b), (0x3f972d70572c34da, 0xc00e4e6affcb0d69, 0x3c944da2b4a32e8b), (0x404517d0a0f954f1, 0x400defccb99937fb, 0xbca1c136d4f696bd), (0x3fdfb653305a1ee4, 0xbfe6784521bc975c, 0xbc740e603a0d13fa), (0x3fae6163881229a6, 0xc00698a129128185, 0xbca942e03278e8ab), (0x3fc9b9b239873842, 0xbff9ac3f1cc4718f, 0xbc92a473acf76c1a), (0x4003e596f5fa87a5, 0x3fed27e34824474b, 0x3c7f931c3eb17713), (0x3f745e0770c0cfac, 0xc0153720a362d3a6, 0x3cbc60e53acef442), (0x3ff5475469f15847, 0x3fd23f517f2dbe19, 0x3c5121e6c154dd81), (0x3f9e13761b9e29aa, 0xc00c38d1a2b3226f, 0xbc9005203d9c6052), (0x40295d7732b1928b, 0x400452628d50de4a, 0xbc4ed3676ab974b5), (0x3f62950d7337c671, 0xc0185ad612d393eb, 0x3cbeb1d1a30a44c1), (0x3fd2bde1daa23c6a, 0xbff3a66c4d1ad065, 0x3c6923aafd35c010), (0x405549c0fb4d986f, 0x4011c71bf85e6e4a, 0xbcb733ae08222b6e), (0x3f5f4efc3afddc5d, 0xc0190a69efff1b0d, 0x3c9fbcb89efdcd50), (0x404c494cad96babd, 0x40102460d9352cb6, 0x3cb4422e754c9f46), (0x3feca6325d6abdee, 0xbfbc50f2c5fd3c19, 0xbc324eb80eb13744), (0x4033b1089f54810d, 0x4007d76d5362f9ab, 0x3ca2797a76df7f34), (0x3fb568b670585cfd, 0xc003d9d59db58016, 0x3c96e6b1033b5db7), (0x3f7a4b16328a04e3, 0xc014319d5482cfa4, 0xbca5c490a1c64c36), (0x403860ebb2cc92ab, 0x40098cb57f4e07d2, 0xbcac4c5cb21f0a09), (0x3f8f699b31fc25d3, 0xc010b5ab9279b85e, 0xbc8f89278a4cb33e), (0x402960d16df7e842, 0x4004537129c98c04, 0xbcaa05a89ebbaeb6), (0x3f7b1ee11dc6efb9, 0xc01411e41d504509, 0x3cbc00518be08e27), (0x3f689b59b7cedd72, 0xc0173b474018f50c, 0xbcb2bca19c384d9b), (0x3fffea8b7062e501, 0x3fe618c73ad1ebbe, 0x3c7fd2ed59c5733b), (0x3f5444bf49407dcb, 0xc01ac7ab90ee3df2, 0xbcae95724cec72f7), (0x3fd9d0459601ade3, 0xbfed0e32876b58cc, 0x3c887d50c70101d8), (0x3fa6149e59686077, 0xc009262661604245, 0x3caa9c6eae5c2bf0), (0x400f2eef1f07ec55, 0x3ff5c45f2900b421, 0x3c9b3e071d8ba3fb), (0x4049fe32d48952f4, 0x400f9b97bfc6db20, 0xbca2bde351b359d4), (0x3fa71132a433e561, 0xc008cc9fa0c868b2, 0x3c7c8ee247413c51), (0x3fe9e1080fe367d7, 0xbfcb2cbe2a374cc5, 0xbc66334680dbd7b4), (0x3f82b3495c06976d, 0xc012c8c882486192, 0xbca509424bf6cd86), (0x3f98b38fffa575d7, 0xc00dcc00f9c3d7b0, 0xbc97c42e61bc1601), (0x3fd37b54f8eb6485, 0xbff307cca9e335a2, 0xbc8aa7fac0e02bcb), (0x404ee2915c521fe7, 0x40107e617f569191, 0xbcbcc3b1d0962048), (0x3f53f44cc701e150, 0xc01ad7abbb5f390d, 0xbcb0de2e1a1f03c6), (0x401966b9da967882, 0x3ffd9379ec0424c4, 0x3c5bfd6202281021), (0x4021d99afb55ff01, 0x400182c7b9c135e4, 0x3ca1f0c43451a487), (0x3fb9ac4522c48658, 0xc00265de40742912, 0x3ca9241f75f83a46), (0x4017ce46954f5151, 0x3ffc89c32c306e36, 0x3c94073d23df5f61), (0x3f95f1017c2d7cae, 0xc00ebea8b58ec314, 0x3ca5ba6bc5a40177), (0x40196a636809aa8c, 0x3ffd95c84f74799e, 0xbc966910c2a6b4a9), (0x4032fb17a164e627, 0x40078c24c23d49e9, 0xbcabd33227e7440a), (0x401527d0beb5b398, 0x3ffaa65372b6ed05, 0x3c9c092468a3d811), (0x3fb0070ab95eda9b, 0xc0062abe686b059c, 0x3ca08e8de0559f9b), (0x3ff7b00fd8bccd43, 0x3fd91c92bbe66ba2, 0x3c71ec38fe18a6f3), (0x4021b9bc8823cfde, 0x4001747278d08206, 0xbca0dfe566dc4cf5), (0x4014a5ce06d7df05, 0x3ffa42cc8df38d10, 0xbc5e54e0ca2ed44c), (0x3f68d1447d5a29e8, 0xc017328d1195bac4, 0x3cb4fd5db024d1da), (0x404963f9a80919eb, 0x400f6b9160b05ec4, 0x3c4526374db12c53), (0x3fe78000b3cf1a39, 0xbfd3c2508d81ebf9, 0x3c7d6df43454d213), (0x7fe6c53d8cef3d27, 0x40862b8a1ec909c8, 0x3cf9a8752da53a7e), (0x000342cdeeb18fc9, 0xc0862fe5598ee7e6, 0xbd2bf7df7d1e9517), ][:] for (x, y1, y2) : inputs var xf : flt64 = std.flt64frombits(x) var r1f : flt64, r2f : flt64, r1u : uint64, r2u : uint64 (r1f, r2f) = math.logoverkill64(xf) r1u = std.flt64bits(r1f) r2u = std.flt64bits(r2f) /* Cut ourselves some slack on the second component */ testr.check(c, r1u == y1 && (r2u & 0xfffffffffff00000) == (y2 & 0xfffffffffff00000), "log(0x{b=16,w=16,p=0}) should be (0x{b=16,w=16,p=0}, 0x{b=16,w=16,p=0}), was (0x{b=16,w=16,p=0}, 0x{b=16,w=16,p=0})", x, y1, y2, r1u, r2u) ;; }