@zigc/lib 0.16.0-dev.3070 → 0.16.0-dev.3121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/c/math.zig +125 -22
  2. package/c/stropts.zig +17 -0
  3. package/c.zig +1 -0
  4. package/compiler_rt/cos.zig +141 -52
  5. package/compiler_rt/limb64.zig +266 -0
  6. package/compiler_rt/long_double.zig +37 -0
  7. package/compiler_rt/rem_pio2l.zig +173 -0
  8. package/compiler_rt/sin.zig +140 -55
  9. package/compiler_rt/sincos.zig +279 -72
  10. package/compiler_rt/tan.zig +118 -47
  11. package/compiler_rt/trig.zig +256 -6
  12. package/compiler_rt.zig +2 -0
  13. package/package.json +1 -1
  14. package/std/Build/Module.zig +1 -1
  15. package/std/Build/abi.zig +8 -4
  16. package/std/Io/Dispatch.zig +2 -0
  17. package/std/Io/File.zig +1 -0
  18. package/std/Io/Threaded.zig +2 -0
  19. package/std/Io/Uring.zig +1 -0
  20. package/std/array_list.zig +22 -31
  21. package/std/debug/Info.zig +4 -0
  22. package/std/debug/SelfInfo/Windows.zig +1 -0
  23. package/std/heap/ArenaAllocator.zig +145 -154
  24. package/std/mem/Allocator.zig +4 -5
  25. package/std/mem.zig +48 -0
  26. package/std/testing/Smith.zig +37 -2
  27. package/std/zig/Ast/Render.zig +186 -458
  28. package/std/zig/Ast.zig +0 -4
  29. package/std/zig/AstSmith.zig +2602 -0
  30. package/std/zig/Parse.zig +83 -74
  31. package/std/zig/system.zig +2 -0
  32. package/std/zig/tokenizer.zig +2 -1
  33. package/std/zig.zig +2 -0
  34. package/libc/mingw/math/arm/sincos.S +0 -30
  35. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  36. package/libc/mingw/math/arm64/rint.c +0 -12
  37. package/libc/mingw/math/arm64/rintf.c +0 -12
  38. package/libc/mingw/math/arm64/sincos.S +0 -32
  39. package/libc/mingw/math/frexpf.c +0 -13
  40. package/libc/mingw/math/frexpl.c +0 -71
  41. package/libc/mingw/math/x86/cos.def.h +0 -65
  42. package/libc/mingw/math/x86/cosl.c +0 -46
  43. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  44. package/libc/mingw/math/x86/sin.def.h +0 -65
  45. package/libc/mingw/math/x86/sinl.c +0 -46
  46. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  47. package/libc/mingw/math/x86/tanl.S +0 -62
  48. package/libc/musl/src/legacy/isastream.c +0 -7
  49. package/libc/musl/src/math/__cosl.c +0 -96
  50. package/libc/musl/src/math/__sinl.c +0 -78
  51. package/libc/musl/src/math/__tanl.c +0 -143
  52. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  53. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  54. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  55. package/libc/musl/src/math/cosl.c +0 -39
  56. package/libc/musl/src/math/fdim.c +0 -10
  57. package/libc/musl/src/math/finite.c +0 -7
  58. package/libc/musl/src/math/finitef.c +0 -7
  59. package/libc/musl/src/math/frexp.c +0 -23
  60. package/libc/musl/src/math/frexpf.c +0 -23
  61. package/libc/musl/src/math/frexpl.c +0 -29
  62. package/libc/musl/src/math/i386/lrint.c +0 -8
  63. package/libc/musl/src/math/i386/lrintf.c +0 -8
  64. package/libc/musl/src/math/i386/rintf.c +0 -7
  65. package/libc/musl/src/math/lrint.c +0 -72
  66. package/libc/musl/src/math/lrintf.c +0 -8
  67. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  68. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  69. package/libc/musl/src/math/rintf.c +0 -30
  70. package/libc/musl/src/math/s390x/rintf.c +0 -15
  71. package/libc/musl/src/math/sincosl.c +0 -60
  72. package/libc/musl/src/math/sinl.c +0 -41
  73. package/libc/musl/src/math/tanl.c +0 -29
  74. package/libc/musl/src/math/x32/lrint.s +0 -5
  75. package/libc/musl/src/math/x32/lrintf.s +0 -5
  76. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  77. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
package/c/math.zig CHANGED
@@ -36,6 +36,8 @@ comptime {
36
36
 
37
37
  if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
38
38
  symbol(&coshf, "coshf");
39
+ symbol(&frexpf, "frexpf");
40
+ symbol(&frexpl, "frexpl");
39
41
  symbol(&hypotf, "hypotf");
40
42
  symbol(&hypotl, "hypotl");
41
43
  symbol(&modff, "modff");
@@ -46,6 +48,11 @@ comptime {
46
48
  symbol(&tanhf, "tanhf");
47
49
  }
48
50
 
51
+ if (builtin.target.isMinGW() or builtin.target.isMuslLibC()) {
52
+ symbol(&rint, "rint");
53
+ symbol(&rintf, "rintf");
54
+ }
55
+
49
56
  if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
50
57
  symbol(&acos, "acos");
51
58
  symbol(&acosf, "acosf");
@@ -59,7 +66,13 @@ comptime {
59
66
  symbol(&cosh, "cosh");
60
67
  symbol(&exp10, "exp10");
61
68
  symbol(&exp10f, "exp10f");
69
+ symbol(&fdim, "fdim");
70
+ symbol(&finite, "finite");
71
+ symbol(&finitef, "finitef");
72
+ symbol(&frexp, "frexp");
62
73
  symbol(&hypot, "hypot");
74
+ symbol(&lrint, "lrint");
75
+ symbol(&lrintf, "lrintf");
63
76
  symbol(&modf, "modf");
64
77
  symbol(&pow, "pow");
65
78
  symbol(&pow10, "pow10");
@@ -70,7 +83,6 @@ comptime {
70
83
  if (builtin.target.isMuslLibC()) {
71
84
  symbol(&copysign, "copysign");
72
85
  symbol(&copysignf, "copysignf");
73
- symbol(&rint, "rint");
74
86
  }
75
87
 
76
88
  symbol(&copysignl, "copysignl");
@@ -147,6 +159,58 @@ fn exp10f(x: f32) callconv(.c) f32 {
147
159
  return math.pow(f32, 10.0, x);
148
160
  }
149
161
 
162
+ fn fdim(x: f64, y: f64) callconv(.c) f64 {
163
+ if (math.isNan(x)) {
164
+ return x;
165
+ }
166
+ if (math.isNan(y)) {
167
+ return y;
168
+ }
169
+ if (x > y) {
170
+ return x - y;
171
+ }
172
+ return 0;
173
+ }
174
+
175
+ fn finite(x: f64) callconv(.c) c_int {
176
+ return if (math.isFinite(x)) 1 else 0;
177
+ }
178
+
179
+ fn finitef(x: f32) callconv(.c) c_int {
180
+ return if (math.isFinite(x)) 1 else 0;
181
+ }
182
+
183
+ fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
184
+ // libc expects `*e` to be unspecified in this case; an unspecified C value
185
+ // should be a valid value of the relevant type, yet Zig's std
186
+ // implementation sets it to `undefined` -- which can even be nonsense
187
+ // according to the type (int). Therefore, we're setting it to a valid
188
+ // int value in Zig -- a zero.
189
+ //
190
+ // This mirrors the handling of infinities, where libc also expects
191
+ // unspecified for the value of `*e` and Zig std sets it to a zero.
192
+ if (math.isNan(x)) {
193
+ e.* = 0;
194
+ return x;
195
+ }
196
+
197
+ const r = math.frexp(x);
198
+ e.* = r.exponent;
199
+ return r.significand;
200
+ }
201
+
202
+ fn frexp(x: f64, e: *c_int) callconv(.c) f64 {
203
+ return frexpGeneric(f64, x, e);
204
+ }
205
+
206
+ fn frexpf(x: f32, e: *c_int) callconv(.c) f32 {
207
+ return frexpGeneric(f32, x, e);
208
+ }
209
+
210
+ fn frexpl(x: c_longdouble, e: *c_int) callconv(.c) c_longdouble {
211
+ return frexpGeneric(c_longdouble, x, e);
212
+ }
213
+
150
214
  fn hypot(x: f64, y: f64) callconv(.c) f64 {
151
215
  return math.hypot(x, y);
152
216
  }
@@ -171,6 +235,14 @@ fn isnanl(x: c_longdouble) callconv(.c) c_int {
171
235
  return if (math.isNan(x)) 1 else 0;
172
236
  }
173
237
 
238
+ fn lrint(x: f64) callconv(.c) c_long {
239
+ return @intFromFloat(rint(x));
240
+ }
241
+
242
+ fn lrintf(x: f32) callconv(.c) c_long {
243
+ return @intFromFloat(rintf(x));
244
+ }
245
+
174
246
  fn modfGeneric(comptime T: type, x: T, iptr: *T) T {
175
247
  if (math.isNegativeInf(x)) {
176
248
  iptr.* = -math.inf(T);
@@ -285,7 +357,7 @@ fn pow10f(x: f32) callconv(.c) f32 {
285
357
  }
286
358
 
287
359
  fn rint(x: f64) callconv(.c) f64 {
288
- const toint: f64 = 1.0 / @as(f64, math.floatEps(f64));
360
+ const toint: f64 = 1.0 / math.floatEps(f64);
289
361
  const a: u64 = @bitCast(x);
290
362
  const e = a >> 52 & 0x7ff;
291
363
  const s = a >> 63;
@@ -305,39 +377,70 @@ fn rint(x: f64) callconv(.c) f64 {
305
377
  return y;
306
378
  }
307
379
 
308
- test "rint" {
380
+ fn rintf(x: f32) callconv(.c) f32 {
381
+ const toint: f32 = 1.0 / math.floatEps(f32);
382
+ const a: u32 = @bitCast(x);
383
+ const e = a >> 23 & 0xff;
384
+ const s = a >> 31;
385
+ var y: f32 = undefined;
386
+
387
+ if (e >= 0x7f + 23) {
388
+ return x;
389
+ }
390
+
391
+ if (s == 1) {
392
+ y = x - toint + toint;
393
+ } else {
394
+ y = x + toint - toint;
395
+ }
396
+
397
+ if (y == 0) {
398
+ return if (s == 1) -0.0 else 0;
399
+ }
400
+ return y;
401
+ }
402
+
403
+ fn testRint(comptime T: type) !void {
404
+ const f = switch (T) {
405
+ f32 => rintf,
406
+ f64 => rint,
407
+ else => @compileError("rint not implemented for" ++ @typeName(T)),
408
+ };
409
+
309
410
  // Positive numbers round correctly
310
- try expectEqual(@as(f64, 42.0), rint(42.2));
311
- try expectEqual(@as(f64, 42.0), rint(41.8));
411
+ try expectEqual(@as(T, 42.0), f(42.2));
412
+ try expectEqual(@as(T, 42.0), f(41.8));
312
413
 
313
414
  // Negative numbers round correctly
314
- try expectEqual(@as(f64, -6.0), rint(-5.9));
315
- try expectEqual(@as(f64, -6.0), rint(-6.1));
415
+ try expectEqual(@as(T, -6.0), f(-5.9));
416
+ try expectEqual(@as(T, -6.0), f(-6.1));
316
417
 
317
418
  // No rounding needed test
318
- try expectEqual(@as(f64, 5.0), rint(5.0));
319
- try expectEqual(@as(f64, -10.0), rint(-10.0));
320
- try expectEqual(@as(f64, 0.0), rint(0.0));
419
+ try expectEqual(@as(T, 5.0), f(5.0));
420
+ try expectEqual(@as(T, -10.0), f(-10.0));
421
+ try expectEqual(@as(T, 0.0), f(0.0));
321
422
 
322
423
  // Very large numbers return unchanged
323
- const large: f64 = 9007199254740992.0; // 2^53
324
- try expectEqual(large, rint(large));
325
- try expectEqual(-large, rint(-large));
424
+ const large: T = 9007199254740992.0; // 2^53
425
+ try expectEqual(large, f(large));
426
+ try expectEqual(-large, f(-large));
326
427
 
327
428
  // Small positive numbers round to zero
328
- const pos_result = rint(0.3);
329
- try expectEqual(@as(f64, 0.0), pos_result);
330
- try expect(@as(u64, @bitCast(pos_result)) == 0);
429
+ const pos_result = f(0.3);
430
+ try expect(math.isPositiveZero(pos_result));
331
431
 
332
432
  // Small negative numbers round to negative zero
333
- const neg_result = rint(-0.3);
334
- try expectEqual(@as(f64, 0.0), neg_result);
335
- const bits: u64 = @bitCast(neg_result);
336
- try expect((bits >> 63) == 1);
433
+ const neg_result = f(-0.3);
434
+ try expect(math.isNegativeZero(neg_result));
337
435
 
338
436
  // Exact half rounds to nearest even (banker's rounding)
339
- try expectEqual(@as(f64, 2.0), rint(2.5));
340
- try expectEqual(@as(f64, 4.0), rint(3.5));
437
+ try expectEqual(@as(T, 2.0), f(2.5));
438
+ try expectEqual(@as(T, 4.0), f(3.5));
439
+ }
440
+
441
+ test "rint" {
442
+ try testRint(f32);
443
+ try testRint(f64);
341
444
  }
342
445
 
343
446
  fn tanh(x: f64) callconv(.c) f64 {
package/c/stropts.zig ADDED
@@ -0,0 +1,17 @@
1
+ const builtin = @import("builtin");
2
+
3
+ const std = @import("std");
4
+ const linux = std.os.linux;
5
+
6
+ const symbol = @import("../c.zig").symbol;
7
+ const errno = @import("../c.zig").errno;
8
+
9
+ comptime {
10
+ if (builtin.target.isMuslLibC()) {
11
+ symbol(&isastream, "isastream");
12
+ }
13
+ }
14
+
15
+ fn isastream(fd: c_int) callconv(.c) c_int {
16
+ return if (errno(linux.fcntl(fd, linux.F.GETFD, 0)) < 0) -1 else 0;
17
+ }
package/c.zig CHANGED
@@ -73,6 +73,7 @@ comptime {
73
73
  _ = @import("c/stdlib.zig");
74
74
  _ = @import("c/string.zig");
75
75
  _ = @import("c/strings.zig");
76
+ _ = @import("c/stropts.zig");
76
77
 
77
78
  _ = @import("c/sys/capability.zig");
78
79
  _ = @import("c/sys/file.zig");
@@ -1,19 +1,30 @@
1
+ //! Ported from musl, which is licensed under the MIT license:
2
+ //! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3
+ //!
4
+ //! https://git.musl-libc.org/cgit/musl/tree/src/math/cosf.c
5
+ //! https://git.musl-libc.org/cgit/musl/tree/src/math/cos.c
6
+ //! https://git.musl-libc.org/cgit/musl/tree/src/math/cosl.c
7
+
1
8
  const std = @import("std");
2
9
  const math = std.math;
3
10
  const mem = std.mem;
4
11
  const expect = std.testing.expect;
12
+ const expectApproxEqAbs = std.testing.expectApproxEqAbs;
5
13
 
6
14
  const compiler_rt = @import("../compiler_rt.zig");
7
15
  const symbol = @import("../compiler_rt.zig").symbol;
8
16
  const trig = @import("trig.zig");
9
17
  const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
10
18
  const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
19
+ const rem_pio2l = @import("rem_pio2l.zig").rem_pio2l;
20
+ const ld = @import("long_double.zig");
11
21
 
12
22
  comptime {
13
- symbol(&__cosh, "__cosh");
23
+ symbol(&cosh, "__cosh");
24
+ symbol(&cosl, "__cosl");
14
25
  symbol(&cosf, "cosf");
15
26
  symbol(&cos, "cos");
16
- symbol(&__cosx, "__cosx");
27
+ symbol(&cosx, "__cosx");
17
28
  if (compiler_rt.want_ppc_abi) {
18
29
  symbol(&cosq, "cosf128");
19
30
  }
@@ -21,7 +32,7 @@ comptime {
21
32
  symbol(&cosl, "cosl");
22
33
  }
23
34
 
24
- pub fn __cosh(a: f16) callconv(.c) f16 {
35
+ pub fn cosh(a: f16) callconv(.c) f16 {
25
36
  // TODO: more efficient implementation
26
37
  return @floatCast(cosf(a));
27
38
  }
@@ -43,27 +54,27 @@ pub fn cosf(x: f32) callconv(.c) f32 {
43
54
  if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
44
55
  return 1.0;
45
56
  }
46
- return trig.__cosdf(x);
57
+ return trig.cosdf(x);
47
58
  }
48
59
  if (ix <= 0x407b53d1) { // |x| ~<= 5*pi/4
49
60
  if (ix > 0x4016cbe3) { // |x| ~> 3*pi/4
50
- return -trig.__cosdf(if (sign) x + c2pio2 else x - c2pio2);
61
+ return -trig.cosdf(if (sign) x + c2pio2 else x - c2pio2);
51
62
  } else {
52
63
  if (sign) {
53
- return trig.__sindf(x + c1pio2);
64
+ return trig.sindf(x + c1pio2);
54
65
  } else {
55
- return trig.__sindf(c1pio2 - x);
66
+ return trig.sindf(c1pio2 - x);
56
67
  }
57
68
  }
58
69
  }
59
70
  if (ix <= 0x40e231d5) { // |x| ~<= 9*pi/4
60
71
  if (ix > 0x40afeddf) { // |x| ~> 7*pi/4
61
- return trig.__cosdf(if (sign) x + c4pio2 else x - c4pio2);
72
+ return trig.cosdf(if (sign) x + c4pio2 else x - c4pio2);
62
73
  } else {
63
74
  if (sign) {
64
- return trig.__sindf(-x - c3pio2);
75
+ return trig.sindf(-x - c3pio2);
65
76
  } else {
66
- return trig.__sindf(x - c3pio2);
77
+ return trig.sindf(x - c3pio2);
67
78
  }
68
79
  }
69
80
  }
@@ -76,10 +87,10 @@ pub fn cosf(x: f32) callconv(.c) f32 {
76
87
  var y: f64 = undefined;
77
88
  const n = rem_pio2f(x, &y);
78
89
  return switch (n & 3) {
79
- 0 => trig.__cosdf(y),
80
- 1 => trig.__sindf(-y),
81
- 2 => -trig.__cosdf(y),
82
- else => trig.__sindf(y),
90
+ 0 => trig.cosdf(y),
91
+ 1 => trig.sindf(-y),
92
+ 2 => -trig.cosdf(y),
93
+ else => trig.sindf(y),
83
94
  };
84
95
  }
85
96
 
@@ -94,7 +105,7 @@ pub fn cos(x: f64) callconv(.c) f64 {
94
105
  if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
95
106
  return 1.0;
96
107
  }
97
- return trig.__cos(x, 0);
108
+ return trig.cos(x, 0);
98
109
  }
99
110
 
100
111
  // cos(Inf or NaN) is NaN
@@ -105,66 +116,144 @@ pub fn cos(x: f64) callconv(.c) f64 {
105
116
  var y: [2]f64 = undefined;
106
117
  const n = rem_pio2(x, &y);
107
118
  return switch (n & 3) {
108
- 0 => trig.__cos(y[0], y[1]),
109
- 1 => -trig.__sin(y[0], y[1], 1),
110
- 2 => -trig.__cos(y[0], y[1]),
111
- else => trig.__sin(y[0], y[1], 1),
119
+ 0 => trig.cos(y[0], y[1]),
120
+ 1 => -trig.sin(y[0], y[1], 1),
121
+ 2 => -trig.cos(y[0], y[1]),
122
+ else => trig.sin(y[0], y[1], 1),
112
123
  };
113
124
  }
114
125
 
115
- pub fn __cosx(a: f80) callconv(.c) f80 {
116
- // TODO: more efficient implementation
117
- return @floatCast(cosq(a));
126
+ pub fn cosx(x: f80) callconv(.c) f80 {
127
+ const se = ld.signExponent(x) & 0x7fff;
128
+ if (se == 0x7fff) {
129
+ return x - x;
130
+ }
131
+
132
+ if (@abs(x) < trig.pi_4) {
133
+ if (se < 0x3fff - math.floatMantissaBits(f80)) {
134
+ // raise inexact if x!=0
135
+ return 1.0 + x;
136
+ }
137
+ return trig.cosx(x, 0.0);
138
+ }
139
+
140
+ var y: [2]f80 = undefined;
141
+ const n = rem_pio2l(f80, x, &y);
142
+ return switch (n & 3) {
143
+ 0 => trig.cosx(y[0], y[1]),
144
+ 1 => -trig.sinx(y[0], y[1], 1),
145
+ 2 => -trig.cosx(y[0], y[1]),
146
+ else => trig.sinx(y[0], y[1], 1),
147
+ };
118
148
  }
119
149
 
120
- pub fn cosq(a: f128) callconv(.c) f128 {
121
- // TODO: more correct implementation
122
- return cos(@floatCast(a));
150
+ pub fn cosq(x: f128) callconv(.c) f128 {
151
+ const se = ld.signExponent(x) & 0x7fff;
152
+ if (se == 0x7fff) {
153
+ return x - x;
154
+ }
155
+
156
+ if (@abs(x) < trig.pi_4) {
157
+ if (se < 0x3fff - math.floatMantissaBits(f128)) {
158
+ // raise inexact if x!=0
159
+ return 1.0 + x;
160
+ }
161
+ return trig.cosq(x, 0.0);
162
+ }
163
+
164
+ var y: [2]f128 = undefined;
165
+ const n = rem_pio2l(f128, x, &y);
166
+ return switch (n & 3) {
167
+ 0 => trig.cosq(y[0], y[1]),
168
+ 1 => -trig.sinq(y[0], y[1], 1),
169
+ 2 => -trig.cosq(y[0], y[1]),
170
+ else => trig.sinq(y[0], y[1], 1),
171
+ };
123
172
  }
124
173
 
125
174
  pub fn cosl(x: c_longdouble) callconv(.c) c_longdouble {
126
175
  switch (@typeInfo(c_longdouble).float.bits) {
127
- 16 => return __cosh(x),
176
+ 16 => return cosh(x),
128
177
  32 => return cosf(x),
129
178
  64 => return cos(x),
130
- 80 => return __cosx(x),
179
+ 80 => return cosx(x),
131
180
  128 => return cosq(x),
132
181
  else => @compileError("unreachable"),
133
182
  }
134
183
  }
135
184
 
136
- test "cos32" {
137
- const epsilon = 0.00001;
185
+ fn testCosSpecial(comptime T: type) !void {
186
+ const f = switch (T) {
187
+ f32 => cosf,
188
+ f64 => cos,
189
+ f80 => cosx,
190
+ f128 => cosq,
191
+ else => @compileError("unimplemented"),
192
+ };
138
193
 
139
- try expect(math.approxEqAbs(f32, cosf(0.0), 1.0, epsilon));
140
- try expect(math.approxEqAbs(f32, cosf(0.2), 0.980067, epsilon));
141
- try expect(math.approxEqAbs(f32, cosf(0.8923), 0.627623, epsilon));
142
- try expect(math.approxEqAbs(f32, cosf(1.5), 0.070737, epsilon));
143
- try expect(math.approxEqAbs(f32, cosf(-1.5), 0.070737, epsilon));
144
- try expect(math.approxEqAbs(f32, cosf(37.45), 0.969132, epsilon));
145
- try expect(math.approxEqAbs(f32, cosf(89.123), 0.400798, epsilon));
194
+ try expect(f(0.0) == 1.0);
195
+ try expect(f(-0.0) == 1.0);
196
+ try expect(math.isNan(f(math.inf(T))));
197
+ try expect(math.isNan(f(-math.inf(T))));
198
+ try expect(math.isNan(f(math.nan(T))));
146
199
  }
147
200
 
148
- test "cos64" {
149
- const epsilon = 0.000001;
150
-
151
- try expect(math.approxEqAbs(f64, cos(0.0), 1.0, epsilon));
152
- try expect(math.approxEqAbs(f64, cos(0.2), 0.980067, epsilon));
153
- try expect(math.approxEqAbs(f64, cos(0.8923), 0.627623, epsilon));
154
- try expect(math.approxEqAbs(f64, cos(1.5), 0.070737, epsilon));
155
- try expect(math.approxEqAbs(f64, cos(-1.5), 0.070737, epsilon));
156
- try expect(math.approxEqAbs(f64, cos(37.45), 0.969132, epsilon));
157
- try expect(math.approxEqAbs(f64, cos(89.123), 0.40080, epsilon));
201
+ test "cos32.normal" {
202
+ const epsilon = math.floatEps(f32);
203
+ try expectApproxEqAbs(@as(f32, 1.0), cosf(0.0), epsilon);
204
+ try expectApproxEqAbs(@as(f32, 0.9800666), cosf(0.2), epsilon);
205
+ try expectApproxEqAbs(@as(f32, 0.6276231), cosf(0.8923), epsilon);
206
+ try expectApproxEqAbs(@as(f32, 0.0707372), cosf(1.5), epsilon);
207
+ try expectApproxEqAbs(@as(f32, 0.0707372), cosf(-1.5), epsilon);
208
+ try expectApproxEqAbs(@as(f32, 0.96913195), cosf(37.45), epsilon);
209
+ try expectApproxEqAbs(@as(f32, 0.40079966), cosf(89.123), epsilon);
158
210
  }
159
211
 
160
212
  test "cos32.special" {
161
- try expect(math.isNan(cosf(math.inf(f32))));
162
- try expect(math.isNan(cosf(-math.inf(f32))));
163
- try expect(math.isNan(cosf(math.nan(f32))));
213
+ try testCosSpecial(f32);
214
+ }
215
+
216
+ test "cos64.normal" {
217
+ const epsilon = math.floatEps(f64);
218
+ try expectApproxEqAbs(@as(f64, 1.0), cos(0.0), epsilon);
219
+ try expectApproxEqAbs(@as(f64, 0.9800665778412416), cos(0.2), epsilon);
220
+ try expectApproxEqAbs(@as(f64, 0.6276230983360804), cos(0.8923), epsilon);
221
+ try expectApproxEqAbs(@as(f64, 0.0707372016677029), cos(1.5), epsilon);
222
+ try expectApproxEqAbs(@as(f64, 0.0707372016677029), cos(-1.5), epsilon);
223
+ try expectApproxEqAbs(@as(f64, 0.9691317730707778), cos(37.45), epsilon);
224
+ try expectApproxEqAbs(@as(f64, 0.4008006809354791), cos(89.123), epsilon);
164
225
  }
165
226
 
166
227
  test "cos64.special" {
167
- try expect(math.isNan(cos(math.inf(f64))));
168
- try expect(math.isNan(cos(-math.inf(f64))));
169
- try expect(math.isNan(cos(math.nan(f64))));
228
+ try testCosSpecial(f64);
229
+ }
230
+
231
+ test "cos80.normal" {
232
+ const epsilon = math.floatEps(f80);
233
+ try expectApproxEqAbs(@as(f80, 1.0), cosx(0.0), epsilon);
234
+ try expectApproxEqAbs(@as(f80, 0.98006657784124163112419651674816888), cosx(0.2), epsilon);
235
+ try expectApproxEqAbs(@as(f80, 0.62762309833608037003563995939286067), cosx(0.8923), epsilon);
236
+ try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), cosx(1.5), epsilon);
237
+ try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), cosx(-1.5), epsilon);
238
+ try expectApproxEqAbs(@as(f80, 0.9691317730707771246), cosx(37.45), epsilon);
239
+ try expectApproxEqAbs(@as(f80, 0.4008006809354834001), cosx(89.123), epsilon);
240
+ }
241
+
242
+ test "cos80.special" {
243
+ try testCosSpecial(f80);
244
+ }
245
+
246
+ test "cos128.normal" {
247
+ const epsilon = math.floatEps(f128);
248
+ try expectApproxEqAbs(@as(f128, 1.0), cosq(0.0), epsilon);
249
+ try expectApproxEqAbs(@as(f128, 0.98006657784124163112419651674816888), cosq(0.2), epsilon);
250
+ try expectApproxEqAbs(@as(f128, 0.62762309833608037003563995939286067), cosq(0.8923), epsilon);
251
+ try expectApproxEqAbs(@as(f128, 0.070737201667702910088189851434268747), cosq(1.5), epsilon);
252
+ try expectApproxEqAbs(@as(f128, 0.070737201667702910088189851434268747), cosq(-1.5), epsilon);
253
+ try expectApproxEqAbs(@as(f128, 0.96913177307077712443149563847233230), cosq(37.45), epsilon);
254
+ try expectApproxEqAbs(@as(f128, 0.40080068093548339848199454493704702), cosq(89.123), epsilon);
255
+ }
256
+
257
+ test "cos128.special" {
258
+ try testCosSpecial(f128);
170
259
  }