Wandbox
SettingsLog
SettingsLog
Language
GitHubLogin
Ran/Viewed Log

Viewed less than a minute ago

cq3yYgkj3x3XhMfi

C gcc 13.2.0

Created at 4 minutes ago

Created by anonymous

Author

anonymous

4 minutes ago

Language

C

Compiler

gcc 13.2.0

Options
Warnings
Compiler Default
no pedantic
Raw compiler options
-lm

Author

anonymous

4 minutes ago

›
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <math.h>
#include <inttypes.h>

uint32_t calc(int num) {
union {
double d;
uint64_t u;
} value;
/* 3乗根を求める */
value.d = pow(num, 1.0 / 3.0);
/* 正規化を解除し、整数部分が本来の値になるようにシフトする */
for (int v = (int)value.d; v > 1; v >>= 1) value.u <<= 1;
/* 求めた値の下位52ビット (仮数部) のうち、上位32ビットを取り出す */
return value.u >> 20;
}

int main(void) {
printf("%08" PRIx32 "\n", calc(2));
printf("%08" PRIx32 "\n", calc(311));
return 0;
}

$ gcc prog.c -Wall -Wextra -lm
428a2f98
c67178f2
Exit Code:
0