【问题标题】:invalid operands of types 'double' (__Attribute__((__cdecl__)) *)(double)' and 'int' to library 'operator*''double' 类型的无效操作数(__Attribute__((__cdecl__)) *)(double)' 和 'int' 到库 'operator*'
【发布时间】:2020-11-03 18:20:57
【问题描述】:
if(maxmesafe[2]>0.0000001){
        d=(maxx[0]*(maxy[1]-maxy[2])+maxx[1]*(maxy[2]-maxy[0])+maxx[2]*(maxy[0]-maxy[1]))/2;
        int x0=maxx[0]*maxx[0],x1=maxx[1]*maxx[1],x2=maxx[2]*maxx[2],y1=maxy[0]*maxy[0],y2=maxy[1]*maxy[1],y3=maxy[2]*maxy[2];
        newx+=((x0+y0)*(maxy[1]-maxy[2])+(x1+y1)*([maxy[2]-maxy[0]))/d;
        newy+=((x0+y0))*(maxx[2]-maxx[1])+(x1+y1)*([maxx[0]-maxx[2])+(x2+y2)*([maxx[1]-maxx[0]))/d;
        ycap=(maxmesafe[0]*maxmesafe[1]*maxmesafe[2])/sqrt((maxmesafe[0]+maxmesafe[1]+maxmesafe[2])*(-maxmesafe[0]+maxmesafe[1]+maxmesafe[2])*(maxmesafe[0]-maxmesafe[1]+maxmesafe[2])*(maxmesafe[0]+maxmesafe[1]-maxmesafe[2]));
    }

我对库 'operator' 错误。

newx、newy、d 和 ycap 值是浮点变量

【问题讨论】:

    标签: c


    【解决方案1】:

    手册页中的 sqrt 定义:

    #include <math.h>
    double sqrt(double x);
    float sqrtf(float x);
    long double sqrtl(long double x);
    

    所以你应该将 sqrt 参数转换为 double 或使用 double 变量:

    sqrt((double)((maxmesafe[0]+maxmesafe[1]+maxmesafe[2])*(-maxmesafe[0]+maxmesafe[1]+maxmesafe[2])*(maxmesafe[0]-maxmesafe[1]+maxmesafe[2])*(maxmesafe[0]+maxmesafe[1]-maxmesafe[2])))
    

    PS:尽量缩进你的代码,甚至内联指令更易读。最好是每行不超过 80 个字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-23
      • 1970-01-01
      相关资源
      最近更新 更多