]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LiveCD/VTOY/ventoy/disksize.c
update languages.ini (#829 #834)
[Ventoy.git] / LiveCD / VTOY / ventoy / disksize.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 typedef unsigned long long UINT64;
6
7 int GetHumanReadableGBSize(UINT64 SizeBytes)
8 {
9 int i;
10 int Pow2 = 1;
11 double Delta;
12 double GB = SizeBytes * 1.0 / 1000 / 1000 / 1000;
13
14 for (i = 0; i < 12; i++)
15 {
16 if (Pow2 > GB)
17 {
18 Delta = (Pow2 - GB) / Pow2;
19 }
20 else
21 {
22 Delta = (GB - Pow2) / Pow2;
23 }
24
25 if (Delta < 0.05)
26 {
27 return Pow2;
28 }
29
30 Pow2 <<= 1;
31 }
32
33 return (int)GB;
34 }
35
36 int main(int argc, char **argv)
37 {
38 UINT64 value = strtoul(argv[1], NULL, 10);
39
40 printf("%d", GetHumanReadableGBSize(value * 512));
41
42 return 0;
43 }