# RangeInt **Repository Path**: heraldw/rangeInt ## Basic Information - **Project Name**: RangeInt - **Description**: 实现一个小范围的整数,可以闭着眼睛加加减减操作,绝对不会溢出。此仓库为ANSI-C版本,适用于嵌入式系统。c++版本请移步RangeInt_cpp - **Primary Language**: C - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-21 - **Last Updated**: 2026-01-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: stm32, ESP32, 嵌入式系统 ## README # RangeInt ![输入图片说明](%E8%AE%A1%E6%95%B0%E5%99%A8.png) #### 介绍 实现一个小范围的整数,可以闭着眼睛加加减减操作,绝对不会溢出。此仓库为ANSI-C版本,适用于嵌入式系统。c++版本请移步RangeInt_cpp 本计数器可以设置为非饱和式加减和饱和式加减。 - 饱和式加减的意思是:加到最大值的时候,继续加就停留在最大值上;减到最小值的时候,继续减就停留在最小值上 - 非饱和式加减的意思是:加到最大值的时候,数值跳到最小;减到最小值的时候,数值跳到最大 #### 软件架构 本class围绕着以下数据结构展开 ``` typedef struct RangeInt { int value; //这个就是你需要的那个数字 bool notSaturation; //非饱和加减模式,false时候表示是饱和式加减 int mmax; //最大值 int mmin; //最小值 }RangeInt; ``` #### 安装教程 没啥好安装的,直接拖进你的工程里面用就好了 #### 使用说明 构造函数 第一个参数指向计数器数据结构 第二个参数==true表示以不饱和方式方式计数 第三个参数,最大值。计数的时候包含本数。 第四个参数,最小值。计数的时候包含本数。 ``` void RangeInt_construct (struct RangeInt* this,bool notSaturation,int vmax,int vmin); //运行的时候包括Vmax本数 ``` 计数器++ ``` void RangeInt_inc(struct RangeInt* this); ``` 计数器-- ``` void RangeInt_dec(struct RangeInt* this); ``` 直接设置计数器数值,会自动处理超出范围的设置。 返回true说明输入数字合法。 返回false表示输入范围超限,this->value会设置成最大值或者最小值。 ``` bool RangeInt_setValue(struct RangeInt* this,int Value); //返回false,说明超出范围了,数字被强制限制在额定范围内 ``` 给计数器设置一个在额定区间的百分比数字,percentage的值域在0.00--1.00之间 ``` void RangeInt_setPercentage(struct RangeInt* this,float percentage); ``` 直接设置到最大值或者最小值 ``` void RangeInt_toMax(struct RangeInt* this); void RangeInt_toMin(struct RangeInt* this); ``` 一次加N,或者一次减N ``` void RangeInt_incN(struct RangeInt* this,int n); void RangeInt_decN(struct RangeInt* this,int n); ``` #### 参与贡献 1. 2. 王帅哥于 2026年1月21日 09:31:46 新建了本仓库 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)