小编yak*_*dbz的帖子

ieee754 浮点数 1/x * x > 1.0

我想知道下面定义的程序是否可以返回 1 假设:

  • IEEE754 浮点运算
  • 没有溢出(既不是 inmax/x也不是 in f*x
  • 没有 nan 或 inf(显然)
  • 0 < x 和 0 < n < 32
  • 没有不安全的数学优化
int canfail(int n, double x) {
    double max = 1ULL << n; // 2^n
    double f = max / x;
    return f * x > max;
}
Run Code Online (Sandbox Code Playgroud)

在我看来,它有时应该返回 1,因为roundToNearest(max / x)通常可以大于max/x。我能够找到相反情况下的数字 where f * x < max,但我没有显示的输入示例,f * x > max我不知道如何找到一个。有人可以帮忙吗?

编辑:如果在 10^(-6) 和 10^6 之间的范围内,我知道 …

c floating-point ieee-754

5
推荐指数
1
解决办法
286
查看次数

预期'struct matrix_t*'但参数的类型为'struct matrix_t*'?_?没有不同

main.c:78:25: erreur: assignment from incompatible pointer type [-Werror]
main.c:81:9: erreur: passing argument 2 of ‘matrix_multiply’ from incompatible pointer type [-Werror]
main.c:6:11: note: expected ‘struct matrix_t *’ but argument is of type ‘struct matrix_t *’
Run Code Online (Sandbox Code Playgroud)

第6行是matrix_multiply函数

这是我的代码,从第74行开始

matrix_t *m;
matrix_t *first = matrix_reader_next(reader);
matrix_t *previous = first;
while ( (m = matrix_reader_next(reader))) {
    previous->next = m;
    previous = m;
}
matrix_t *result = matrix_multiply(first,first->next);
Run Code Online (Sandbox Code Playgroud)

这是我的函数原型和结构

typedef struct {
   int **M;
   int nLi;
   int nCo;
   struct matrix_t *next;
} matrix_t;

matrix_t* matrix_multiply(matrix_t* …
Run Code Online (Sandbox Code Playgroud)

c struct types pointers

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×2

floating-point ×1

ieee-754 ×1

pointers ×1

struct ×1

types ×1