我当前忙于WebGL中的延期阴影,我需要将3个整数值(在[0..256] = 256^3)中解码为单个32位float并稍后对其进行编码.因为这是针对WebGL的,因此必须无需刻度操作即可完成.精度对我来说并不重要(但我认为可以实现). 这是我拥有的,但我认为这是错误的,因为我存储编码值的纹理的精度. float packColor(vec3 color) { return (color.r + (color.g*256.) + (color.b*256.*256.)) / (256.*256.*256.); } vec3 decodeColor(float f) { float b = floor(f * 256.0); float g = floor(f * 65536.0) - (b*256.); float r = (floor(f * 16777216.0) - (b*65536.)) - (g*256.); return vec3(r, g, b)/ 25
以下是关于 int 的编程技术问答
我是c编程的新手,我需要从两个.dat文件中获取图像,并比较它们是否相等.文件首先具有图像的数量,然后具有一些图像.如果所有图像都相同,我需要返回1个. .dat文件之一的图片: f1.dat 前20个表示20个"组"图像. 然后3 4意味着3x4矩阵,其余的是矩阵.与其他19个矩阵相同. 我需要去将第一个文件的第一个矩阵与另一个文件中的第一个文件进行比较. 这是我写的代码: #include #include struct irudia{ int w,h; unsigned char im[16][16]; }; int berdinak (struct irudia *im1, struct irudia *im2){ int berdin = 1; if ((im1->w != im2->w) || (im1->h != im2->h)){ return 0; } for (i
我正在学习pthreads.我的代码执行我想要的方式,我可以使用它.但这给了我有关汇编的警告. 我使用: 编译 gcc test.c -o test -pthread 使用GCC 4.8.1.我得到了警告 test.c: In function ‘main’: test.c:39:46: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] pthread_create(&(tid[i]), &attr, runner, (void *) i); ^ test.c: In function ‘runner’: test.c:54:22: warning: cast from pointer to integer of different size [-Wpoint
我最初有一个用于斐波那契变量数组的全局变量,但发现不允许.我需要进行基本的多线程并处理竞赛条件,但是我无法在Pthread Create中以void参数为feed int.我已经尝试使用一个恒定的指针而没有运气.由于某种奇怪的原因,void*通过了第一个布尔测试,但没有以下情况: $ gcc -o fibonacci fibonacci.c fibonacci.c:22:16: warning: comparison between pointer and integer ('void *' and 'int') else if (arg == 1) ~~~ ^ ~ 1 warning generated. 我的代码一团糟,我真的很困惑,因为我已经重写了很多次.如果我将所有ARG在我的线程运行函数中以INT的形式施加,我会得到一个分段故障11,这是有道理的.所有通过地址传递I索引的尝试都失败了,因为它是一个空白,无
在c中,我知道int main()返回int其中void main()不返回.除此之外,它们之间是否有区别?第一个比第二个好吗? 解决方案 绝大多数时间,int main(void)或int main(int argc, char* argv[])之一就是您需要使用的.特别是,如果您正在编写一个程序,该程序将由任何主要的编译器汇编,以便在个人计算机上运行,并拥有完整的C标准库,那么您几乎可以肯定需要从int返回int C6>. (我还会避免使用一个空参数列表,请参见" 为什么我们不在Main中使用(void)?") C99标准确实允许其他实施定义的签名,如果您阅读了编译器的手册,则可以使用这些签名,并且说您可以. (5.1.2.2.1)应使用int的返回类型定义,没有参数...或两个参数...或以其他实现定义的方式 就个人而言,即使它们是允许的(如果可能的话),我也会避免它们,因为如果您需要移植到另一个系统,这是另一件事. 请参阅下面的评论" 为
我在C ++中制作虚拟机,我遇到了这个错误, error: field has incomplete type 'int []' int instrarr[]; 我绝对不知道int阵列有什么问题.有人可以看一下,让我知道我做错了什么,我已经看了一个多小时了,我似乎找不到我必须遗漏的细节.我的整个文件都在下面,您需要参考. #include #include #include #include using namespace std; class vm { private: string finfo; string filedata; string fconv; string instruction; int instrarr[]; int zerocount[]; pub
我想将integer [] []转换为Vector>.经过大量的阅读,似乎没有人在网上留下可搜索的帖子,以了解这种性质.大量的int矢量可以倍增向量,arraylist to vector等.可悲的是,我还没有找到想要的东西.所以..你们中的任何一个人都知道适当的方法吗?我正在考虑将我的int[][]转换为字符串,然后将其转换为vector>.意见?这样的事情会有用.将我的数组转换为对象数组 Object[] a1d = { "Hello World", new Date(), Calendar.getInstance(), }; // Arrays.asList(Object[]) --> List List l = Arrays.asList(a1d); // Vector contstructor takes Collection // List is a subclass of Collection Vector
我想使用此ASCII代码初始化此Char Vector: vector a = { 201, 187, 200, 188, 205, 186 }; 我在所有6个字符中都会获得此语法错误: 从" int"到" char"的缩小转换无效:恒定值不适合目标类型 但是,当我初始化一个Char变量时,具有相同的ASCII代码: char b = 201; 它可以正常工作. 所以我意识到在向量中,由于某种原因,char类型可以在127之前接收int值.开始128语法错误出现. 这与正常变量不同,当char类型可以接收任何int值时. 我尝试将矢量声明为未签名的char,而语法错误则消失. vector a = { 201, 187, 200, 188, 205, 186 }; 但仍然, 为什么char类型向量无法接收与char类型变量相同的int数据? 我真的很感激有人解释我这种行为
我刚刚开始学习C ++,并对向量有疑问. 我正在阅读的书指出,如果我想提取双型矢量的大小(例如),我应该做类似的事情: vector::size_type vector_size; vector_size = myVector.size(); ,而在Java中,我可能会做 int vector_size; vector_size = myVector.size(); 我的问题是,为什么有一个名为vector :: size_type的类型? C ++为什么不只是使用INT? 解决方案 c ++是一种用于库写作*的语言,允许作者尽可能笼统地是其关键优势之一.与其规定使用任何特定数据类型的标准容器,不如说每个容器都会公开A size_type成员类型.这允许更大的灵活性和通用性.例如,考虑此通用代码: template Container, typename T> void doStuff(co
如何初始化C ++中的2维vector? 例如,我有4个阵列,每个长度为8个int,例如以下 int a1[] = {1,2,3,4,5,6,7,8}; int a2[] = {1,2,3,4,9,10,11,12}; int a3[] = {1,2,5,6,9,10,13,14}; int a4[] = {1,3,5,7,9,11,13,15}; 我有这个 vector > aa (4); aa[i] (a1,a1+8); ,但这给出了错误.我什至尝试将数组A1提供至V1并将V1传递给aa[i],但它仍然失败. 那么,初始化2维元素vector 的元素的正确方法是什么 解决方案 aa[i].assign(a1,a1+8); 其他解决方案 int arr[4][8] = { {1, 2, 3, 4, 5, 6, 7, 8}, {1, 2, 3, 4, 9, 10, 11,
信不信由你,当我搜索这个问题时,我想出了nada. 如何按"列"之一对int s的多维vector进行排序? 非常感谢! C ++ res = mysql_perform_query(conn, "SELECT column1, column2, column3 FROM table1;"); std::vector > myVector; while ((row = mysql_fetch_row(res)) !=NULL){ int rankedID = atoi(row[0]); std::vector tempRow; tempRow.push_back(atoi(row[0])); tempRow.push_back(atoi(row[1])); tempRow.push_back(atoi(row[2])); myVector.push_back(te
在这个问题P> for (vector::size_type ix = 0; ix ! = ivec.size(); ++ix) { ivec[ix] = 0; } 我知道为什么在这里不使用int,但是为什么不使用size_t? 在什么情况下我应该使用vector::size_type而不是size_t? 解决方案 使用size_type的主要时间在模板中.尽管std::vector::size_type通常是size_t,但some_other_container::size_type可能是其他类型,而是 1 .允许用户添加到std名称空间的几件事之一是某些用户定义类型的现有模板的专业化.因此,对于某些奇数size_t 而言,std::vector::size_type实际上可能是size_t以外的某种类型,即使标准库中定义的基本模板可能始终使用size_t. . 因此,如果要使用与该容器一起使用的模板内的特定容器的
Dim myarray(2) as Variant myarray(0)="3" myarray(1)="4" myarray(2)="5" myarray(3)="9" 我希望它成为 myarray(0)=3 myarray(1)=4 myarray(2)=5 myarray(3)=9 只有1行中没有循环的任何方法可以做到这一点? 这是针对excel2010. 我想要这样的东西,但它不起作用: intArray = Array.ConvertAll(stringArray , Function(str) Int32.Parse(str)) 解决方案 通过数组循环并单一转换值足够快.这是一个代码段,以显示转换循环相对于执行单元格I/O的速度速度: Private Const I_MAX = 10000 Private Const J_MAX = 200 Private Declare Function GetTickCount Lib "kerne
当我运行以下视觉基本代码时: Dim b As Double b = (2 ^ 16 - 1) * Math.Sqrt(Math.Sqrt((a / (2 ^ 8 - 1)))) (假设a是一个double,其值为15.0) 我对b的结果约为32,275. 但是,当我运行以下Java代码时,该代码应该与上述相同: double b; b = (2 ^ 16 - 1) * Math.sqrt(Math.sqrt((a / (2 ^ 8 - 1)))); 再次以a为15,我得到的结果截然不同:大约17. 都在求解此方程: 为什么这样?对于我正在做的事情,我正在寻找的视觉基本产量结果. 解决方案 ^是
我正在尝试获取当前的价值(示例.12)将其分配到变量(示例.今天= 12). DateFormat DateFormat= new SimpleDateFormat ("dd"); //get current day time with Date() Date day= new Date (); int day1 = Integer.valueOf(day); 或 DateFormat DateFormat= new SimpleDateFormat ("dd"); //get current day time with Date() Date day= new Date (); int day1 = day; 解决方案 String year1= String.valueOf (year); String month1= Stri
我是与Python和编程编程的新手 b=["hi","hello","howdy"] for i in b: print i #This code outputs: hi hello howdy 我该如何制作它,以便迭代变量是一个INT,因此以下方式起作用? b=["hi","hello","howdy"] for i in b: print i #I want it to output: 0 1 2 解决方案 Pythonic方法将与enumerate(): for index, item in enumerate(b): print index, item 也有range(len(b)),但是您几乎总是会在循环主体中检索item,因此enumerate()大多数时候是更好的选择: for index in range(len(b)): print index, b[index] 其他解决方案 b=["hi",
这是我的代码的一部分: private void button1_Click(object sender, EventArgs e) { int Chocolate = int.Parse(QtyChocolate.Text); TableUpdate("Chocolate", QtyChocolate.Text); int Vanilla = int.Parse(QtyVanilla.Text); TableUpate("Vanilla", QtyVanilla.Text); int Strawberry = int.Parse(QtyStrawberry.Text); TableUpate("Strawberry", QtyStrawberry.Text); int Melon = int.Parse(QtyMelon.Text); TableUpate("Melon", QtyMelon.Text); i