草庐IT

integer-math

全部标签

c++ - 未解析的外部符号 "private: static int Math::result"

这个问题在这里已经有了答案:Whatisanundefinedreference/unresolvedexternalsymbolerrorandhowdoIfixit?(38个答案)关闭8年前。这是我的类定义:#includeusingnamespacestd;classMath{private:staticintresult;public:staticintadd(inta,intb){result=a+b;returnresult;};};这是主要的:#include#include"Amin.cpp"usingnamespacestd;intmain(){Math::add(2

c++ - 根据 value_type 调用适当的构造函数 : integer or float

我有一个函数,它使用均匀分布将最小值和最大值之间的随机值填充到容器中。#include#include#include#includetemplatevoiduniform_random(TContainer&container,consttypenameTContainer::value_typemin,consttypenameTContainer::value_typemax){std::random_devicerd;std::mt19937gen(rd());//Belowlinedoesnotworkwithintegerscontainerstd::uniform_rea

c++ - 在常数值上强制 Clang 为 "perform math early"

这与Howtoforceconstpropagationthroughaninlinefunction?有关Clang有一个集成的汇编程序;而且它不使用系统的汇编程序(通常是GNUAS(GAS))。非Clang早期执行了数学运算,一切都“正常工作”。我说“早”是因为@n.m。反对将其描述为“预处理器执行的数学运算”。但是这个想法是这个值在编译时是已知的,应该尽早评估它,就像预处理器评估#if(X%32==0)时一样。.下面,Clang3.6提示违反了约束。似乎常量没有在整个过程中传播:$exportCXX=/usr/local/bin/clang++$$CXX--versionclan

c++ - libpng 错误 : PNG unsigned integer out of range

当尝试从内存中读取PNG时,我遇到了这个奇怪的错误:libpngerror::PNGunsignedintegeroutofrange这个错误是由引起的png_read_info(png_ptr,info_ptr);它使用以下处理程序:staticvoidReadDataFromBuffer(png_structppng_ptr,png_bytepoutBytes,png_size_tbyteCountToRead){PNGDataPtrdataptr=(PNGDataPtr)png_get_io_ptr(png_ptr);png_uint_32i;coutlenpdataptr->l

c++ - 2 个重载具有相似的转换 - 内置运算符 integer[pointer-to-object]

我有以下类(class):classDictionaryRef{public:operatorbool()const;std::stringconst&operator[](std::stringconst&name)const;//...};然后我尝试使用它:DictionaryRefref=...;ref["asdf"];//error输出提示两个重载,但只列出一个:1>...:errorC2666:'DictionaryRef::operator[]':2overloadshavesimilarconversions1>...:couldbe'conststd::string&D

c++ - 预处理器 "invalid integer constant expression"比较 int 和 double

在我的代码中的某处,我有预处理器定义#defineZOOM_FACTOR1我在另一个地方#ifdefZOOM_FACTOR#if(ZOOM_FACTOR==1)#defineFONT_SIZE8#else#defineFONT_SIZE12#endif#else#defineFONT_SIZE8#endif问题是当我将ZOOM_FACTOR值更改为float值时,例如1.5,出现编译错误C1017:无效的整数常量表达式。有谁知道我为什么会收到这个错误,有没有办法在预处理器指令中比较integer和floatingpointnumber? 最佳答案

c++ - boost::math::erf的算法

boosterf函数背后的算法是否有任何可用的详细信息?该模块的文档不是很精确。我发现的只是几种方法混合在一起。对我来说,它看起来像是Abramowitz和Stegun的变体。混合了哪些方法?这些方法是如何混合的?erf函数(常数时间)的复杂度是多少?塞巴斯蒂安 最佳答案 BoostMathToolkit的文档有一长串references,其中包括Abramowitz和Stegun。erf-function接口(interface)包含一个policy可用于控制数值精度(及其运行时复杂性)的模板参数。#includenamespac

c++ - 如何仅使用 math.h 将字符串转换为 double

我正在尝试将字符串转换为double字符串,但由于我正在处理Windowsnative应用程序(如仅链接到ntdll.dll),所以我没有大部分可用的标准库。我可以在math.h中使用基本的FP支持,但基本上就是这样。如何将字符串转换为最接近该字符串中表示的有理数的double? 最佳答案 如果你真的想得到最近的,这个问题就很难了,你需要任意精度的算法来实现这个结果。参见ftp://ftp.ccs.neu.edu/pub/people/will/howtoread.ps例如。 关于c++

c++ - 使用 libpcl_surface 在 boost::math::lanczos 中调试段错误

仅当我在使用调试标志编译的代码上使用gdb进行调试时,才会出现以下错误ProgramreceivedsignalSIGSEGV,Segmentationfault.0x00007fffc79a7ff0inboost::math::lanczos::lanczos_initializer::init::init()()from/usr/lib/libpcl_surface.so.1.7操作系统:unbutu14.04我有最新的pcl库(1.7Sprikelhof)和boost库(1.54)请注意,在gdb外部运行时不会出现段错误。 最佳答案

c++ - 可变参数模板 : Perfect forwarding of integer parameter to lambda

有类似的问题,但我没有找到适合我的问题的答案。考虑以下代码:#include#include#include#include#includeclassTestClass{public:TestClass(intvalue):mValue(value){}private:intmValue;};templateclassDeferredCreator{public:templateDeferredCreator(Args&&...args):mpCreator([=]()->T*{returnnewT(std::forward(args)...);}),mpObject(){}T*get