| ... | ... | @@ -98,6 +98,15 @@ fn testSqrt() !void { |
| 98 | 98 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), 1.0488088481701516, epsilon)); |
| 99 | 99 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.0)), 1.4142135623730950, epsilon)); |
| 100 | 100 | |
| 101 | { |
| 102 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 103 | var result = @sqrt(v); |
| 104 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); |
| 105 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); |
| 106 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); |
| 107 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon)); |
| 108 | } |
| 109 | |
| 101 | 110 | if (builtin.zig_backend == .stage1) { |
| 102 | 111 | if (has_f80_rt) { |
| 103 | 112 | // TODO https://github.com/ziglang/zig/issues/10875 |
| ... | ... | @@ -116,16 +125,6 @@ fn testSqrt() !void { |
| 116 | 125 | // var a: f128 = 49; |
| 117 | 126 | //try expect(@sqrt(a) == 7); |
| 118 | 127 | //} |
| 119 | | |
| 120 | | // TODO Implement Vector support for stage2 |
| 121 | | { |
| 122 | | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 123 | | var result = @sqrt(v); |
| 124 | | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); |
| 125 | | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); |
| 126 | | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); |
| 127 | | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon)); |
| 128 | | } |
| 129 | 128 | } |
| 130 | 129 | } |
| 131 | 130 | |
| ... | ... | @@ -155,26 +154,25 @@ test "@sin" { |
| 155 | 154 | } |
| 156 | 155 | |
| 157 | 156 | fn testSin() !void { |
| 158 | | // TODO: Implement Vector support for other backends |
| 159 | | if (builtin.zig_backend == .stage1) { |
| 157 | // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)` |
| 158 | // so skip the rest of the tests. |
| 159 | if (builtin.zig_backend != .stage1) { |
| 160 | inline for ([_]type{ f16, f32, f64 }) |ty| { |
| 161 | const eps = epsForType(ty); |
| 162 | try expect(@sin(@as(ty, 0)) == 0); |
| 163 | try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi)), 0, eps)); |
| 164 | try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 2)), 1, eps)); |
| 165 | try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | { |
| 160 | 170 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 161 | 171 | var result = @sin(v); |
| 162 | 172 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); |
| 163 | 173 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); |
| 164 | 174 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); |
| 165 | 175 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon)); |
| 166 | | |
| 167 | | // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)` |
| 168 | | // so skip the rest of the tests. |
| 169 | | return; |
| 170 | | } |
| 171 | | |
| 172 | | inline for ([_]type{ f16, f32, f64 }) |ty| { |
| 173 | | const eps = epsForType(ty); |
| 174 | | try expect(@sin(@as(ty, 0)) == 0); |
| 175 | | try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi)), 0, eps)); |
| 176 | | try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 2)), 1, eps)); |
| 177 | | try expect(math.approxEqAbs(ty, @sin(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); |
| 178 | 176 | } |
| 179 | 177 | } |
| 180 | 178 | |
| ... | ... | @@ -184,26 +182,25 @@ test "@cos" { |
| 184 | 182 | } |
| 185 | 183 | |
| 186 | 184 | fn testCos() !void { |
| 187 | | // TODO: Implement Vector support for other backends |
| 188 | | if (builtin.zig_backend == .stage1) { |
| 185 | // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)` |
| 186 | // so skip the rest of the tests. |
| 187 | if (builtin.zig_backend != .stage1) { |
| 188 | inline for ([_]type{ f16, f32, f64 }) |ty| { |
| 189 | const eps = epsForType(ty); |
| 190 | try expect(@cos(@as(ty, 0)) == 1); |
| 191 | try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi)), -1, eps)); |
| 192 | try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 2)), 0, eps)); |
| 193 | try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | { |
| 189 | 198 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 190 | 199 | var result = @cos(v); |
| 191 | 200 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); |
| 192 | 201 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); |
| 193 | 202 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); |
| 194 | 203 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon)); |
| 195 | | |
| 196 | | // stage1 emits an incorrect compile error for `@as(ty, std.math.pi / 2)` |
| 197 | | // so skip the rest of the tests. |
| 198 | | return; |
| 199 | | } |
| 200 | | |
| 201 | | inline for ([_]type{ f16, f32, f64 }) |ty| { |
| 202 | | const eps = epsForType(ty); |
| 203 | | try expect(@cos(@as(ty, 0)) == 1); |
| 204 | | try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi)), -1, eps)); |
| 205 | | try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 2)), 0, eps)); |
| 206 | | try expect(math.approxEqAbs(ty, @cos(@as(ty, std.math.pi / 4)), 0.7071067811865475, eps)); |
| 207 | 204 | } |
| 208 | 205 | } |
| 209 | 206 | |
| ... | ... | @@ -220,8 +217,7 @@ fn testExp() !void { |
| 220 | 217 | try expect(math.approxEqAbs(ty, @exp(@as(ty, 5)), 148.4131591025766, eps)); |
| 221 | 218 | } |
| 222 | 219 | |
| 223 | | // TODO: Implement Vector support for other backends |
| 224 | | if (builtin.zig_backend == .stage1) { |
| 220 | { |
| 225 | 221 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 226 | 222 | var result = @exp(v); |
| 227 | 223 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -244,8 +240,7 @@ fn testExp2() !void { |
| 244 | 240 | try expect(math.approxEqAbs(ty, @exp2(@as(ty, 4.5)), 22.627416997969, eps)); |
| 245 | 241 | } |
| 246 | 242 | |
| 247 | | // TODO: Implement Vector support for other backends |
| 248 | | if (builtin.zig_backend == .stage1) { |
| 243 | { |
| 249 | 244 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 250 | 245 | var result = @exp2(v); |
| 251 | 246 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -281,8 +276,7 @@ fn testLog() !void { |
| 281 | 276 | try expect(math.approxEqAbs(ty, @log(@as(ty, 5)), 1.6094379124341, eps)); |
| 282 | 277 | } |
| 283 | 278 | |
| 284 | | // TODO: Implement Vector support for other backends |
| 285 | | if (builtin.zig_backend == .stage1) { |
| 279 | { |
| 286 | 280 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 287 | 281 | var result = @log(v); |
| 288 | 282 | try expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -305,8 +299,7 @@ fn testLog2() !void { |
| 305 | 299 | try expect(math.approxEqAbs(ty, @log2(@as(ty, 10)), 3.3219280948874, eps)); |
| 306 | 300 | } |
| 307 | 301 | |
| 308 | | // TODO: Implement Vector support for other backends |
| 309 | | if (builtin.zig_backend == .stage1) { |
| 302 | { |
| 310 | 303 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 311 | 304 | var result = @log2(v); |
| 312 | 305 | try expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -329,8 +322,7 @@ fn testLog10() !void { |
| 329 | 322 | try expect(math.approxEqAbs(ty, @log10(@as(ty, 50)), 1.698970004336, eps)); |
| 330 | 323 | } |
| 331 | 324 | |
| 332 | | // TODO: Implement Vector support for other backends |
| 333 | | if (builtin.zig_backend == .stage1) { |
| 325 | { |
| 334 | 326 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 335 | 327 | var result = @log10(v); |
| 336 | 328 | try expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -362,8 +354,7 @@ fn testFabs() !void { |
| 362 | 354 | // try expect(@fabs(b) == 2.5); |
| 363 | 355 | // } |
| 364 | 356 | |
| 365 | | // TODO: Implement Vector support for other backends |
| 366 | | if (builtin.zig_backend == .stage1) { |
| 357 | { |
| 367 | 358 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 368 | 359 | var result = @fabs(v); |
| 369 | 360 | try expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -390,8 +381,7 @@ fn testFloor() !void { |
| 390 | 381 | // try expect(@floor(a) == 3); |
| 391 | 382 | // } |
| 392 | 383 | |
| 393 | | // TODO: Implement Vector support for other backends |
| 394 | | if (builtin.zig_backend == .stage1) { |
| 384 | { |
| 395 | 385 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 396 | 386 | var result = @floor(v); |
| 397 | 387 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -418,8 +408,7 @@ fn testCeil() !void { |
| 418 | 408 | // try expect(@ceil(a) == 4); |
| 419 | 409 | // } |
| 420 | 410 | |
| 421 | | // TODO: Implement Vector support for other backends |
| 422 | | if (builtin.zig_backend == .stage1) { |
| 411 | { |
| 423 | 412 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 424 | 413 | var result = @ceil(v); |
| 425 | 414 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); |
| ... | ... | @@ -446,8 +435,7 @@ fn testTrunc() !void { |
| 446 | 435 | // try expect(@trunc(a) == -3); |
| 447 | 436 | // } |
| 448 | 437 | |
| 449 | | // TODO: Implement Vector support for other backends |
| 450 | | if (builtin.zig_backend == .stage1) { |
| 438 | { |
| 451 | 439 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 452 | 440 | var result = @trunc(v); |
| 453 | 441 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); |