Update cetz & ci

This commit is contained in:
2025-09-23 23:29:06 -07:00
parent 121780df6c
commit e5b0053465
17 changed files with 393 additions and 483 deletions

View File

@ -1,5 +1,5 @@
#import "@local/handout:0.1.0": *
#import "@preview/cetz:0.3.1"
#import "@preview/cetz:0.4.2"
= Floats
#definition()
@ -33,72 +33,66 @@ Another way we can interpret a bit string is as a _signed floating-point decimal
Floats represent a subset of the real numbers, and are interpreted as follows: \
#note([The following only applies to floats that consist of 32 bits. We won't encounter any others today.])
#align(
center,
box(
inset: 2mm,
cetz.canvas({
import cetz.draw: *
#align(center, box(inset: 2mm, cetz.canvas({
import cetz.draw: *
let chars = (
`0`,
`b`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
)
let chars = (
`0`,
`b`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`_`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
`0`,
)
let x = 0
for c in chars {
content((x, 0), c)
x += 0.25
}
let x = 0
for c in chars {
content((x, 0), c)
x += 0.25
}
let y = -0.4
line((0.3, y), (0.65, y))
content((0.45, y - 0.2), [s])
let y = -0.4
line((0.3, y), (0.65, y))
content((0.45, y - 0.2), [s])
line((0.85, y), (2.9, y))
content((1.9, y - 0.2), [exponent])
line((0.85, y), (2.9, y))
content((1.9, y - 0.2), [exponent])
line((3.10, y), (9.4, y))
content((6.3, y - 0.2), [fraction])
}),
),
)
line((3.10, y), (9.4, y))
content((6.3, y - 0.2), [fraction])
})))
- The first bit denotes the sign of the float's value
We'll label it $s$. \

View File

@ -1,6 +1,6 @@
#import "@local/handout:0.1.0": *
#import "@preview/cetz:0.3.1"
#import "@preview/cetz-plot:0.1.0": plot, chart
#import "@preview/cetz:0.4.2"
#import "@preview/cetz-plot:0.1.2": chart, plot
= Integers and Floats
@ -44,19 +44,11 @@ This allows us to improve the average error of our linear approximation:
{
let domain = (0, 1)
plot.add(
f1,
domain: domain,
label: $log(1+x)$,
style: (stroke: ogrape),
)
plot.add(f1, domain: domain, label: $log(1+x)$, style: (
stroke: ogrape,
))
plot.add(
f2,
domain: domain,
label: $x$,
style: (stroke: oblue),
)
plot.add(f2, domain: domain, label: $x$, style: (stroke: oblue))
},
)
})
@ -90,19 +82,11 @@ This allows us to improve the average error of our linear approximation:
{
let domain = (0, 1)
plot.add(
f1,
domain: domain,
label: $log(1+x)$,
style: (stroke: ogrape),
)
plot.add(f1, domain: domain, label: $log(1+x)$, style: (
stroke: ogrape,
))
plot.add(
f2,
domain: domain,
label: $x$,
style: (stroke: oblue),
)
plot.add(f2, domain: domain, label: $x$, style: (stroke: oblue))
},
)
})
@ -120,16 +104,13 @@ We won't bother with this---we'll simply leave the correction term as an opaque
#v(1fr)
#note(
type: "Note",
[
"Average error" above is simply the area of the region between the two graphs:
$
integral_0^1 abs( #v(1mm) log(1+x)_2 - (x+epsilon) #v(1mm))
$
Feel free to ignore this note, it isn't a critical part of this handout.
],
)
#note(type: "Note", [
"Average error" above is simply the area of the region between the two graphs:
$
integral_0^1 abs(#v(1mm) log(1+x)_2 - (x+epsilon) #v(1mm))
$
Feel free to ignore this note, it isn't a critical part of this handout.
])
#pagebreak()
@ -149,12 +130,11 @@ $
Let $E$ and $F$ be the exponent and float bits of $x_f$. \
We then have:
$
log_2(x_f)
&= log_2 ( 2^(E-127) times (1 + (F) / (2^23)) ) \
&= E - 127 + log_2(1 + F / (2^23)) \
& approx E-127 + F / (2^23) + epsilon \
&= 1 / (2^23)(2^23 E + F) - 127 + epsilon \
&= 1 / (2^23)(x_i) - 127 + epsilon
log_2(x_f) & = log_2 ( 2^(E-127) times (1 + (F) / (2^23)) ) \
& = E - 127 + log_2(1 + F / (2^23)) \
& approx E-127 + F / (2^23) + epsilon \
& = 1 / (2^23)(2^23 E + F) - 127 + epsilon \
& = 1 / (2^23)(x_i) - 127 + epsilon
$
])