在Ruby中有符号和无符号整数 [英] Signed and Unsigned Integers in Ruby
问题描述
与C一样,不红宝石已经签署和无符号整数,如果是的话那么确实有符号整数的String类回报平均长度的方法? (由于用C整数如果没有指定意味着签字)
Like C , does ruby have signed and unsigned integers and if it does then does that mean length method of String class return signed integer ? (Since in C integer if not specified implies signed)
推荐答案
红宝石实现了这样的方式的区别符号整数/无符号是不相关的,如红宝石整数自动伸入BIGNUM(任意长度的整数)时适用。
Ruby implements integers in such a way that the distinction signed/unsigned is irrelevant, as Ruby integers extend automatically into BigNum (arbitrary length integers) when applicable.
这有效地prevents整数溢出,这是恕我直言,最主要的原因,人们关心与固定大小的整数像C语言符号性。
This effectively prevents integer overflow, which is IMHO the main reason why people care about signedness in languages with fixed-size integers like C.
这篇关于在Ruby中有符号和无符号整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!