当前位置:网站首页>编程语言中,取余和取模的区别
编程语言中,取余和取模的区别
2022-08-09 20:51:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
取余,遵循尽可能让商向0靠近的原则
取模,遵循尽可能让商向负无穷靠近的原则
在matlab中,关于取余和取模是这么定义的:
当y≠0时:
取余:rem(x,y)=x-y.*fix(x./y)
取模:mod(x,y)=x-y.*floor(x./y)
其中,fix()函数是向0取整,floor()函数是向负无穷取
运算为例:
7/(-3)=-2.3,在这个运算中,x为7,y为-3,分别调用fix()和floor()两个函数,得到结果是:
fix(-2.3)=-2
floor(-2.3)=-3
所以,rem(7,-3)=1,mod(7,-3)=-2
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/105810.html原文链接:https://javaforall.cn
边栏推荐
- Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?
- 力扣15-三数之和——HashSet&双指针法
- LeetCode Daily Question (321. Create Maximum Number)
- C语言预处理命令是什么?
- 如何在WPF中设置Grid ColumnDefinitions的样式
- Unity_物体自转
- Word怎么制作双面席卡?使用Word制作双面席卡方法
- Error when source install/setup.bash
- Install Mysql8.0 on windos, and solve the problem of re-login exception ERROR 1045 (28000)
- Word箭头上面怎么打字
猜你喜欢

Error when source install/setup.bash

Word文档怎么输入无穷大符号∞
![[Graphic and textual] How to reinstall Win7 system](/img/24/3acccb93e5e219f39477dc77229a58.png)
[Graphic and textual] How to reinstall Win7 system

Problems with compiling SIP with QGIS

Don't tell me to play, I'm taking the PMP exam: what you need to know about choosing an institution for the PMP exam

matlab neural network ANN classification

URL Protocol 网页打开应用程序

Simulation of Water Temperature Control System Based on Fuzzy PID Controller

CMake installation upgrade higher version

字节二面问的MySQL,差点没答好
随机推荐
一种基于连接和安全熵的网络空间整体安全认识和方法
【深度学习】pix2pix GAN理论及代码实现
【高效工具】远程控制软件 ToDesk(收藏夹)
LED闪烁 闪灯芯片IC 手电筒IC 闪灯控制IC 闪烁IC流水灯
leetcode二叉搜索树与双向链表
安科瑞支持以太网通讯、profibus通讯嵌入式电能表APM指导性技术要求-Susie 周
Overview of Security Analysis Technology for Smart Home Devices
Error when source install/setup.bash
Number of daffodils within a thousand
痛击面试官 CURD系统也能做出技术含量
微软Excel表格点击单元格行和列都显示颜色怎么弄?聚光灯效果设置
Definition and Basic Operations of Linear Tables
基于Docker构建MySQL主从复制数据库
An overall security understanding and method of cyberspace based on connection and security entropy
buuctf(探险2)
【NOI模拟赛】防AK题(生成函数,单位根,Pollard-Rho)
matlab 神经网络 ANN 分类
Definition and Basic Operations of Sequence Tables
Win11找不到Internet Explore怎么办
Word怎么制作一张标准的答题卡?