C:U64和uint64_t之间的差异(C: Difference between U64 and uint64_t)
我在使用Java几年后尝试学习C语言。 我发现了一些我想要重现的代码,看起来像这样:
U64 attack_table[...]; // ~840 KiB struct SMagic { U64* ptr; // pointer to attack_table for each particular square U64 mask; // to mask relevant squares of both lines (no outer squares) U64 magic; // magic 64-bit factor int shift; // shift right }; SMagic mBishopTbl[64]; SMagic mRookTbl[64]; U64 bishopAttacks(U64 occ, enumSquare sq) { U64* aptr = mBishopTbl[sq].ptr; occ &= mBishopTbl[sq].mask; occ *= mBishopTbl[sq].magic; occ >>= mBishopTbl[sq].shift; return aptr[occ]; } U64 rookAttacks(U64 occ, enumSquare sq) { U64* aptr = mRookTbl[sq].ptr; occ &= mRookTbl[sq].mask; occ *= mRookTbl[sq].magic; occ >>= mRookTbl[sq].shift; return aptr[occ]; }
代码并不重要,但我已经失败了使用相同的数据类型:
U64
,我只找到了uint64_t
。 现在我想知道U64
,uint64_t
和long
的区别在哪里。如果有人可以向我简要解释一下,包括每个人的优势,我感到非常高兴。
问候,芬兰人
I am trying to learn C after working with Java for a couple of years. I've found some code that I wanted to reproduce which looked something like this:
U64 attack_table[...]; // ~840 KiB struct SMagic { U64* ptr; // pointer to attack_table for each particular square U64 mask; // to mask relevant squares of both lines (no outer squares) U64 magic; // magic 64-bit factor int shift; // shift right }; SMagic mBishopTbl[64]; SMagic mRookTbl[64]; U64 bishopAttacks(U64 occ, enumSquare sq) { U64* aptr = mBishopTbl[sq].ptr; occ &= mBishopTbl[sq].mask; occ *= mBishopTbl[sq].magic; occ >>= mBishopTbl[sq].shift; return aptr[occ]; } U64 rookAttacks(U64 occ, enumSquare sq) { U64* aptr = mRookTbl[sq].ptr; occ &= mRookTbl[sq].mask; occ *= mRookTbl[sq].magic; occ >>= mRookTbl[sq].shift; return aptr[occ]; }
The code is not that important but I already failed at using the same datatype:
U64
, I only founduint64_t
. Now I would like to know where the difference inU64
,uint64_t
andlong
is.I am very happy if someone could briefly explain this one to me, including the advantage of each of them.
Greetings, Finn
原文:https://stackoverflow.com/questions/50556046
最满意答案
首先,你不需要在a,b,c上使用parseInt(),因为它们已经是整数。 再次count是一个整数,而你将它与字符串进行比较。 这应该工作。
if(count == 8) { if ((a > b ) && (a > c)) { alert("A is Highest"); } else if ((b > a ) && (b > c)) { alert("B is Highest"); } else { alert("C is highest!"); }
Firstly you do not need to use parseInt() on a, b, c as they are already integers. And again count is an integer while you are comparing it to a string. This should work.
if(count == 8) { if ((a > b ) && (a > c)) { alert("A is Highest"); } else if ((b > a ) && (b > c)) { alert("B is Highest"); } else { alert("C is highest!"); }
相关问答
更多-
MySQL如何从下表中为每对值选择最高值?(MySQL how do I select only highest for each pair values from the following table?)[2022-09-04]
select farm_id, gate_id, max(score) from table group by farm_id, gate_id ? select farm_id, gate_id, max(score) from table group by farm_id, gate_id ? -
如果列类型为TEXT,则默认排序行为将数据视为字符串,因此按字母顺序(非数字)对它们进行排序。 将列类型更改为数字类型,它将正确排序。 If your column type is TEXT, the default sorting behavior treats the data as strings, and therefore sorts them alphabetically (not numerically). Change your column type to a number type, a ...
-
首先,你不需要在a,b,c上使用parseInt(),因为它们已经是整数。 再次count是一个整数,而你将它与字符串进行比较。 这应该工作。 if(count == 8) { if ((a > b ) && (a > c)) { alert("A is Highest"); } else if ((b > a ) && (b > c)) { alert("B is Highest"); } else { ...
-
如何按最高值分组(How to group by on a highest value)[2023-08-24]
您可以使用MAX聚合函数。 select country, max(value) value from countries group by country 查看实例 。 编辑:由于数据的性质,原始解决方案只是正确的。 我已从第一个查询中删除了ID,以更正错误。 这是另一个解决方案(基于@Juan Carlos Oropeza的工作 - 谢谢你)将返回ID并消除关系。 select min(x.id) id, x.country, x.value from ( select ... -
这将在Θ(n)时间内完成: $a = $b = $c = $d = null; foreach($array as $v) { if(!isset($a) || $v > $a) { $d = $c; $c = $b; $b = $a; $a = $v; }elseif(!isset($b) || $v > $b) { $d = $c; $c = $b; $b = $v; }elseif(!isset($c) || $v > $c) { ...
-
将这样一组条目放入一个列表中并对其进行排序是一种选择。 但33k元素是一个数字,其中排序的O(n * log(n))复杂性可能已经对性能产生了明显的影响。 一个应用是使用nr4bt已经提到的PriorityQueue(我在回答时写了这段代码)。 它基本上将所有元素插入到根据映射条目的值排序的PriorityQueue中。 import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java ...
-
首先,输出到变量。 这是通过ob_start()和ob_get_clean()来解决的,它将所有输出放到缓冲区而不是屏幕并将缓冲区返回给变量。 然后比较两个变量并回显最高值: ob_start(); listingpress_property_area(); $a = ob_get_clean(); ob_start(); listingpress_property_areautil(); $b = ob_get_clean(); echo max($a, $b); First, get output ...
-
您可以从查询中进行选择。 因此,从两个表中选择每个casenumber的最大时间戳并进行比较。 select from (select casenumber, max(timestamp) as maxt from search_history group by casenumber) sh join (select casenumber, max(timestamp) as maxt from parse_history group by casenumber) ph on sh.casenumbe ...
-
rsort($array); $top3 = array_reverse(array_slice($array, 0, 3)); rsort($array); $top3 = array_reverse(array_slice($array, 0, 3));
-
这是一个公式解决方案。 我使用了20行并提取了每列包含前5行的行 - 您可以根据需要扩展到尽可能多的行。 使用A1:B20中的数据在D1中使用此公式,使用CTRL + SHIFT + ENTER确认并复制到E1和向下两列: =IFERROR(INDEX(A$1:A$20,SMALL(IF(($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)),ROW(A$1:A$20)-ROW(A$1)+1),ROWS(D$1:D1))),"" ...