-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_types.py
More file actions
23 lines (19 loc) · 872 Bytes
/
generate_types.py
File metadata and controls
23 lines (19 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def generate_fixed_type_aliases():
"""Generate Rust type aliases for fixed-point numbers."""
types = [(sign, bits) for sign in ["I", "U"] for bits in [8, 16, 32, 64, 128]]
output = []
for sign, bits in types:
# Generate all possible fractional bit combinations
type_name = f"FheFixed{sign}{bits}"
for frac_bits in range(bits+1):
int_bits = bits - frac_bits
output.append(
f"pub type {sign}{int_bits}F{frac_bits} = {type_name}<extra::U{frac_bits}>;"
)
return "\n".join(output)
print("// Generated by generate_types.py")
print("use crate::{FheFixedI128, FheFixedI16, FheFixedI32, FheFixedI64, FheFixedI8};")
print("use crate::{FheFixedU128, FheFixedU16, FheFixedU32, FheFixedU64, FheFixedU8};")
print("use fixed::types::extra;")
print()
print(generate_fixed_type_aliases())