草庐IT

double-pointer

全部标签

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++ - 如何读取这些表达式 : *&pointer VS &*pointer

如果我有:intj=8;int*pointer=&j;那么如果我这样做:&*pointer==*&pointer返回1(true)。但是我对第二个表达有疑问:&*pointer返回指针指向的地址(首先计算*然后&)*&pointer返回指针地址,然后它指向什么......但这是变量而不是地址。所以这是我的疑问...... 最佳答案 &*pointer取消引用指针(下图中的1.)为您提供int对象(2.),然后获取地址该对象,当然与指针(1.)具有相同的值。┌─────────┐┌───┐│pointer┿━>│j│└────────

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

c++ - Valgrind 导致长 double 的数字问题

我的代码中有以下函数用于检查数字是否具有允许值(在对数空间中):templatestaticvoidcheck_if_normal(Tt){Tadditive_neutral_element=make_additive_neutral_element();//probabilityisallowedtobe0inlogspace//probabilityalsoisallowedtobe-infinlogspaceif(!std::isnormal(t)&&t!=0&&t!=additive_neutral_element)throwstd::underflow_error("Prob

c++ - 将 uint64_t 转换为 double 后出现意外结果

在下面的代码中:#include...uint64_tt1=1510763846;uint64_tt2=1510763847;doubled1=(double)t1;doubled2=(double)t2;//d1==t2=>evaluatestotruesomehow?//t1==d2=>evaluatestotruesomehow?//d1==d2=>evaluatestotruesomehow?//t1==t2=>evaluatestofalse,ofcourse.std::cout我得到这个输出:uint64_t:1510763846,1510763847,double:151

c++ - AVX中的6元素 double vector 矩阵 vector 相乘

我需要以double执行以下操作:数字表示值在内存中的存储方式。我想用AVX实现这个。如果我先将[QK]的列填充到8个元素,然后用[x]和[QK进行矩阵vector乘法,会不会更好?]后跟一个点积?编辑:好的,所以我决定实现一个带有填充vector的FLOAT32位版本,如下所示://PerformmatrixvectormultiplicationofQK*x//LoadfirstfourcolumnsQKinto4ymmregistersymm0=_mm256_load_ps((float*)(QK));ymm1=_mm256_load_ps((float*)(QK+8));ymm

c++ - 没有 typedef 的运算符 member_function_pointer_type()?

是否可以在不使用typedef的情况下创建一个operatormember_function_pointer_type()(即通过内联指定成员函数指针的类型)?例如,在实现SafeBoolIdiom时:classFoo{typedefvoid(Foo::*bool_type)()const;public:operatorbool_type()const;};是否可以在声明运算符时直接写出bool_type的类型?如果是,怎么办? 最佳答案 这似乎是唯一不能在不使用typedef的情况下声明(类型转换)operator的情况。如果它是