File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -11,5 +11,10 @@ comptime {
11
11
}
12
12
13
13
fn imaxabs (a : intmax_t ) callconv (.c ) intmax_t {
14
- return if (a > 0 ) a else - a ;
14
+ return @intCast (@abs (a ));
15
+ }
16
+
17
+ test imaxabs {
18
+ const val : intmax_t = -10 ;
19
+ try std .testing .expectEqual (10 , imaxabs (val ));
15
20
}
Original file line number Diff line number Diff line change @@ -12,13 +12,28 @@ comptime {
12
12
}
13
13
14
14
fn abs (a : c_int ) callconv (.c ) c_int {
15
- return if ( a > 0 ) a else - a ;
15
+ return @intCast ( @abs ( a )) ;
16
16
}
17
17
18
18
fn labs (a : c_long ) callconv (.c ) c_long {
19
- return if ( a > 0 ) a else - a ;
19
+ return @intCast ( @abs ( a )) ;
20
20
}
21
21
22
22
fn llabs (a : c_longlong ) callconv (.c ) c_longlong {
23
- return if (a > 0 ) a else - a ;
23
+ return @intCast (@abs (a ));
24
+ }
25
+
26
+ test abs {
27
+ const val : c_int = -10 ;
28
+ try std .testing .expectEqual (10 , abs (val ));
29
+ }
30
+
31
+ test labs {
32
+ const val : c_long = -10 ;
33
+ try std .testing .expectEqual (10 , labs (val ));
34
+ }
35
+
36
+ test llabs {
37
+ const val : c_longlong = -10 ;
38
+ try std .testing .expectEqual (10 , llabs (val ));
24
39
}
You can’t perform that action at this time.
0 commit comments