- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
XMFLOAT4X4 在矩阵定义中使用并内的并,但是当我尝试使用和不使用额外并的相同方法时,我会在访问模式中得到不同的结果。我不确定这是否是在 union 的初始化中,或者我在实现中可能会出错的地方。在我的代码中,单 union 不起作用,但现在在此代码中,双 union 不起作用。这是为什么?
#include <stdio.h>
typedef union{
union{
struct{float xx,xy,xz,xw, yx,yy,yz,yw, zx,zy,zz,zw, wx,wy,wz,ww;};
float m[4][4];
};
}Mat4DoubleUnion;
typedef union{
struct{float xx,xy,xz,xw, yx,yy,yz,yw, zx,zy,zz,zw, wx,wy,wz,ww;};
float m[4][4];
}Mat4SingleUnion;
int main(void){
Mat4SingleUnion mat_single_1 =
{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
Mat4SingleUnion mat_single_2 =
{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
Mat4DoubleUnion mat_double_1 =
{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
Mat4DoubleUnion mat_double_2 =
{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
Mat4DoubleUnion out_double;
Mat4SingleUnion out_single;
for(unsigned i = 0; i < 4; ++i){
for(unsigned j = 0; j < 4; ++j){
out_double.m[i][j] = mat_double_1.m[i][j] + mat_double_2.m[i][j];
out_single.m[i][j] = mat_single_1.m[i][j] + mat_single_2.m[i][j];
}
printf("Double Union\n");
for(unsigned i = 0; i < 4; ++i){
printf("[%f %f %f %f]\n", out_double.m[i][0], out_double.m[i][1], out_double.m[i][2], out_double.m[i][3]);
}
printf("\n");
printf("Single Union\n");
for(unsigned i = 0; i < 4; ++i){
printf("[%f %f %f %f]\n", out_single.m[i][0], out_single.m[i][1], out_single.m[i][2], out_single.m[i][3]);
}
printf("\n");
}
}
输出如下。您可以注意到整个循环过程中出现的大量数字,并且当您到达末尾时,两个矩阵的总和不是正确的输出。
Double Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 -170141183460469231731687303715884105728.000000 0.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
[304728612076653271699817077145600.000000 18030524136642386826155261952.000000 269154975309704986624.000000 73908519441581681410048.000000]
Single Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
Double Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 2.000000 0.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
[304728612076653271699817077145600.000000 18030524136642386826155261952.000000 269154975309704986624.000000 73908519441581681410048.000000]
Single Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 2.000000 0.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
Double Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 2.000000 0.000000 0.000000]
[0.000000 0.000000 2.000000 0.000000]
[304728612076653271699817077145600.000000 18030524136642386826155261952.000000 269154975309704986624.000000 73908519441581681410048.000000]
Single Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 2.000000 0.000000 0.000000]
[0.000000 0.000000 2.000000 0.000000]
[0.000000 0.000000 0.000000 0.000000]
Double Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 2.000000 0.000000 0.000000]
[0.000000 0.000000 2.000000 0.000000]
[0.000000 0.000000 0.000000 2.000000]
Single Union
[2.000000 0.000000 0.000000 0.000000]
[0.000000 2.000000 0.000000 0.000000]
[0.000000 0.000000 2.000000 0.000000]
[0.000000 0.000000 0.000000 2.000000]
最佳答案
尝试更改这两行。这是一个非常微妙的使用前启动问题。
Mat4DoubleUnion out_double; memset(&out_double, 0, sizeof(out_double));
Mat4SingleUnion out_single; memset(&out_single, 0, sizeof(out_single));
在每个外循环中,您只启动了一行 out_single 和 out_double,因此其余行都是垃圾。在最后一个外循环中,所有行均已正确启动,输出正确。我认为未启动的使用是未定义的行为,所以...
你可以尝试内存检查工具valgrind,在这种情况下会告诉很多信息:
valgrind --tool=memcheck ./a.out
关于c - 并内并和 splinter 矩阵加法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55055449/
我正在尝试将父 div 标记的最小宽度设置为内部所有子项的等效宽度。有办法吗? 例如, #sidebar{ width: 325px; } #content{ width: 500
我正在其中一个脚本中做一些附加操作,下面是一些简化的代码: foreach($entry in $arr){ ... switch($entry.AccessRights) { "GenericRea
float 在我的 Java/JOGL (OpenGL for Java) 程序中没有按预期计算。在绘制方法中,当调用每一帧(每秒 60 帧)时,我尝试修改对象的位置。所有值都是浮点值。 float
我正在尝试使用 C 中的结构为一个项目进行复杂的 vector 加法和点积。我已经编写了代码,但是,虽然它的编译没有问题,但一旦我运行我的程序,它就会停止工作。我还有该程序的其他部分,但这只是相关部分
这个问题已经有答案了: Use of java.math.MathContext (5 个回答) 已关闭 8 年前。 首先,我的搜索能力可能没有我希望的那么好,所以也许这种问题已经存在了。如果是的话请
PFB 说明问题的示例代码片段: var x=0.323; var cumulativeVal = 0; for(i=0;i<30;i++){
这个查询的每一步在 PostgreSQL 中的执行顺序是什么? SELECT SUM(field1)+SUM(field2)+SUM(field3)-SUM(field4); 据我所知,加法/减法是按
我正在尝试熟悉 Java 多线程应用程序。我试图想出一个可以很好地并行化的简单应用程序。我认为 vector 加法是一个很好的应用。但是,在我的 Linux 服务器(有 4 个内核)上运行时,我没有得
我在进行简单的加法并将值保存在变量中时遇到问题。 基本上我有以下代码: var accsen; var lowsev = parseInt(accsen); var hisev
所以我最近几个小时一直在解决一个问题,似乎无法阻止我的程序崩溃。问题是创建一个程序,该程序采用任意大小的矩阵,并且能够使用运算符重载将一个矩阵加到另一个矩阵上。当我尝试添加我类(class)的两个对象
我正在尝试添加以下内容,但它一直连接并返回一个字符串。 var nums = [1.99, 5.11, 2.99]; var total = 0; nums.forEach(f
我在网上搜索了数据仓库中加法、半加法和非加法度量之间的区别。我找到了一些结果,但我很难理解这些差异,因为它们不是一个例子。您能否通过示例向我更多地解释加法、半加法和非加法措施之间的区别。 最佳答案 T
%{control.current + #displayRows} 最终是我需要执行的语句。我将其放在 s:if 标记中,并使用 test 来查看该值是否在特定范围内。 最终,我得到的是字符串连接而不
请帮助我解释为什么下面的代码会得到奇怪的输出......为什么 getName() 得到 null。 输出: 列表检查:null:1 public class ListTest { public st
我需要通过字典生成校验和。键和值。 是否有任何简单的方法以迭代方式完成此任务。 foreach(dic.Keys 中的变量项) 校验和 += 校验和(dic[item]) + 校验和(item); 在
我想计算平均销售产品数量。表: pieces | date | status ------------------------------------------- 1
我正在尝试从 mysql 获取 INT 值并进行添加,最后更新数据库。不过这个好像没有更新?我该如何解决这个问题? $resultSecond = mysql_query("SELECT * FROM
我遇到了一个奇怪的问题。 有一张图片,我只需要重新计算非零像素。我想通过 numpy 来完成,因为我处理了数千张图像并且我需要它的速度。 这是一个维度较低的简化示例。 假设我有以下矩阵: [[0,
我不确定下一步该做什么。它们只是文本字段中的美元金额。我正在尝试将它们加在一起。 NSString *checkAmount = [checkAmountInput.text substringFro
我正在测试我的一些代码,在 javascript 中我添加了 .1+.2 ,它给了我 .30000000000000004 而不是 .3 。我不明白这一点。但是当我添加 .1+.3 时,它给了我 .4
我是一名优秀的程序员,十分优秀!