aboutsummaryrefslogtreecommitdiff
path: root/std/math/tanh.zig
diff options
context:
space:
mode:
authorMarc Tiehuis <marctiehuis@gmail.com>2017-06-21 18:21:11 +1200
committerMarc Tiehuis <marctiehuis@gmail.com>2017-06-21 18:21:11 +1200
commit14a324a0fa8d60dbf7d6948a992a09d8a65cbdc4 (patch)
tree2ddb5dd971975ed0726e7946f92426f6d5d7b171 /std/math/tanh.zig
parentdfa2d11167db31e3b490c7d37633871fef4f2d52 (diff)
downloadzig-14a324a0fa8d60dbf7d6948a992a09d8a65cbdc4.tar.gz
zig-14a324a0fa8d60dbf7d6948a992a09d8a65cbdc4.zip
Fixes for release mode tests
Diffstat (limited to 'std/math/tanh.zig')
-rw-r--r--std/math/tanh.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/std/math/tanh.zig b/std/math/tanh.zig
index a76de9ce22..c88dc08156 100644
--- a/std/math/tanh.zig
+++ b/std/math/tanh.zig
@@ -30,11 +30,15 @@ fn tanh32(x: f32) -> f32 {
var t: f32 = undefined;
+ if (x == 0.0 or math.isNan(x)) {
+ return x;
+ }
+
// |x| < log(3) / 2 ~= 0.5493 or nan
if (ux > 0x3F0C9F54) {
// |x| > 10
if (ux > 0x41200000) {
- t = 1.0 + 0 / x;
+ t = 1.0;
} else {
t = math.expm1(2 * x);
t = 1 - 2 / (t + 2);
@@ -71,10 +75,7 @@ fn tanh64(x: f64) -> f64 {
var t: f64 = undefined;
// TODO: Shouldn't need these checks.
- if (x == 0.0) {
- return x;
- }
- if (math.isNan(x)) {
+ if (x == 0.0 or math.isNan(x)) {
return x;
}
@@ -82,7 +83,7 @@ fn tanh64(x: f64) -> f64 {
if (w > 0x3FE193EA) {
// |x| > 20 or nan
if (w > 0x40340000) {
- t = 1.0; // TODO + 0 / x;
+ t = 1.0;
} else {
t = math.expm1(2 * x);
t = 1 - 2 / (t + 2);
@@ -137,7 +138,6 @@ test "math.tanh64" {
}
test "math.tanh32.special" {
- // TODO: Error on release (like pow)
assert(tanh32(0.0) == 0.0);
assert(tanh32(-0.0) == -0.0);
assert(tanh32(math.inf(f32)) == 1.0);