- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你好,
我在 Release模式下使用 Microsoft Visual C++ 2008 Express Edition 构建了我的项目。然而,我这里的一些浮点值与调试配置中的不同。出于某种原因,对于某些特定功能,它们都变成了 NaN 或零。我不确定为什么会这样,这是我第一次在 Release模式下构建任何帮助!
尝试的步骤:
浮点命令行选项。
由于一些原因,单步执行代码没有成功。
盯着代码看的时间感谢阅读!
这是行为不端的代码(注意:过去我在使用此特定功能时遇到过 NaN 问题,然而这很奇怪):
/*
This file is part of White - Storm: Lightning (alpha).
Copyright 2012 Christopher Augustus Greeley
White - Storm: Lightning (alpha) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
White - Storm: Lightning (alpha) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with White - Storm: Lightning (alpha). If not, see <http://www.gnu.org/licenses/>.
*/
#include "Vector Calculator.h"
WSL::Math::Vector::VectorCalculator::VectorCalculator()
{
WSL::Containers::Base::XYZ temp;
default_ = temp;
}
WSL::Containers::Base::XYZ WSL::Math::Vector::VectorCalculator::VectorCalculation( WSL::Containers::Base::XYZ goTo, WSL::Containers::Base::XYZ position, float speed, bool td )
{
//Make sure that the vector doesent have any stray values lying around.//
vector = default_;
//Calculate Magnitude.//
x = goTo.getX() - position.getX();
y = goTo.getY() - position.getY();
z = goTo.getZ() - position.getZ();
if( td == true )
magnitude = magn.DotProduct( x, y, z, magnitude );
else
magnitude = magn.DotProduct( x, y, magnitude );
if( x == 0 && y == 0 && z == 0 )
return vector;
//Normilise//
magnitude = sqrt( magnitude );
//Make sure we do not divide by zero.//
if( magnitude != 0 )
{
if( x != 0 )
x /= magnitude;
if( y != 0 )
y /= magnitude;
if( td == true )
if( z != 0 )
z /= magnitude;
}
//Go The Desired Speed.//
if( speed >=0 )
{
x *= speed;
y *= speed;
}
if( td == true )
z *= speed;
vector.setX( x );
vector.setY( y );
vector.setZ( z );
return vector;
}
inline float WSL::Math::Formulas::Dot::DotProduct( float x, float y, float mag )
{
return ( mag = ( ( x ) * ( x ) + ( y ) * ( y ) ) );
}
inline float WSL::Math::Formulas::Dot::DotProduct( float x, float y, float z, float mag )
{
return ( mag = ( ( x ) * ( x ) + ( y ) * ( y ) + ( z ) * ( z ) ) );
}
标题:
/*
This file is part of White - Storm: Lightning (alpha).
Copyright 2012 Christopher Augustus Greeley
White - Storm: Lightning (alpha) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
White - Storm: Lightning (alpha) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with White - Storm: Lightning (alpha). If not, see <http://www.gnu.org/licenses/>.
*/
#include "Int Bool.h"
namespace WSL
{
namespace Math
{
namespace Formulas
{
class Dot
{
public:
inline float DotProduct( float x, float y, float mag );
inline float DotProduct( float x, float y, float z, float mag );
};
}
namespace Vector
{
struct VectorCalculator
{
VectorCalculator();
WSL::Containers::Base::XYZ VectorCalculation( WSL::Containers::Base::XYZ goTo, WSL::Containers::Base::XYZ position, float speed, bool td );
WSL::Containers::Base::XYZ VectorCalculation( WSL::Containers::Base::XYZ goTo, WSL::Containers::Base::XYZ *position, float speed, bool td );
private:
WSL::Containers::Base::XYZ vector;
WSL::Containers::Base::XYZ default_;
float x, y, z, magnitude;
Math::Formulas::Dot magn;
};
}
}
}
对于上下文:
/*
This file is part of White - Storm: Lightning (alpha).
Copyright 2012 Christopher Augustus Greeley
White - Storm: Lightning (alpha) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
White - Storm: Lightning (alpha) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with White - Storm: Lightning (alpha). If not, see <http://www.gnu.org/licenses/>.
*/
#include "Include.h"
namespace WSL
{
namespace Containers
{
namespace Base
{
struct XYZB
{
inline float getX() { return X; }
inline float getY() { return Y; }
inline float getZ() { return Z; }
inline void setX( float Value ) { X = Value; }
inline void setY( float Value ) { Y = Value; }
inline void setZ( float Value ) { Z = Value; }
protected:
float X, Y, Z;
};
struct XYZ : public XYZB
{
public:
XYZ( float x, float y, float z )
{
X = x;
Y = y;
Z = z;
}
inline XYZ() { X = 0; Y = 0; Z = 0; }
};
}
}
}
这些文件存在问题:
/*
This file is part of White - Storm: Lightning (alpha).
Copyright 2012 Christopher Augustus Greeley
White - Storm: Lightning (alpha) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
White - Storm: Lightning (alpha) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with White - Storm: Lightning (alpha). If not, see <http://www.gnu.org/licenses/>.
*/
#include "Vector.h"
WSL::Containers::Math::Vector::Vector()
{
destinationInitialize = false;
threeDimentional = false;
}
WSL::Containers::Math::Vector::Vector( WSL::Containers::Base::XYZ position_ )
{
position = position_;
destinationInitialize = false;
threeDimentional = false;
}
WSL::Containers::Math::Vector::Vector( WSL::Containers::Base::XYZ position_, bool threeDimentional_ )
{
position = position_;
destinationInitialize = false;
threeDimentional = threeDimentional_;
}
float WSL::Containers::Math::Vector::GetDestinationX()
{
return destination.getX();
}
float WSL::Containers::Math::Vector::GetDestinationY()
{
return destination.getY();
}
float WSL::Containers::Math::Vector::GetDestinationZ()
{
return destination.getZ();
}
WSL::Containers::Base::XYZ WSL::Containers::Math::Vector::GetDestination()
{
return destination;
}
WSL::Containers::Base::XYZ WSL::Containers::Math::Vector::GetPosition()
{
return position;
}
float WSL::Containers::Math::Vector::GetX()
{
return position.getX();
}
float WSL::Containers::Math::Vector::GetY()
{
return position.getY();
}
float WSL::Containers::Math::Vector::GetZ()
{
return position.getZ();
}
void WSL::Containers::Math::Vector::SetThreeDimentional( bool value )
{
threeDimentional = value;
}
bool WSL::Containers::Math::Vector::GetThreeDimentional()
{
return threeDimentional;
}
void WSL::Containers::Math::Vector::CalculateVector()
{
vector = vectorCalculator.VectorCalculation( destination, position, speed, threeDimentional );
}
void WSL::Containers::Math::Vector::Move()
{
position.setX( position.getX() + vector.getX() );
position.setY( position.getY() + vector.getY() );
position.setZ( position.getZ() + vector.getZ() );
}
void WSL::Containers::Math::Vector::SetPosition( WSL::Containers::Base::XYZ position_ )
{
position = position_;
}
void WSL::Containers::Math::Vector::SetSpeed( float speed_ )
{
speed = speed_;
}
void WSL::Containers::Math::Vector::SetDestination( float x, float y )
{
destination.setX( x );
destination.setY( y );
if( destinationInitialize == false )
{
destinationInitialize = true;
destination.setZ( 0 );
}
}
void WSL::Containers::Math::Vector::SetDestination( float x, float y, float z )
{
destination.setX( x );
destination.setY( y );
destination.setZ( z );
}
void WSL::Containers::Math::Vector::SetDestination( WSL::Containers::Base::XYZ destination_ )
{
destination = destination_;
}
void WSL::Containers::Math::Vector::SetDestination( float allCoords )
{
destination.setX( allCoords );
destination.setY( allCoords );
destination.setZ( allCoords );
}
void WSL::Containers::Math::Vector::SetVector( WSL::Containers::Base::XYZ vector_ )
{
vector = vector_;
}
WSL::Containers::Base::XYZ WSL::Containers::Math::Vector::GetVector()
{
return vector;
}
float WSL::Containers::Math::Vector::GetSpeed()
{
return speed;
}
标题:
/*
This file is part of White - Storm: Lightning (alpha).
Copyright 2012 Christopher Augustus Greeley
White - Storm: Lightning (alpha) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
White - Storm: Lightning (alpha) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with White - Storm: Lightning (alpha). If not, see <http://www.gnu.org/licenses/>.
*/
#include "Engine.h"
namespace WSL
{
namespace Containers
{
namespace Math
{
class Vector
{
WSL::Math::Vector::VectorCalculator vectorCalculator;
WSL::Containers::Base::XYZ position;
WSL::Containers::Base::XYZ destination;
WSL::Containers::Base::XYZ vector;
bool destinationInitialize, threeDimentional;
float speed;
public:
Vector();
Vector( WSL::Containers::Base::XYZ position_ );
Vector( WSL::Containers::Base::XYZ position_, bool threeDimentional_ );
void CalculateVector();
bool GetThreeDimentional();
void Move();
void SetPosition( WSL::Containers::Base::XYZ position_ );
void SetDestination( float x, float y );
void SetDestination( float x, float y, float z );
void SetDestination( WSL::Containers::Base::XYZ destination_ );
void SetDestination( float allCoords );
void SetSpeed( float speed_ );
void SetThreeDimentional( bool value );
void SetVector( WSL::Containers::Base::XYZ vector_ );
float GetDestinationX();
float GetDestinationY();
float GetDestinationZ();
WSL::Containers::Base::XYZ GetDestination();
WSL::Containers::Base::XYZ GetPosition();
WSL::Containers::Base::XYZ GetVector();
float GetX();
float GetY();
float GetZ();
float GetSpeed();
};
}
}
}
最佳答案
好的。因此,正如我在评论中所写,我不知道您问题的答案,但也许我可以提供一些可以帮助您找到问题的指示。
我的第一个建议是将您的代码从 lua 上下文中取出并进行一个小的单元测试来调试它。如果 Release模式下的单元测试没有错误,那么您的问题出在其他地方。如果仍然存在错误,您也许可以找到您的代码中是否存在错误。如果您确定您的代码中没有错误,这里有一些提示
根据我的经验,当遇到 NaN、Zeros 或 INF 时,预计不会出现任何情况,并且输入或计算没有问题,那么您可能需要检查您或您使用的任何库是否更改了浮点标志任何方式(在 Windows 中,你使用 controlfp 或 control87,在 GCC 中,你有 FPU_SETCW FPU_GETCW 宏)不匹配的编译标志也会改变浮点计算的完成方式,可能会导致此类问题。确保使用相同的浮点标志编译所有库。
您可能还想更改检查 mag 是否不为零的方式。您总是会遇到接近零的浮点值的麻烦。如果您不知道 Bruce Dawson 关于比较 float 的文章,这里有一个指向最新版本的链接:http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
如果这些都没有帮助,您可能从 LUA 传递了错误的数字。
关于c++ - Visual C++ 2008 发布版本打破了我的花车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12809853/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!