- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,所以我正在做一些图形数学并插入我认为是 float 的东西(我很确定我事先操纵 float 的方式不知何故搞砸了 ...)进入功能并得到奇怪的负面结果。
例如当 Angle 初始等于 350.0 时执行以下操作时,测试最终为
-.99。 为什么?
Angle= (float)(Angle-(int)Angle)+(float)((int)Angle%90);
// calculates x and y based on angle and Hypotenuse
float test= sin(Angle);
float test2= 1/(Speed*Time);
float test3= test/test2;
buffX= sin(Angle)/ (1.f/(Speed*Time));
buffY= sin(Angle-90)/ (1.f/(Speed*Time));
试图在一切都不起作用之前通过放置 (float) 来保持 Angle float ...请帮忙! 谢谢!
最佳答案
那是因为 C/C++ 运行时函数 sin()
需要以弧度而不是度数为单位的参数。
转换为弧度:
float test= sin(Angle / 180 * M_PI);
等等
关于c++ - cMath 和 sin 函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6368055/
我很困惑为什么这段代码没有包含就可以工作 "#include " 下面是我的代码,没有它也能正常工作。 // PowerApp.cpp : Defines the entry point for th
我编写了一个利用 Fast Light Toolkit 的小程序,但由于某种原因,在尝试访问 cmath header 中的函数时会生成编译器错误。 如错误::acos has not been de
所以我最近在尝试涉及浮点运算的问题。下面是该代码的一个片段。 #include #include typedef unsigned long long ull; int main(){ lon
我正在用 clang 编译我的项目,但我遇到了一个奇怪的错误: [ 1%] Building CXX object CMakeFiles/tfs.dir/src/actions.cpp.o In fi
嘿伙计们(还有姑娘们),我正在做我的家庭作业,除了我不知道如何使用 cmath 库中的函数之一将两个方程合并为一个之外,我已经完成了大部分。我将复制并粘贴作业说明,然后是我的代码和我遇到困难的部分。粗
我可以使用 C++ 中的任何方法(例如重载或模板化)来允许我将类实例作为参数传递给 cmath 函数吗?例如,如果我有一个名为 “Point” 的类(如下所示),有什么方法可以执行操作 std::ab
嘿,所以我设法在我编码的一些图形数学中找到了问题,显然当我到达这行代码时:float test3= asin(test2); where test2= 0.017409846。 根据我的理解,“asi
我的问题是:有没有办法在提供单精度或 double 参数时始终使用数学函数的扩展精度版本 - 例如 sqrt、exp 和 &c - 而无需使用显式转换? 例如我想要这个功能,没有转换的麻烦: floa
我正在尝试使用 GLM 与 Vulkan/SDL 配合使用。我这两个都工作正常,但是当我选择构建时,它说 /usr/include/c++/7.1.1/cmath:45: error: math.h:
如何在不使用 cmath 的情况下获取两个 double 类型输入的底数:如果第一个输入为负但不适用于不确定哪里出错的正整数,这就是它的工作原理?任何见解表示赞赏..谢谢 int main() {
数学函数的命名空间是什么?全局还是 std? 考虑 cos功能。它有 3 个重载。但也有来自 math.h 的遗留 cos。 C 对函数重载一无所知。因此 cos(x) 无法解析为 cos(float
我想创建一个映射,其键是作为字符串的函数名称,值是函数本身。所以像这样... #include #include #include #include typedef std::function
给定以下用户定义的类型 S,它具有到 double 的转换函数: struct S { operator double() { return 1.0;} }; 以及以下对 cmath 的调用使用
以下程序编译正确: #include int main(int argc, char *argv[]) { return int(log(23.f)); } (在带有标志 -std=c++1
我曾经使用 math.h 没有任何问题。现在,我使用一个外部库,它本身有一个名为 math.h 的文件。 ,但其中包括 . 将此库添加到我的项目中(或者甚至只是添加包含目录,而不涉及代码)现在会从
我得到了名为 y0 的变量并包含 cmath,当使用不带任何参数的 g++ 编译它时,出现编译错误 错误:“double(double) throw ()”和“double”类型的操作数对二进制“op
我正在尝试学习 C++,并且正在使用 MS Visual Studio 2019。我有以下代码: #include int main() { std::cout 的 header 标题。
我使用 ppa:deadsnakes/ppa 存储库在 ubuntu 上安装了 python3.7。 当我尝试运行时 import cmath 在 python shell 中失败并显示消息: Mod
嘿,所以我正在做一些图形数学并插入我认为是 float 的东西(我很确定我事先操纵 float 的方式不知何故搞砸了 ...)进入功能并得到奇怪的负面结果。 例如当 Angle 初始等于 350.0
我正在使用 OpenGL ES 2 创建一个 iPhone 应用程序,它同时使用 objective-c 和 c++。其中有一个用于定义一些 vector 属性的头文件,该文件包含导致错误的cmath
我是一名优秀的程序员,十分优秀!