草庐IT

double-quoted

全部标签

c++ - 有没有办法将 double 隐式转换为 std::array<double,1>?

我有一个这样的模板类:templateclassFoo{Foo(std::array);}和一个函数func(Foof);我希望能够像这样调用函数和构造函数:func(1);Foof(1);代替func({1});Foof({1});有什么好的方法可以做到这一点吗?如果无法进行隐式转换,可以1为Foo添加构造函数吗?仅案例? 最佳答案 double的隐式转换进入std::array不可能。这将需要为double重载转换运算符但这无法完成,因为您不能为内置类型重载运算符。你可以做的就是添加Foo(double);构造函数,然后使用st

c++ - C++中打印 double 的最大宽度

我想知道,使用fprintf打印的double最长的字符数是多少?我的猜测是错误的。提前致谢。 最佳答案 12有点低估了。在我的机器上,以下结果是一个317个字符长的字符串:#include#include#includeintmain(){doubled=-std::numeric_limits::max();charstr[2048]="";std::sprintf(str,"%f",d);std::size_tlength=std::strlen(str);}使用%e产生14个字符长的字符串。

C++ 将字符串转换为 double

我一整天都在努力寻找解决方案!您可能会将其标记为重新发布,但我真正想要的是不使用boost词法转换的解决方案。传统的C++方法会很棒。我试过这段代码,但它返回了一组乱码数字和字母。stringline;doublelineconverted;istringstreambuffer(line);lineconverted;buffer>>lineconverted;我也试过这个,但它总是返回0。stringstreamconvert(line);if(!(convert>>lineconverted)){lineconverted=0;}提前致谢:)编辑:对于我使用的第一个解决方案(乱码

c++ - 两个 double 可以同时相等和不相等吗?

我的程序中有一个非常奇怪的错误。我无法在可重现的代码中隔离错误,但在我的代码中的某个地方有:doubledistance,criticalDistance;...if(distance>criticalDistance){std::cout在调试构建中一切正常。只有一个分支被执行。但在发布构建中,一切都变得一团糟,有时两个分支都会被执行。这很奇怪,因为如果我添加else条件:if(distance>criticalDistance){std::cout这不会发生。请问这是什么原因造成的?我在32位计算机上的Ubuntu13.10上使用gcc4.8.1。编辑1:我正在使用预编译器标志-s

c++ - C/C++ 优化 : negate doubles fast

我需要快速否定大量的double。如果bit_generator生成0,则必须更改符号。如果bit_generator生成1,则什么也不会发生。循环运行多次,bit_generator速度极快。在我的平台上,案例2明显快于案例1。看起来我的CPU不喜欢分支。有没有更快和便携的方法来做到这一点?您如何看待案例3?//generates0and1intbit_generator();//bigvector(C++)vectorv;//case1for(size_ti=0;i编辑:添加了案例4和C-tag,因为vector可以是普通数组。因为我可以控制如何生成double,所以我重新设计了代

c++ - 浮点计算使用 float 的结果与使用 double 的结果不同

我有以下代码行。hero->onBeingHit(ENEMY_ATTACK_POINT*(1.0-hero->getDefensePercent()));voidonBeingHit(intdecHP)方法接受整数并更新健康点数。floatgetDefensePercent()方法是一个返回英雄防御百分比的getter方法。ENEMY_ATTACK_POINT是定义为#defineENEMY_ATTACK_POINT20的宏常数因子。假设hero->getDefensePercent()返回0.1。所以计算是20*(1.0-0.1)=20*(0.9)=18每当我尝试使用以下代码时(没有

c++ - 无法将 double [] [] 转换为 double **

我有一个带有3个参数的函数,第一个是**double。normalizeDataZeroMeanUnitSD(double**trainingActions,intnumberOfTrainingActions,intdescriptorDimension)当我从main调用它时,我尝试使用normalizeDataZeroMeanUnitSD(data,681,24);然而,我收到了cannotconvertparameter1from'double[681][24]'to'double**'这是我构建数据数组的方式:fstreaminfile;infile.open("gabor\

java - Spring @Value TypeMismatchException :Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

我想用@Value注解注入(inject)一个Double属性如:@ServicepublicclassMyService{@Value("${item.priceFactor}")privateDoublepriceFactor=0.1;//...并使用Spring属性占位符(属性文件):item.priceFactor=0.1我得到异常:org.springframework.beans.TypeMismatchException:Failedtoconvertvalueoftype'java.lang.String'torequiredtype'java.lang.Double'

java - Spring @Value TypeMismatchException :Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

我想用@Value注解注入(inject)一个Double属性如:@ServicepublicclassMyService{@Value("${item.priceFactor}")privateDoublepriceFactor=0.1;//...并使用Spring属性占位符(属性文件):item.priceFactor=0.1我得到异常:org.springframework.beans.TypeMismatchException:Failedtoconvertvalueoftype'java.lang.String'torequiredtype'java.lang.Double'

c++ (double)0.700 * int(1000) => 699(不是 double 问题)

使用g++(Ubuntu/Linaro4.6.3-1ubuntu5)4.6.3我尝试了scaledvalue2的不同类型转换,但直到我将乘法存储在double变量中,然后存储到int中,我才能得到期望的结果..但我无法解释为什么???我知道double(0.6999999999999999555910790149937383830547332763671875)是一个问题,但我不明白为什么一种方法可以,另一种不行??如果精度有问题,我预计两者都会失败。我不需要解决方案来修复它..但只是一个为什么??(问题已修复)voidmain(){doublevalue=0.7;intscaleFa