Skip to content

Commit 34680d1

Browse files
committed
Optimize hyperreal scientific fast paths
1 parent dc6e098 commit 34680d1

8 files changed

Lines changed: 1450 additions & 1168 deletions

File tree

benchmarks.md

Lines changed: 101 additions & 100 deletions
Large diffs are not rendered by default.

dispatch_trace.md

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.

promoted_slow_offenders.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ generated_tan_p96 generated[9396] -4 128/155 18279 tan_generated_9396_neg_4_128_
101101
generated_sin_p96 generated[11884] 4 14/31 18269 sin_generated_11884_4_14_31_p96
102102
generated_tan_p96 generated[14421] 5 25/47 18209 tan_generated_14421_5_25_47_p96
103103
generated_sin_p96 generated[13219] 4 31/51 18188 sin_generated_13219_4_31_51_p96
104-
generated_atan_p96 generated[2739] -1 235/241 18159 atan_generated_2739_neg_1_235_241_p96
104+
generated_cos_p96 generated[9950] -5 1/5 18169 cos_generated_9950_neg_5_1_5_p96

slow_performers.txt

Lines changed: 885 additions & 884 deletions
Large diffs are not rendered by default.

src/real/arithmetic/add_sub.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,6 @@ impl<T: AsRef<Real>> Sub<T> for &Real {
207207

208208
fn sub(self, other: T) -> Self::Output {
209209
let other = other.as_ref();
210-
if self.class == Pi
211-
&& self.rational.is_one()
212-
&& other.class == One
213-
&& other.rational == *rationals::THREE
214-
{
215-
crate::trace_dispatch!("real", "sub", "cached-pi-minus-three");
216-
return constants::pi_minus_three();
217-
}
218-
if self.class == One
219-
&& self.rational == *rationals::THREE
220-
&& other.class == Pi
221-
&& other.rational.is_one()
222-
{
223-
crate::trace_dispatch!("real", "sub", "cached-three-minus-pi");
224-
return -constants::pi_minus_three();
225-
}
226210
if self.class == other.class {
227211
// Same symbolic basis subtraction mirrors addition: update the scale only.
228212
let rational = &self.rational - &other.rational;
@@ -240,6 +224,22 @@ impl<T: AsRef<Real>> Sub<T> for &Real {
240224
primitive_approx_cache: Cell::new(PrimitiveApproxCache::Empty),
241225
};
242226
}
227+
if self.class == Pi
228+
&& self.rational.is_one()
229+
&& other.class == One
230+
&& other.rational == *rationals::THREE
231+
{
232+
crate::trace_dispatch!("real", "sub", "cached-pi-minus-three");
233+
return constants::pi_minus_three();
234+
}
235+
if self.class == One
236+
&& self.rational == *rationals::THREE
237+
&& other.class == Pi
238+
&& other.rational.is_one()
239+
{
240+
crate::trace_dispatch!("real", "sub", "cached-three-minus-pi");
241+
return -constants::pi_minus_three();
242+
}
243243
if other.has_zero_scale() {
244244
return self.clone();
245245
}
@@ -396,4 +396,3 @@ impl Real {
396396
}
397397
}
398398
}
399-

0 commit comments

Comments
 (0)