{"id":20145878,"url":"https://github.com/usagi/arithmetic-sign","last_synced_at":"2025-10-03T15:44:45.667Z","repository":{"id":57493669,"uuid":"295427340","full_name":"usagi/arithmetic-sign","owner":"usagi","description":"Arithmetic `Sign`(≈+1|-1) to/from arithmetic types such as `f64`, `i32` utility.","archived":false,"fork":false,"pushed_at":"2020-09-14T13:38:26.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-11T02:03:35.286Z","etag":null,"topics":["arithmetic","math","negative","positive","rust","sign"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usagi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-14T13:37:57.000Z","updated_at":"2023-01-16T13:12:50.000Z","dependencies_parsed_at":"2022-08-30T04:01:00.893Z","dependency_job_id":null,"html_url":"https://github.com/usagi/arithmetic-sign","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Farithmetic-sign","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Farithmetic-sign/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Farithmetic-sign/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Farithmetic-sign/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usagi","download_url":"https://codeload.github.com/usagi/arithmetic-sign/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Farithmetic-sign/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259184738,"owners_count":22818266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arithmetic","math","negative","positive","rust","sign"],"created_at":"2024-11-13T22:18:34.562Z","updated_at":"2025-10-03T15:44:40.642Z","avatar_url":"https://github.com/usagi.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arithmetic-sign\n\nArithmetic `Sign`(≈+1|-1) to/from arithmetic types such as `f64`, `i32` utility.\n\n## Feature\n\n- [x] `From` and `TryFrom`: An arithmetic type such as `f64`, `i32` =(`from`/`try_from`)\u003e `Sign`\n    - [x] `From`: For an integral such as `i32`.; It has no infinite pattern.\n    - [x] `TryFrom`: For an float such as `f64`.; It has +inf, -inf and NaN infinite patterns.\n        - [x] A finite, +inf, -inf are valid =\u003e `Ok`, nan is invalid =\u003e `Err`.\n- [x] `as_T`: `Sign` =(`as_T`)\u003e an arithmetic type such as `f64`, `i32`\n    - [x] `as_uT`: Safety unsigned casting. eg. pos =\u003e Ok, neg =\u003e Err\n- [x] `Display`: `Sign` =(`to_string`)\u003e `\"-\"` or `\"+\"`\n    - [x] `Sign` =(`to_string_specified(\"S\", \"N\")`)\u003e `\"S\"` or `\"N\"`\n- [x] `Mul` and `Div`: `Sign * Sign` or `Sign / Sign` -\u003e `Sign`; eg. neg * neg =\u003e pos, pos / neg =\u003e neg\n- [x] `Neg` and `Not`: `-Sign` or `!Sign` -\u003e `Sign`; eg. -neg =\u003e pos, !pos =\u003e neg\n- [x] `Eq`: `Sign` `==`|`!=` `Sign`; eg. neg == neg =\u003e true, pos != neg =\u003e true\n- [x] `Ord`: `Sign` `\u003c`|`\u003c=`|`\u003e=`|`\u003e` `Sign`; eg. neg \u003c pos =\u003e true, pos \u003e= pos =\u003e true, neg \u003e pos =\u003e false\n\n## Usage\n\n- See also: [tests/test.rs](tests/test.rs).\n\n```rust\nuse arithmetic_sign::*;\n```\n\n```rust\nlet _sign = Sign::from( 123 ); // -\u003e Sign::Positive\nlet _sign = Sign::from( 0 ); // -\u003e Sign::Positive\nlet _sign = Sign::from( -0 ); // -\u003e Sign::Positive\nlet _sign = Sign::from( -123 ); // -\u003e Sign::Negative\nlet _sign_maybe = Sign::try_from( 1.23 ); // -\u003e Ok( Sign::Positive )\nlet _sign_maybe = Sign::try_from( 0.0 ); // -\u003e Ok( Sign::Positive )\nlet _sign_maybe = Sign::try_from( -0.0 ); // -\u003e Ok( Sign::Positive )\nlet _sign_maybe = Sign::try_from( 1.23 ); // -\u003e Ok( Sign::Negative )\nlet _sign_maybe = Sign::try_from( std::f64::inf() ); // -\u003e Ok( Sign::Positive )\nlet _sign = Sign::from( -123 ) * Sign::from( 123 ); // -\u003e Sign::Negative\nlet _sign = !Sign::from( -123 ); // -\u003e Sign::Positive\nlet _f64 = Sign::Positive.as_f64(); // 1f64\nlet _i32 = Sign::Negative.as_i32(); // -1i32\nlet _u8 = Sign::Positive.as_u8().unwrap(); // 1u8\nlet _u8 = Sign::Negative.as_u8().is_err(); // true\n```\n\n## Motivation\n\n- The std sign features such as `std::{f32|f64}::copysign` or `std::*::signum`s are regard to negative from `-0.0`.\n    - But, I author wanted to regard to \"not a negative\" as \"positive\" from `0.0` and `-0.0`.\n    - And, I author wanted to boolean-like type such as \"positive\" and \"negative\" that has only 2-variant.\n    - And, Infinity is a valid signed value, NaN is not a valid value.\n\n## License\n\n- [MIT](LICENSE.md)\n\n## Author\n\n- [USAGI.NETWORK / Usagi Ito](https://github.com/usagi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi%2Farithmetic-sign","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusagi%2Farithmetic-sign","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi%2Farithmetic-sign/lists"}