Math.hを使用できない環境でのべき乗計算


お疲れ様です。  
C環境で、ガンマ補正関連の画質処理を作成しているのですが、  
速度をなるべく早くするということでMath.hを禁止され、  
どのようにべき乗計算をするか分からない状態であり、  
もしこうして解決したなどの経験がございましたらご教授ください。

**【実行したいこと】**  
ガンマ2.2などの画質変換用のLutテーブル作成

**【Math.hがあれば実装していたであろう内容】**  
①ガンマ2.2の画像のガンマを外す  
＝(Y / Y最大値) ^ (2.2)  
②ガンマ2.2に再度なおす  
＝(①の結果) ^ (1.0 / 2.2) * Y最大値  
//// ＝(Y) ^ (1.0 / 2.2) * Y最大値 **//間違い**

※このべき乗をpowでやる予定でした。

* * *

<追記>  
・YおよびYの最大値は整数になります。10bit 0-1023になります。  
・ガンマ値は固定値で、ガンマ2.2、ガンマ1.8、ガンマ2.6‌​で変換をかける予定です。  
・「速度 > 精度」の優先順位になっています。  
・②の式が間違っていたので修正いたしました。  
①と②は基本ワンセットになっていると思ってください。(片方だけ実行することはない)

以上、よろしくお願いいたします。




> 速度をなるべく早くするということでMath.hを禁止され、どのようにべき乗計算をするか分からない

質問の意図（というよりも質問者さんが受けた指示内容）がようやくわかりました。  
「`<math.h>`の関数を使わずLookup tableを構築する」ではなくて「Lookup
tableを使用することで`<math.h>`の関数を使わず済む」ではないでしょうか。そして予めLUT; Lookup
tableを作ってソースコードに埋め込むのではないでしょうか。

[code]

    #include <math.h>
    #include <stdio.h>
    
    const int ymax = 1023;
    const double gamma = 2.2;
    int encode(int y) {
        return (int)round(ymax * pow((double)y / ymax, 1 / gamma));
    
    }
    int decode(int y) {
        return (int)round(ymax * pow((double)y / ymax, gamma));
    }
    
    #define GENERATE(FUNC)  do {                    \
        printf("int " #FUNC "(int y) {\n");         \
        printf("    static const int lut[] = { ");  \
        for (int y = 0; y <= ymax; y++)             \
        printf("%d, ", FUNC(y));                    \
        printf("};\n");                             \
        printf("    return lut[y];\n");             \
        printf("};\n");                             \
        } while(0)
    
    int main(){
        GENERATE(encode);
        GENERATE(decode);
        return 0;
    }
    
[/code]

を実行して得られる

[code]

    int encode(int y) {
        static const int lut[] = { 0, 44, 60, 72, 82, 91, 99, 106, 113, 119, 125, 130, 136, 141, 145, 150, 155, 159, 163, 167, 171, 175, 179, 182, 186, 189, 193, 196, 199, 203, 206, 209, 212, 215, 218, 221, 223, 226, 229, 232, 234, 237, 240, 242, 245, 247, 250, 252, 255, 257, 259, 262, 264, 266, 269, 271, 273, 275, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 319, 321, 323, 325, 327, 328, 330, 332, 334, 335, 337, 339, 341, 342, 344, 346, 347, 349, 351, 352, 354, 356, 357, 359, 360, 362, 363, 365, 367, 368, 370, 371, 373, 374, 376, 377, 379, 380, 382, 383, 385, 386, 388, 389, 391, 392, 393, 395, 396, 398, 399, 401, 402, 403, 405, 406, 407, 409, 410, 412, 413, 414, 416, 417, 418, 420, 421, 422, 424, 425, 426, 427, 429, 430, 431, 433, 434, 435, 436, 438, 439, 440, 441, 443, 444, 445, 446, 448, 449, 450, 451, 452, 454, 455, 456, 457, 458, 460, 461, 462, 463, 464, 466, 467, 468, 469, 470, 471, 473, 474, 475, 476, 477, 478, 479, 480, 482, 483, 484, 485, 486, 487, 488, 489, 490, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 580, 581, 582, 583, 584, 585, 586, 587, 588, 588, 589, 590, 591, 592, 593, 594, 595, 595, 596, 597, 598, 599, 600, 601, 601, 602, 603, 604, 605, 606, 607, 607, 608, 609, 610, 611, 612, 613, 613, 614, 615, 616, 617, 618, 618, 619, 620, 621, 622, 623, 623, 624, 625, 626, 627, 627, 628, 629, 630, 631, 632, 632, 633, 634, 635, 636, 636, 637, 638, 639, 640, 640, 641, 642, 643, 644, 644, 645, 646, 647, 647, 648, 649, 650, 651, 651, 652, 653, 654, 655, 655, 656, 657, 658, 658, 659, 660, 661, 661, 662, 663, 664, 665, 665, 666, 667, 668, 668, 669, 670, 671, 671, 672, 673, 674, 674, 675, 676, 677, 677, 678, 679, 680, 680, 681, 682, 683, 683, 684, 685, 686, 686, 687, 688, 688, 689, 690, 691, 691, 692, 693, 694, 694, 695, 696, 696, 697, 698, 699, 699, 700, 701, 701, 702, 703, 704, 704, 705, 706, 706, 707, 708, 709, 709, 710, 711, 711, 712, 713, 713, 714, 715, 716, 716, 717, 718, 718, 719, 720, 720, 721, 722, 723, 723, 724, 725, 725, 726, 727, 727, 728, 729, 729, 730, 731, 731, 732, 733, 733, 734, 735, 735, 736, 737, 738, 738, 739, 740, 740, 741, 742, 742, 743, 744, 744, 745, 746, 746, 747, 748, 748, 749, 750, 750, 751, 751, 752, 753, 753, 754, 755, 755, 756, 757, 757, 758, 759, 759, 760, 761, 761, 762, 763, 763, 764, 765, 765, 766, 766, 767, 768, 768, 769, 770, 770, 771, 772, 772, 773, 773, 774, 775, 775, 776, 777, 777, 778, 779, 779, 780, 780, 781, 782, 782, 783, 784, 784, 785, 785, 786, 787, 787, 788, 789, 789, 790, 790, 791, 792, 792, 793, 794, 794, 795, 795, 796, 797, 797, 798, 798, 799, 800, 800, 801, 801, 802, 803, 803, 804, 805, 805, 806, 806, 807, 808, 808, 809, 809, 810, 811, 811, 812, 812, 813, 814, 814, 815, 815, 816, 817, 817, 818, 818, 819, 820, 820, 821, 821, 822, 822, 823, 824, 824, 825, 825, 826, 827, 827, 828, 828, 829, 830, 830, 831, 831, 832, 832, 833, 834, 834, 835, 835, 836, 836, 837, 838, 838, 839, 839, 840, 841, 841, 842, 842, 843, 843, 844, 845, 845, 846, 846, 847, 847, 848, 849, 849, 850, 850, 851, 851, 852, 853, 853, 854, 854, 855, 855, 856, 856, 857, 858, 858, 859, 859, 860, 860, 861, 862, 862, 863, 863, 864, 864, 865, 865, 866, 867, 867, 868, 868, 869, 869, 870, 870, 871, 871, 872, 873, 873, 874, 874, 875, 875, 876, 876, 877, 878, 878, 879, 879, 880, 880, 881, 881, 882, 882, 883, 884, 884, 885, 885, 886, 886, 887, 887, 888, 888, 889, 889, 890, 891, 891, 892, 892, 893, 893, 894, 894, 895, 895, 896, 896, 897, 897, 898, 899, 899, 900, 900, 901, 901, 902, 902, 903, 903, 904, 904, 905, 905, 906, 906, 907, 908, 908, 909, 909, 910, 910, 911, 911, 912, 912, 913, 913, 914, 914, 915, 915, 916, 916, 917, 917, 918, 918, 919, 919, 920, 921, 921, 922, 922, 923, 923, 924, 924, 925, 925, 926, 926, 927, 927, 928, 928, 929, 929, 930, 930, 931, 931, 932, 932, 933, 933, 934, 934, 935, 935, 936, 936, 937, 937, 938, 938, 939, 939, 940, 940, 941, 941, 942, 942, 943, 943, 944, 944, 945, 945, 946, 946, 947, 947, 948, 948, 949, 949, 950, 950, 951, 951, 952, 952, 953, 953, 954, 954, 955, 955, 956, 956, 957, 957, 958, 958, 959, 959, 960, 960, 961, 961, 962, 962, 963, 963, 964, 964, 965, 965, 966, 966, 967, 967, 968, 968, 969, 969, 970, 970, 970, 971, 971, 972, 972, 973, 973, 974, 974, 975, 975, 976, 976, 977, 977, 978, 978, 979, 979, 980, 980, 981, 981, 982, 982, 982, 983, 983, 984, 984, 985, 985, 986, 986, 987, 987, 988, 988, 989, 989, 990, 990, 991, 991, 992, 992, 992, 993, 993, 994, 994, 995, 995, 996, 996, 997, 997, 998, 998, 999, 999, 999, 1000, 1000, 1001, 1001, 1002, 1002, 1003, 1003, 1004, 1004, 1005, 1005, 1006, 1006, 1006, 1007, 1007, 1008, 1008, 1009, 1009, 1010, 1010, 1011, 1011, 1012, 1012, 1012, 1013, 1013, 1014, 1014, 1015, 1015, 1016, 1016, 1017, 1017, 1018, 1018, 1018, 1019, 1019, 1020, 1020, 1021, 1021, 1022, 1022, 1023, 1023, };
        return lut[y];
    };
    int decode(int y) {
        static const int lut[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 41, 41, 41, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 46, 46, 46, 47, 47, 48, 48, 49, 49, 49, 50, 50, 51, 51, 52, 52, 52, 53, 53, 54, 54, 55, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 61, 62, 62, 63, 63, 64, 64, 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 75, 75, 76, 76, 77, 77, 78, 78, 79, 79, 80, 80, 81, 82, 82, 83, 83, 84, 84, 85, 85, 86, 87, 87, 88, 88, 89, 89, 90, 91, 91, 92, 92, 93, 94, 94, 95, 95, 96, 97, 97, 98, 98, 99, 100, 100, 101, 102, 102, 103, 103, 104, 105, 105, 106, 107, 107, 108, 109, 109, 110, 110, 111, 112, 112, 113, 114, 114, 115, 116, 116, 117, 118, 118, 119, 120, 121, 121, 122, 123, 123, 124, 125, 125, 126, 127, 127, 128, 129, 130, 130, 131, 132, 132, 133, 134, 135, 135, 136, 137, 138, 138, 139, 140, 141, 141, 142, 143, 144, 144, 145, 146, 147, 147, 148, 149, 150, 150, 151, 152, 153, 154, 154, 155, 156, 157, 157, 158, 159, 160, 161, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 180, 181, 181, 182, 183, 184, 185, 186, 187, 187, 188, 189, 190, 191, 192, 193, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 294, 295, 296, 297, 298, 299, 300, 301, 303, 304, 305, 306, 307, 308, 309, 311, 312, 313, 314, 315, 316, 317, 319, 320, 321, 322, 323, 324, 326, 327, 328, 329, 330, 332, 333, 334, 335, 336, 338, 339, 340, 341, 342, 344, 345, 346, 347, 348, 350, 351, 352, 353, 355, 356, 357, 358, 360, 361, 362, 363, 365, 366, 367, 368, 370, 371, 372, 373, 375, 376, 377, 378, 380, 381, 382, 384, 385, 386, 387, 389, 390, 391, 393, 394, 395, 397, 398, 399, 401, 402, 403, 405, 406, 407, 409, 410, 411, 413, 414, 415, 417, 418, 419, 421, 422, 423, 425, 426, 427, 429, 430, 432, 433, 434, 436, 437, 438, 440, 441, 443, 444, 445, 447, 448, 450, 451, 452, 454, 455, 457, 458, 459, 461, 462, 464, 465, 467, 468, 469, 471, 472, 474, 475, 477, 478, 480, 481, 483, 484, 485, 487, 488, 490, 491, 493, 494, 496, 497, 499, 500, 502, 503, 505, 506, 508, 509, 511, 512, 514, 515, 517, 518, 520, 521, 523, 524, 526, 527, 529, 530, 532, 534, 535, 537, 538, 540, 541, 543, 544, 546, 548, 549, 551, 552, 554, 555, 557, 559, 560, 562, 563, 565, 567, 568, 570, 571, 573, 575, 576, 578, 579, 581, 583, 584, 586, 587, 589, 591, 592, 594, 596, 597, 599, 601, 602, 604, 605, 607, 609, 610, 612, 614, 615, 617, 619, 620, 622, 624, 625, 627, 629, 631, 632, 634, 636, 637, 639, 641, 642, 644, 646, 648, 649, 651, 653, 654, 656, 658, 660, 661, 663, 665, 667, 668, 670, 672, 674, 675, 677, 679, 681, 682, 684, 686, 688, 689, 691, 693, 695, 697, 698, 700, 702, 704, 705, 707, 709, 711, 713, 714, 716, 718, 720, 722, 724, 725, 727, 729, 731, 733, 735, 736, 738, 740, 742, 744, 746, 747, 749, 751, 753, 755, 757, 759, 760, 762, 764, 766, 768, 770, 772, 774, 776, 777, 779, 781, 783, 785, 787, 789, 791, 793, 795, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 829, 831, 833, 835, 837, 839, 841, 843, 845, 847, 849, 851, 853, 855, 857, 859, 861, 863, 865, 867, 869, 871, 873, 875, 877, 879, 881, 883, 885, 887, 889, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 925, 927, 929, 931, 933, 935, 937, 939, 941, 943, 945, 948, 950, 952, 954, 956, 958, 960, 962, 965, 967, 969, 971, 973, 975, 977, 980, 982, 984, 986, 988, 990, 992, 995, 997, 999, 1001, 1003, 1005, 1008, 1010, 1012, 1014, 1016, 1019, 1021, 1023, };
        return lut[y];
    };
    
[/code]

ということではないでしょうか？

なお、質問文の数式では値が元に戻らないため、数式を調べ直すことをお勧めします。私のコードが正しいとも限りません。

* * *

> どのようにべき乗計算をするか

についてですが、`x^y =
2^(y*log2(x))`の変換ができ、またCPUは２進数で処理しているため`2^x`や`log2(x)`には強いため高速化をもくろむことはできますが、結局は実数部が残り`<math.h>`を用いるかマクローリン展開などになります。誤差の問題もありますし、最初から`pow`を使用した方が高速なのではと思います。

なお、[x87プロセッサを使用した場合、`pow`はおおよそ次のように計算](https://sayurin.blogspot.jp/2008/12/pow-
x-y.html)されます。

[code]

    __declspec(noinline) double pow( double x, double y ){
      __asm{
        fld y
        fld x
        fyl2x
        fst ST(1)
        frndint
        fxch ST(1)
        fsub ST(0), ST(1)
        f2xm1
        fld1
        faddp ST(1), ST(0)
        fscale
      }
    }
    
[/code]




> 速度をなるべく早くするということでMath.hを禁止され、どのようにべき乗計算をするか分からない

質問の意図（というよりも質問者さんが受けた指示内容）がようやくわかりました。  
「`<math.h>`の関数を使わずLookup tableを構築する」ではなくて「Lookup
tableを使用することで`<math.h>`の関数を使わず済む」ではないでしょうか。そして予めLUT; Lookup
tableを作ってソースコードに埋め込むのではないでしょうか。

[code]

    #include <math.h>
    #include <stdio.h>
    
    const int ymax = 1023;
    const double gamma = 2.2;
    int encode(int y) {
        return (int)round(ymax * pow((double)y / ymax, 1 / gamma));
    
    }
    int decode(int y) {
        return (int)round(ymax * pow((double)y / ymax, gamma));
    }
    
    #define GENERATE(FUNC)  do {                    \
        printf("int " #FUNC "(int y) {\n");         \
        printf("    static const int lut[] = { ");  \
        for (int y = 0; y <= ymax; y++)             \
        printf("%d, ", FUNC(y));                    \
        printf("};\n");                             \
        printf("    return lut[y];\n");             \
        printf("};\n");                             \
        } while(0)
    
    int main(){
        GENERATE(encode);
        GENERATE(decode);
        return 0;
    }
    
[/code]

を実行して得られる

[code]

    int encode(int y) {
        static const int lut[] = { 0, 44, 60, 72, 82, 91, 99, 106, 113, 119, 125, 130, 136, 141, 145, 150, 155, 159, 163, 167, 171, 175, 179, 182, 186, 189, 193, 196, 199, 203, 206, 209, 212, 215, 218, 221, 223, 226, 229, 232, 234, 237, 240, 242, 245, 247, 250, 252, 255, 257, 259, 262, 264, 266, 269, 271, 273, 275, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 319, 321, 323, 325, 327, 328, 330, 332, 334, 335, 337, 339, 341, 342, 344, 346, 347, 349, 351, 352, 354, 356, 357, 359, 360, 362, 363, 365, 367, 368, 370, 371, 373, 374, 376, 377, 379, 380, 382, 383, 385, 386, 388, 389, 391, 392, 393, 395, 396, 398, 399, 401, 402, 403, 405, 406, 407, 409, 410, 412, 413, 414, 416, 417, 418, 420, 421, 422, 424, 425, 426, 427, 429, 430, 431, 433, 434, 435, 436, 438, 439, 440, 441, 443, 444, 445, 446, 448, 449, 450, 451, 452, 454, 455, 456, 457, 458, 460, 461, 462, 463, 464, 466, 467, 468, 469, 470, 471, 473, 474, 475, 476, 477, 478, 479, 480, 482, 483, 484, 485, 486, 487, 488, 489, 490, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 580, 581, 582, 583, 584, 585, 586, 587, 588, 588, 589, 590, 591, 592, 593, 594, 595, 595, 596, 597, 598, 599, 600, 601, 601, 602, 603, 604, 605, 606, 607, 607, 608, 609, 610, 611, 612, 613, 613, 614, 615, 616, 617, 618, 618, 619, 620, 621, 622, 623, 623, 624, 625, 626, 627, 627, 628, 629, 630, 631, 632, 632, 633, 634, 635, 636, 636, 637, 638, 639, 640, 640, 641, 642, 643, 644, 644, 645, 646, 647, 647, 648, 649, 650, 651, 651, 652, 653, 654, 655, 655, 656, 657, 658, 658, 659, 660, 661, 661, 662, 663, 664, 665, 665, 666, 667, 668, 668, 669, 670, 671, 671, 672, 673, 674, 674, 675, 676, 677, 677, 678, 679, 680, 680, 681, 682, 683, 683, 684, 685, 686, 686, 687, 688, 688, 689, 690, 691, 691, 692, 693, 694, 694, 695, 696, 696, 697, 698, 699, 699, 700, 701, 701, 702, 703, 704, 704, 705, 706, 706, 707, 708, 709, 709, 710, 711, 711, 712, 713, 713, 714, 715, 716, 716, 717, 718, 718, 719, 720, 720, 721, 722, 723, 723, 724, 725, 725, 726, 727, 727, 728, 729, 729, 730, 731, 731, 732, 733, 733, 734, 735, 735, 736, 737, 738, 738, 739, 740, 740, 741, 742, 742, 743, 744, 744, 745, 746, 746, 747, 748, 748, 749, 750, 750, 751, 751, 752, 753, 753, 754, 755, 755, 756, 757, 757, 758, 759, 759, 760, 761, 761, 762, 763, 763, 764, 765, 765, 766, 766, 767, 768, 768, 769, 770, 770, 771, 772, 772, 773, 773, 774, 775, 775, 776, 777, 777, 778, 779, 779, 780, 780, 781, 782, 782, 783, 784, 784, 785, 785, 786, 787, 787, 788, 789, 789, 790, 790, 791, 792, 792, 793, 794, 794, 795, 795, 796, 797, 797, 798, 798, 799, 800, 800, 801, 801, 802, 803, 803, 804, 805, 805, 806, 806, 807, 808, 808, 809, 809, 810, 811, 811, 812, 812, 813, 814, 814, 815, 815, 816, 817, 817, 818, 818, 819, 820, 820, 821, 821, 822, 822, 823, 824, 824, 825, 825, 826, 827, 827, 828, 828, 829, 830, 830, 831, 831, 832, 832, 833, 834, 834, 835, 835, 836, 836, 837, 838, 838, 839, 839, 840, 841, 841, 842, 842, 843, 843, 844, 845, 845, 846, 846, 847, 847, 848, 849, 849, 850, 850, 851, 851, 852, 853, 853, 854, 854, 855, 855, 856, 856, 857, 858, 858, 859, 859, 860, 860, 861, 862, 862, 863, 863, 864, 864, 865, 865, 866, 867, 867, 868, 868, 869, 869, 870, 870, 871, 871, 872, 873, 873, 874, 874, 875, 875, 876, 876, 877, 878, 878, 879, 879, 880, 880, 881, 881, 882, 882, 883, 884, 884, 885, 885, 886, 886, 887, 887, 888, 888, 889, 889, 890, 891, 891, 892, 892, 893, 893, 894, 894, 895, 895, 896, 896, 897, 897, 898, 899, 899, 900, 900, 901, 901, 902, 902, 903, 903, 904, 904, 905, 905, 906, 906, 907, 908, 908, 909, 909, 910, 910, 911, 911, 912, 912, 913, 913, 914, 914, 915, 915, 916, 916, 917, 917, 918, 918, 919, 919, 920, 921, 921, 922, 922, 923, 923, 924, 924, 925, 925, 926, 926, 927, 927, 928, 928, 929, 929, 930, 930, 931, 931, 932, 932, 933, 933, 934, 934, 935, 935, 936, 936, 937, 937, 938, 938, 939, 939, 940, 940, 941, 941, 942, 942, 943, 943, 944, 944, 945, 945, 946, 946, 947, 947, 948, 948, 949, 949, 950, 950, 951, 951, 952, 952, 953, 953, 954, 954, 955, 955, 956, 956, 957, 957, 958, 958, 959, 959, 960, 960, 961, 961, 962, 962, 963, 963, 964, 964, 965, 965, 966, 966, 967, 967, 968, 968, 969, 969, 970, 970, 970, 971, 971, 972, 972, 973, 973, 974, 974, 975, 975, 976, 976, 977, 977, 978, 978, 979, 979, 980, 980, 981, 981, 982, 982, 982, 983, 983, 984, 984, 985, 985, 986, 986, 987, 987, 988, 988, 989, 989, 990, 990, 991, 991, 992, 992, 992, 993, 993, 994, 994, 995, 995, 996, 996, 997, 997, 998, 998, 999, 999, 999, 1000, 1000, 1001, 1001, 1002, 1002, 1003, 1003, 1004, 1004, 1005, 1005, 1006, 1006, 1006, 1007, 1007, 1008, 1008, 1009, 1009, 1010, 1010, 1011, 1011, 1012, 1012, 1012, 1013, 1013, 1014, 1014, 1015, 1015, 1016, 1016, 1017, 1017, 1018, 1018, 1018, 1019, 1019, 1020, 1020, 1021, 1021, 1022, 1022, 1023, 1023, };
        return lut[y];
    };
    int decode(int y) {
        static const int lut[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 41, 41, 41, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 46, 46, 46, 47, 47, 48, 48, 49, 49, 49, 50, 50, 51, 51, 52, 52, 52, 53, 53, 54, 54, 55, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 61, 62, 62, 63, 63, 64, 64, 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 75, 75, 76, 76, 77, 77, 78, 78, 79, 79, 80, 80, 81, 82, 82, 83, 83, 84, 84, 85, 85, 86, 87, 87, 88, 88, 89, 89, 90, 91, 91, 92, 92, 93, 94, 94, 95, 95, 96, 97, 97, 98, 98, 99, 100, 100, 101, 102, 102, 103, 103, 104, 105, 105, 106, 107, 107, 108, 109, 109, 110, 110, 111, 112, 112, 113, 114, 114, 115, 116, 116, 117, 118, 118, 119, 120, 121, 121, 122, 123, 123, 124, 125, 125, 126, 127, 127, 128, 129, 130, 130, 131, 132, 132, 133, 134, 135, 135, 136, 137, 138, 138, 139, 140, 141, 141, 142, 143, 144, 144, 145, 146, 147, 147, 148, 149, 150, 150, 151, 152, 153, 154, 154, 155, 156, 157, 157, 158, 159, 160, 161, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 180, 181, 181, 182, 183, 184, 185, 186, 187, 187, 188, 189, 190, 191, 192, 193, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 294, 295, 296, 297, 298, 299, 300, 301, 303, 304, 305, 306, 307, 308, 309, 311, 312, 313, 314, 315, 316, 317, 319, 320, 321, 322, 323, 324, 326, 327, 328, 329, 330, 332, 333, 334, 335, 336, 338, 339, 340, 341, 342, 344, 345, 346, 347, 348, 350, 351, 352, 353, 355, 356, 357, 358, 360, 361, 362, 363, 365, 366, 367, 368, 370, 371, 372, 373, 375, 376, 377, 378, 380, 381, 382, 384, 385, 386, 387, 389, 390, 391, 393, 394, 395, 397, 398, 399, 401, 402, 403, 405, 406, 407, 409, 410, 411, 413, 414, 415, 417, 418, 419, 421, 422, 423, 425, 426, 427, 429, 430, 432, 433, 434, 436, 437, 438, 440, 441, 443, 444, 445, 447, 448, 450, 451, 452, 454, 455, 457, 458, 459, 461, 462, 464, 465, 467, 468, 469, 471, 472, 474, 475, 477, 478, 480, 481, 483, 484, 485, 487, 488, 490, 491, 493, 494, 496, 497, 499, 500, 502, 503, 505, 506, 508, 509, 511, 512, 514, 515, 517, 518, 520, 521, 523, 524, 526, 527, 529, 530, 532, 534, 535, 537, 538, 540, 541, 543, 544, 546, 548, 549, 551, 552, 554, 555, 557, 559, 560, 562, 563, 565, 567, 568, 570, 571, 573, 575, 576, 578, 579, 581, 583, 584, 586, 587, 589, 591, 592, 594, 596, 597, 599, 601, 602, 604, 605, 607, 609, 610, 612, 614, 615, 617, 619, 620, 622, 624, 625, 627, 629, 631, 632, 634, 636, 637, 639, 641, 642, 644, 646, 648, 649, 651, 653, 654, 656, 658, 660, 661, 663, 665, 667, 668, 670, 672, 674, 675, 677, 679, 681, 682, 684, 686, 688, 689, 691, 693, 695, 697, 698, 700, 702, 704, 705, 707, 709, 711, 713, 714, 716, 718, 720, 722, 724, 725, 727, 729, 731, 733, 735, 736, 738, 740, 742, 744, 746, 747, 749, 751, 753, 755, 757, 759, 760, 762, 764, 766, 768, 770, 772, 774, 776, 777, 779, 781, 783, 785, 787, 789, 791, 793, 795, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 829, 831, 833, 835, 837, 839, 841, 843, 845, 847, 849, 851, 853, 855, 857, 859, 861, 863, 865, 867, 869, 871, 873, 875, 877, 879, 881, 883, 885, 887, 889, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 925, 927, 929, 931, 933, 935, 937, 939, 941, 943, 945, 948, 950, 952, 954, 956, 958, 960, 962, 965, 967, 969, 971, 973, 975, 977, 980, 982, 984, 986, 988, 990, 992, 995, 997, 999, 1001, 1003, 1005, 1008, 1010, 1012, 1014, 1016, 1019, 1021, 1023, };
        return lut[y];
    };
    
[/code]

ということではないでしょうか？

なお、質問文の数式では値が元に戻らないため、数式を調べ直すことをお勧めします。私のコードが正しいとも限りません。

* * *

> どのようにべき乗計算をするか

についてですが、`x^y =
2^(y*log2(x))`の変換ができ、またCPUは２進数で処理しているため`2^x`や`log2(x)`には強いため高速化をもくろむことはできますが、結局は実数部が残り`<math.h>`を用いるかマクローリン展開などになります。誤差の問題もありますし、最初から`pow`を使用した方が高速なのではと思います。

なお、[x87プロセッサを使用した場合、`pow`はおおよそ次のように計算](https://sayurin.blogspot.jp/2008/12/pow-
x-y.html)されます。

[code]

    __declspec(noinline) double pow( double x, double y ){
      __asm{
        fld y
        fld x
        fyl2x
        fst ST(1)
        frndint
        fxch ST(1)
        fsub ST(0), ST(1)
        f2xm1
        fld1
        faddp ST(1), ST(0)
        fscale
      }
    }
    
[/code]

