use std::fmt::Write;
const COMMENT_WIDTH: usize = 80;
pub(crate) fn comment(out: &mut String, marker: &str, indent: usize, text: &str) {
let room = COMMENT_WIDTH.saturating_sub(indent + marker.len() + 1);
for (i, paragraph) in text.split("\n\n").enumerate() {
if i > 0 {
writeln!(out, "{marker}").unwrap();
}
let mut line = String::new();
for word in paragraph.split_whitespace() {
if !line.is_empty() && line.len() + 1 + word.len() > room {
writeln!(out, "{marker} {line}").unwrap();
line.clear();
}
if !line.is_empty() {
line.push(' ');
}
line.push_str(word);
}
writeln!(out, "{marker} {line}").unwrap();
}
}
pub(crate) fn power_of_two(x: f64) -> i64 {
debug_assert!(x.is_normal() && x.to_bits() & ((1 << 52) - 1) == 0);
i64::try_from(x.to_bits() >> 52).expect("11 bits") - 1023
}
pub(crate) fn literal(x: f64) -> String {
debug_assert!(x.is_finite());
format!("{x:?}")
}