c++ - Multiplication is returning me incorrect values
问题描述
I am writing some code for an Arduino project I am working on, and the multiplication is returning me incorrect values, and I can't figure out why.
String calculateShutterSpeed(float fs, int i, int l){
float fstop = fs;
int iso = i;
int lux = l;
float c = 1.00;
float shutterspeedTop = 0;
double shutterspeedBottom = 0;
shutterspeedTop = pow(fs, 2)*c;
shutterspeedBottom = lux*iso;
shutterspeedBottom = shutterspeedBottom/shutterspeedTop;
The code giving me the error is the line where I multiply lux by iso, in some cases (with small numbers) it works fine, but as soon as I use larger numbers it starts giving me incorrect numbers, such as a lux of 4833 and iso of 200 will give me a result of -16440.
解决方案
推荐阅读
- mysql - MYSQL 一个表里面有几千个表。是否可行且有效?
- flutter - Flutter pub 获取错误 - easy_localization
- reactjs - 检查 React 组件是否从另一个组件抛出错误
- android - 如何从自定义绘画小部件更改为剪辑路径小部件?
- angular - 如何使用具有相对路径的 nginx 提供角度服务
- javascript - HTML input type="time" 只允许 15 分钟间隔
- xml - Saxon EE 10.3 XSLT 错误:无法创建其父节点是文档节点的属性节点 (id)
- docker - 无法在 Powershell 命令中创建 DockerFile
- java - 为集群项目生成随机坐标
- python - 基于具有多行的第二个列表附加到列表 python