Skip to content

Commit 31d2b18

Browse files
committed
fix up up up
1 parent b04b070 commit 31d2b18

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

npsr/precise.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,38 @@ struct Subnormal {
4646
class FPExceptions {
4747
public:
4848
static constexpr auto kNone = 0;
49+
// guard against missing macros on some platforms
50+
// (e.g. Emscripten)
51+
#ifdef FE_INVALID
4952
static constexpr auto kInvalid = FE_INVALID;
53+
#else
54+
static constexpr auto kInvalid = 0;
55+
#endif
56+
#ifdef FE_DIVBYZERO
5057
static constexpr auto kDivByZero = FE_DIVBYZERO;
58+
#else
59+
static constexpr auto kDivByZero = 0;
60+
#endif
61+
#ifdef FE_OVERFLOW
5162
static constexpr auto kOverflow = FE_OVERFLOW;
63+
#else
64+
static constexpr auto kOverflow = 0;
65+
#endif
66+
#ifdef FE_UNDERFLOW
5267
static constexpr auto kUnderflow = FE_UNDERFLOW;
68+
#else
69+
static constexpr auto kUnderflow = 0;
70+
#endif
71+
static constexpr auto kAll = kInvalid | kDivByZero | kOverflow | kUnderflow;
5372

5473
void Raise(int errors) noexcept { mask_ |= errors; }
5574

5675
protected:
57-
void Load() noexcept {
58-
loaded_ = std::fegetexceptflag(&saved_, FE_ALL_EXCEPT) == 0;
59-
}
76+
void Load() noexcept { loaded_ = std::fegetexceptflag(&saved_, kAll) == 0; }
6077

6178
~FPExceptions() noexcept {
6279
if (loaded_) {
63-
std::fesetexceptflag(&saved_, FE_ALL_EXCEPT);
80+
std::fesetexceptflag(&saved_, kAll);
6481
}
6582
if (mask_ != kNone) {
6683
std::feraiseexcept(mask_);

npsr/trig/inl.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,26 @@ HWY_API V SinCos(Prec &prec, V x) {
5555
constexpr bool kIsSingle = std::is_same_v<TFromV<V>, float>;
5656
const DFromV<V> d;
5757
V ret;
58-
5958
// Step 1: Select base algorithm based on accuracy requirements
6059
if constexpr (Prec::kLowAccuracy) {
6160
// Low precision: Cody-Waite reduction with degree-9 polynomial
62-
// Error: ~1-2 ULP
61+
// Error: ~2 ULP and 3~ for non-fma
6362
ret = Low<IS_COS>(x);
6463
} else {
6564
// High precision: π/16 reduction with table lookup + polynomial
66-
// Error: ~0.5 ULP
65+
// Error: ~1 ULP
6766
ret = High<IS_COS>(x);
6867
}
69-
7068
// Step 2: Handle special cases (NaN, Inf) if enabled
7169
auto is_finite = IsFinite(x);
7270
if constexpr (Prec::kSpecialCases) {
7371
// IEEE 754 requires: sin(±∞) = NaN, cos(±∞) = NaN
7472
ret = IfThenElse(is_finite, ret, NaN(d));
73+
// -0.0 should return -0.0 for sine
74+
if constexpr (!IS_COS) {
75+
ret = IfThenElse(Eq(x, Set(d, 0.0)), x, ret);
76+
}
7577
}
76-
7778
// Step 3: Handle very large arguments if enabled
7879
// For |x| > threshold, standard algorithms lose precision due to
7980
// catastrophic cancellation in x - n*π reduction
@@ -91,12 +92,10 @@ HWY_API V SinCos(Prec &prec, V x) {
9192
ret = IfThenElse(has_large_arg, Extended<IS_COS>(x), ret);
9293
}
9394
}
94-
9595
// Step 4: Raise invalid operation exception for infinity inputs
9696
if constexpr (Prec::kExceptions) {
9797
prec.Raise(!AllFalse(d, IsInf(x)) ? FPExceptions::kInvalid : 0);
9898
}
99-
10099
return ret;
101100
}
102101

tools/sollya/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def format_duration(seconds: float) -> str:
6464
"""Format duration in human-readable format."""
6565
match seconds:
6666
case s if s < 1:
67-
return f"{s*1000:.0f}ms"
67+
return f"{s * 1000:.0f}ms"
6868
case s if s < 60:
6969
return f"{s:.1f}s"
7070
case s:
71-
return f"{int(s//60)}m {int(s%60)}s"
71+
return f"{int(s // 60)}m {int(s % 60)}s"
7272

7373

7474
def check_sollya_available() -> bool:

0 commit comments

Comments
 (0)