File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 33## Unreleased
44
55* [ #7 ] - Add ` strtoul ` and ` strcpy `
6+ * [ #8 ] - Add ` abs `
67
78[ #7 ] : https://github.com/rust-embedded-community/tinyrlibc/pull/7
9+ [ #8 ] : https://github.com/rust-embedded-community/tinyrlibc/pull/8
810
911## v0.2.2 (2022-03-17)
1012
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ This crate basically came about so that the [nrfxlib](https://github.com/NordicP
88
99## Implemented so far
1010
11+ * abs
1112* strol
1213* atoi
1314* strcmp
Original file line number Diff line number Diff line change 1+ //! Rust implementation of C library function `abs`
2+ //!
3+ //! Licensed under the Blue Oak Model Licence 1.0.0
4+
5+ use crate :: CInt ;
6+
7+ /// Calculates the integer absolute value
8+ ///
9+ /// ```
10+ /// use tinyrlibc::abs;
11+ /// assert_eq!(abs(-2), 2);
12+ /// ```
13+ #[ no_mangle]
14+ pub extern "C" fn abs ( i : CInt ) -> CInt {
15+ i. abs ( )
16+ }
17+
18+ #[ cfg( test) ]
19+ mod test {
20+ use super :: * ;
21+
22+ #[ test]
23+ fn neg ( ) {
24+ assert_eq ! ( abs( -2 ) , 2 ) ;
25+ }
26+
27+ #[ test]
28+ fn pos ( ) {
29+ assert_eq ! ( abs( 3 ) , 3 ) ;
30+ }
31+
32+ #[ test]
33+ fn zero ( ) {
34+ assert_eq ! ( abs( 0 ) , 0 ) ;
35+ }
36+ }
Original file line number Diff line number Diff line change 1313#[ allow( unused_imports) ]
1414use std as core;
1515
16+ mod abs;
17+ pub use self :: abs:: abs;
18+
1619mod strcmp;
1720pub use self :: strcmp:: strcmp;
1821
You can’t perform that action at this time.
0 commit comments