Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit abc9e6f

Browse files
committed
Docs update
1 parent d172001 commit abc9e6f

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

crates/libm-test/examples/plot_domains.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Program to write all inputs from a generator to a file, then invoke a Julia script
2+
//! to plot them. Requires Julia with the `CairoMakie` dependency.
3+
//!
4+
//! Note that running in release mode by default generates a _lot_ more datapoints, which
5+
//! causes plotting to be extremely slow (some simplification to done in the script).
6+
17
use std::io::{BufWriter, Write};
28
use std::path::Path;
39
use std::process::Command;
@@ -6,14 +12,15 @@ use std::{env, fs};
612
use libm_test::domain::{Domain, SqrtDomain, TrigDomain, Unbounded};
713
use libm_test::gen::domain;
814

15+
const JL_PLOT: &str = "examples/plot_file.jl";
16+
917
fn main() {
1018
let out_dir = Path::new("build");
1119
if !out_dir.exists() {
1220
fs::create_dir(out_dir).unwrap();
1321
}
1422

15-
let jl_script =
16-
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("examples/plot_file.jl");
23+
let jl_script = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join(JL_PLOT);
1724

1825
let mut j_args = Vec::new();
1926

@@ -30,10 +37,11 @@ fn main() {
3037
}
3138

3239
fn plot_one<D: Domain<f32>>(out_dir: &Path, name: &str, j_args: &mut Vec<String>) {
33-
let base_name = out_dir.join(format!("{name}-inputs"));
40+
let base_name = out_dir.join(format!("domain-inputs-{name}"));
3441
let text_file = base_name.with_extension("txt");
3542

3643
{
44+
// Scope for file and writer
3745
let f = fs::File::create(&text_file).unwrap();
3846
let mut w = BufWriter::new(f);
3947

crates/libm-test/examples/plot_file.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
# using Plots
1+
"A quick script to for plotting a list of floats.
2+
3+
Takes a list of floats and a real function, plots both on a graph in both
4+
linear and log scale. Requires [Makie] (specifically CairoMakie) for plotting.
5+
6+
[Makie]: https://docs.makie.org/stable/
7+
"
8+
29
using CairoMakie
310

411
CairoMakie.activate!(px_per_unit=10)
@@ -24,10 +31,11 @@ function plot_one(
2431
f::Function;
2532
xlims::Union{Tuple{Any,Any},Nothing},
2633
xlims_log::Union{Tuple{Any,Any},Nothing},
27-
)
34+
)::Nothing
2835
float_file = "$base_name.txt"
2936
lin_out_file = "$base_name.png"
3037
log_out_file = "$base_name-log.png"
38+
3139
if xlims === nothing
3240
xlims = (-6, 6)
3341
end
@@ -62,6 +70,7 @@ function plot_one(
6270
delete!(ax)
6371
end
6472

73+
# Args alternate `name1 path1 name2 path2`
6574
fn_names = ARGS[1:2:end]
6675
base_names = ARGS[2:2:end]
6776

@@ -100,8 +109,5 @@ for idx in eachindex(fn_names)
100109
)
101110
end
102111

103-
104112
base_name = ARGS[1]
105113
fn_name = ARGS[2]
106-
107-

crates/libm-test/src/f8_impl.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
//! A IEEE-compliant 8-bit float type for testing purposes.
2+
13
use std::cmp::{self, Ordering};
24
use std::{fmt, ops};
35

46
use crate::Float;
57

6-
/// Sometimes verifying float logic is easiest when all values can easily be checked exhaustively
8+
/// Sometimes verifying float logic is easiest when all values can quickly be checked exhaustively
79
/// or by hand.
810
///
911
/// IEEE-754 compliant type that includes a 1 bit sign, 4 bit exponent, and 3 bit significand.
1012
/// Bias is -7.
1113
///
1214
/// Based on <https://en.wikipedia.org/wiki/Minifloat#Example_8-bit_float_(1.4.3)>.
1315
#[derive(Clone, Copy)]
16+
#[repr(transparent)]
1417
#[allow(non_camel_case_types)]
1518
pub struct f8(u8);
1619

0 commit comments

Comments
 (0)