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

Commit a01049d

Browse files
committed
wip, f16 not working
1 parent 1fce1e4 commit a01049d

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/math/generic/scalbn.rs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ where
5454
// 2 ^ sig_total_bits, representation of what can be accounted for with subnormals
5555
let f_exp_subnorm = F::from_parts(false, sig_total_bits + F::EXP_BIAS, zero);
5656

57-
dbg!((Hexf(f_exp_max), Hexf(f_exp_min), Hexf(f_exp_subnorm)));
58-
57+
dbg!(exp_max, exp_min, sig_total_bits, sig_total_bits + F::EXP_BIAS);
58+
dbg!(Hexf(f_exp_max), Hexf(f_exp_min), Hexf(f_exp_subnorm));
5959
dbg!(Hexf(x), n);
6060

6161
// The goal is to multiply `x` by a scale factor that applies `n`. However, there are cases
@@ -86,13 +86,16 @@ where
8686
let add = -exp_min - sig_total_bits as i32;
8787
dbg!(Hexf(mul), add);
8888

89-
if n < exp_min + sig_total_bits as i32 {
89+
if n < exp_min - sig_total_bits as i32 {
90+
dbg!("block 1");
9091
x *= f_exp_min;
9192
n += -exp_min;
93+
dbg!(Hexf(x), n);
9294

93-
if n < exp_min + sig_total_bits as i32 {
95+
if n < exp_min - sig_total_bits as i32 {
9496
x *= f_exp_min;
9597
n += -exp_min;
98+
dbg!(Hexf(x), n);
9699

97100
// if n < exp_min + sig_total_bits as i32 {
98101
// x *= f_exp_min;
@@ -105,9 +108,33 @@ where
105108

106109
if n < exp_min {
107110
n = exp_min;
111+
dbg!(Hexf(x), n);
108112
}
109113
// }
114+
} else if n < exp_min {
115+
// only for f16
116+
117+
x *= mul;
118+
n += add;
119+
120+
dbg!(Hexf(x), n);
121+
if n < exp_min {
122+
n = exp_min;
123+
dbg!(Hexf(x), n);
124+
}
110125
}
126+
} else if n < exp_min {
127+
// dbg!("block 2");
128+
// // only for f16
129+
130+
// x *= mul;
131+
// n += add;
132+
133+
// dbg!(Hexf(x), n);
134+
// if n < exp_min {
135+
// n = exp_min;
136+
// dbg!(Hexf(x), n);
137+
// }
111138
}
112139

113140
// if n < exp_min {
@@ -262,28 +289,4 @@ mod tests {
262289
fn spec_test_f128() {
263290
spec_test::<f128>();
264291
}
265-
266-
// #[test]
267-
// fn foobar32() {
268-
// let x = hf32!("0x1.fffffep+127");
269-
// let n = -2147483639;
270-
// scalbn(x, n);
271-
// std::eprintln!();
272-
// let x = hf32!("0x1.fffffep-126");
273-
// let n = 2147483639;
274-
// scalbn(x, n);
275-
// panic!();
276-
// }
277-
278-
// #[test]
279-
// fn foobar16() {
280-
// let x = hf16!("0x1.ffp+15");
281-
// let n = -2147483639;
282-
// scalbn(x, n);
283-
// std::eprintln!();
284-
// let x = hf16!("0x1.ffp-15");
285-
// let n = 2147483639;
286-
// scalbn(x, n);
287-
// panic!();
288-
// }
289292
}

0 commit comments

Comments
 (0)