Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfind_limits.lua
More file actions
Latest commit
54 lines (51 loc) · 1.47 KB
/
Copy pathfind_limits.lua
File metadata and controls
54 lines (51 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- bitlib test suite
-- (c) Reuben Thomas 2007-2008
-- See README for license
-- Prepend a binary 1 to a hex constant
functionprepend_one (s)
ifs=="0" then
return"1"
elseifstring.sub (s, 1, 1) =="1" then
return"3" ..string.sub (s, 2)
elseifstring.sub (s, 1, 1) =="3" then
return"7" ..string.sub (s, 2)
elseifstring.sub (s, 1, 1) =="7" then
return"f" ..string.sub (s, 2)
else
return"1" ..s
end
end
-- Invert a hex constant
localinverted= {
["0"] ="f", ["1"] ="e", ["2"] ="d", ["3"] ="c",
["4"] ="b", ["5"] ="a", ["6"] ="9", ["7"] ="8",
["8"] ="7", ["9"] ="6", ["a"] ="5", ["b"] ="4",
["c"] ="3", ["d"] ="2", ["e"] ="1", ["f"] ="0",
}
functioninvert_hex (s)
fori=1, #sdo
s=string.sub (s, 1, i-1) ..inverted[string.sub (s, i, i)] ..string.sub (s, i+1)
end
ifstring.sub (s, 1, 1) =="0" then
s="1" ..s
end
returns
end
-- Calculate number of bits in a float mantissa
localfloat_bits=0
localfloat_max="0"
localfloat_umax="0"
localf=1
repeat
f=f*2
float_bits=float_bits+1
iff<f+1then
float_max=prepend_one (float_max)
end
float_umax=prepend_one (float_umax)
untilf>=f+1
localfloat_min=invert_hex (float_max)
print ("#define BITLIB_FLOAT_BITS " ..float_bits)
print ("#define BITLIB_FLOAT_MAX 0x" ..float_max.."L")
print ("#define BITLIB_FLOAT_MIN (-0x" ..float_min.."L)")
print ("#define BITLIB_FLOAT_UMAX 0x" ..float_umax.."UL")