我想在Rails 3下创建一个bigint(或string任何不是int)类型的主键字段.
我有一个给定的数据结构,例如:
things
------
id bigint primary_key
name char(32)
Run Code Online (Sandbox Code Playgroud)
我目前正试图推动的方法:
create_table :things, :id => false do |t| # That prevents the creation of (id int) PK
t.integer :id, :limit => 8 # That makes the column type bigint
t.string :name, :limit => 32
t.primary_key :id # This is perfectly ignored :-(
end
Run Code Online (Sandbox Code Playgroud)
列类型是正确的,但主键选项不会出现在sqlite3中,我怀疑MySQL也是如此.
我将我的long值保存在SQL Server表中varbinary(max):
var savedValue = BitConverter.GetBytes(longValue);
Run Code Online (Sandbox Code Playgroud)
现在我需要在T-SQL查询中使用该值,但是当我尝试获取值时:
select cast(Value as bigint) from dbo.MyValues
Run Code Online (Sandbox Code Playgroud)
它返回不同的数值.例如,如果我-8588797048854775808在.NET中保存,在T-SQL中我得到了33802181122903688
请告诉我这是什么问题?有问题可以解决吗?
当我注意到语法检查结果警告无用的常量(1)时,我正在编写一个模块作为我的应用程序的一部分.这是为什么?
常量是1模块末尾的强制性,通常会被警告忽略,如下所示perldoc perldiag:
对于等于0或1的数值常量,不会发出此警告,因为它们通常用在类似的语句中
Run Code Online (Sandbox Code Playgroud)1 while sub_with_side_effects();
(可能有一个更好的来源.毕竟1在文件的最后是完全需要的,不要被警告.)
但是,即使对于几乎空的模块,也会产生警告use bigint.
package Foo;
use bigint;
1;
Run Code Online (Sandbox Code Playgroud)
对于这个简单的文件语法检查,会产生以下警告:
$> perl -Wc Foo.pm
Useless use of a constant (1) in void context at Foo.pm line 5.
Foo.pm syntax OK
Run Code Online (Sandbox Code Playgroud)
bigint除了在sqlite中输入长十六进制数字之外,我找不到任何引用和警告消息,但我认为这并没有真正解决我的问题.
我的Perl是Cygwin的v5.14.4,bigint是0.36.
我需要像BigIntegerJavascript 一样将字符串转换为bigint
例
var reqId = "78099864177253771992779766288266836166272662";
var result = parseInt(reqId);
document.write(result);
Run Code Online (Sandbox Code Playgroud)
由于JavaScript允许整数最多为2 ^ 53,因此结果值不匹配.
有没有办法克服这个问题?
在寻找BigInt库的过程中,我遇到了这篇文章: Microsoft Windows上的C或C++ BigInt库
接受的答案提到了GMP库,但其中一位评论者声称库不会非常优雅地出错,并且对生产代码不利.有没有人用这个库进行任何长期开发?有什么好的选择吗?提前致谢.
除了在CONVERT函数中包装我的文字之外,有没有办法指定我想要例如12345表示为BIGINT而不是INT?在C#中,我可以指定12345L,但我不知道T-SQL中的等效功能.
我正在使用浏览器内的Javascript,而不是NodeJS.我有两个Uint8Arrays ......
var d1 = new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255])
var d2 = new Uint8Array([255, 255, 255, 255, 237, 49, 56, 0])
Run Code Online (Sandbox Code Playgroud)
每个元素都有8个元素,整数在0到255之间.每个数组代表一个更大的数字.例如,第一个数组表示正整数
0xffffffff
Run Code Online (Sandbox Code Playgroud)
我的问题是如何将d1除以d2得到结果?我读到Javascript中一个整数的最大值是2 ^ 53,我相信它比我可以拥有的最大数字少.我不关心结果的对象类型是什么,但是Uint8Array很好.
我正在研究项目 Euler Problem 104的问题 n\xc2\xb0104并想用 javascript 来完成。
\n\n为了解决这个问题,我需要计算斐波那契序列的大值,但是这个序列产生的数字太大,无法用经典的 Number 处理,所以我使用最新版本的 javascript 支持的 BigInt。
\n\n一旦我将特定结果存储在 BigInt 中,我需要检查它的前 10 位和最后一位数字。
\n\n为了从 Number 中获取数字,我们通常会执行如下代码所示的操作,但是当数字变得非常大时,就会出现问题:
\n\nlet number = BigInt(123456789)\r\nconsole.log(number.toString())\r\nconsole.log(number.toString()[3]) // Result is fine\r\n\r\nlet bigNumber = BigInt(1234567891111111111111111111111111111)\r\nconsole.log(bigNumber.toString())\r\nconsole.log(bigNumber.toString()[30]) // unpredictable resultRun Code Online (Sandbox Code Playgroud)\r\n似乎“toString()”方法仅使用 Number 类型的精度(我相信是 2^53),因此我们很快就会失去 BigInt 数字最后一位数字的精度。问题是我找不到其他方法来提取这些数字。
\n\n编辑: \n我需要完美的精度,因为基本上我正在做的事情是:
\n\n计算斐波那契(500) = 280571172992510140037611932413038677189525
\n\n获取该数字的最后 10 位数字:8677189525(这是丢失精度的地方)
\n\n然后为了解决我的问题,我需要检查最后 10 位数字是否包含从 1 到 9 的所有数字
\n我目前正在对大量数字(最多 10M 位)进行素性测试。
现在,我正在使用带有 GMP 库的 ac 程序。我使用 OpenMP 进行了一些并行化,并获得了不错的加速(4 核时为 3.5~)。问题是我没有足够的 CPU 核心来运行我的整个数据集。
我有一个 NVidia GPU,并且我试图找到 GMP 的替代方案,但适用于 GPU。它可以是 CUDA 或 OpenCL。
是否有可以在我的 GPU 上运行的任意精度库?如果有一种简单或更优雅的方法,我也愿意使用另一种编程语言。
我有以下应该转换std::array<uint8_t>为BigIntie 的代码示例boost::multiprecision::cpp_int。我使用 MSYS2 中的 clang64 15.0.7 (\xd0\xa1++17) 编译此代码。代码工作正常并将 uint8_t 数组转换为 BigInt。
#include <string>\n#include <iostream>\n#include <boost/multiprecision/cpp_int.hpp>\n\nusing BigInt = boost::multiprecision::cpp_int;\n\nconst auto b = std::array<uint8_t, 16>{\n 0x11, 0x22, 0x33, 0x44,\n 0x11, 0x22, 0x33, 0x44,\n 0x11, 0x22, 0x33, 0x44,\n 0x11, 0x22, 0x33, 0x44\n};\n\nint main() {\n size_t shift = 0;\n auto initial = BigInt{};\n\n auto i = std::accumulate(\n b.cbegin(),\n b.cend(),\n initial,\n [&shift](const BigInt &acc, uint8_t it) {\n auto byte = BigInt{it};\n auto result = acc | (byte << …Run Code Online (Sandbox Code Playgroud) bigint ×10
javascript ×3
c++ ×2
sql-server ×2
t-sql ×2
arrays ×1
biginteger ×1
boost ×1
clang ×1
division ×1
gcc ×1
literals ×1
long-integer ×1
node.js ×1
perl ×1
perl-module ×1
perlsyn ×1
primary-key ×1
uint8array ×1