Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
4
Task/Integer-overflow/ALGOL-68/integer-overflow-1.alg
Normal file
4
Task/Integer-overflow/ALGOL-68/integer-overflow-1.alg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
BEGIN
|
||||
print (max int);
|
||||
print (1+max int)
|
||||
END
|
||||
4
Task/Integer-overflow/ALGOL-68/integer-overflow-2.alg
Normal file
4
Task/Integer-overflow/ALGOL-68/integer-overflow-2.alg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
BEGIN
|
||||
print (long max int);
|
||||
print (1+ long max int)
|
||||
END
|
||||
|
|
@ -43,9 +43,9 @@ begin
|
|||
P_UB; P_SB; P_UW; P_Th; P_SD; P_Cr;
|
||||
New_Line;
|
||||
|
||||
Put_Line("Forcing a variable to overflow:");
|
||||
Put_Line("Forcing a variable of type Crazy to overflow:");
|
||||
loop -- endless loop
|
||||
Put(" " & Crazy'Image(A) & "+1");
|
||||
A := A + 1;
|
||||
A := A + 1; -- line 49 -- this will later raise a CONSTRAINT_ERROR
|
||||
end loop;
|
||||
end Overflow;
|
||||
|
|
|
|||
5
Task/Integer-overflow/Befunge/integer-overflow.bf
Normal file
5
Task/Integer-overflow/Befunge/integer-overflow.bf
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"a9jc>"*:*+*+:0\- "(-",,:.048*"="99")1 -" >:#,_$v
|
||||
v,,,9"="*84 .: ,,"+"*84 .: **:*" }}" ,+55 .-\0-1<
|
||||
>:+. 55+, ::0\- :. 48*"-",, \:. 48*"="9,,, -. 55v
|
||||
v.*: ,,,,,999"="*84 .: ,,"*"*84 .: *+8*7"s9" ,+<
|
||||
>55+, 0\- "(",:.048*"="99"1-/)1 -">:#,_$ 1-01-/.@
|
||||
35
Task/Integer-overflow/C++/integer-overflow.cpp
Normal file
35
Task/Integer-overflow/C++/integer-overflow.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <iostream>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
std::cout << std::boolalpha
|
||||
<< std::numeric_limits<std::int32_t>::is_modulo << '\n'
|
||||
<< std::numeric_limits<std::uint32_t>::is_modulo << '\n' // always true
|
||||
<< std::numeric_limits<std::int64_t>::is_modulo << '\n'
|
||||
<< std::numeric_limits<std::uint64_t>::is_modulo << '\n' // always true
|
||||
<< "Signed 32-bit:\n"
|
||||
<< -(-2147483647-1) << '\n'
|
||||
<< 2000000000 + 2000000000 << '\n'
|
||||
<< -2147483647 - 2147483647 << '\n'
|
||||
<< 46341 * 46341 << '\n'
|
||||
<< (-2147483647-1) / -1 << '\n'
|
||||
<< "Signed 64-bit:\n"
|
||||
<< -(-9223372036854775807-1) << '\n'
|
||||
<< 5000000000000000000+5000000000000000000 << '\n'
|
||||
<< -9223372036854775807 - 9223372036854775807 << '\n'
|
||||
<< 3037000500 * 3037000500 << '\n'
|
||||
<< (-9223372036854775807-1) / -1 << '\n'
|
||||
<< "Unsigned 32-bit:\n"
|
||||
<< -4294967295U << '\n'
|
||||
<< 3000000000U + 3000000000U << '\n'
|
||||
<< 2147483647U - 4294967295U << '\n'
|
||||
<< 65537U * 65537U << '\n'
|
||||
<< "Unsigned 64-bit:\n"
|
||||
<< -18446744073709551615LU << '\n'
|
||||
<< 10000000000000000000LU + 10000000000000000000LU << '\n'
|
||||
<< 9223372036854775807LU - 18446744073709551615LU << '\n'
|
||||
<< 4294967296LU * 4294967296LU << '\n';
|
||||
return 0;
|
||||
}
|
||||
8
Task/Integer-overflow/Julia/integer-overflow-1.julia
Normal file
8
Task/Integer-overflow/Julia/integer-overflow-1.julia
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
s = subtypes(Signed)
|
||||
u = subtypes(Unsigned)
|
||||
|
||||
println("Integer Type Limits")
|
||||
for i in 1:length(s)
|
||||
println(s[i], " [", typemin(s[i]), ", ", typemax(s[i]), "]")
|
||||
println(u[i], " [", typemin(u[i]), ", ", typemax(u[i]), "]")
|
||||
end
|
||||
5
Task/Integer-overflow/Julia/integer-overflow-2.julia
Normal file
5
Task/Integer-overflow/Julia/integer-overflow-2.julia
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
println("Add to typemax")
|
||||
for t in s
|
||||
over = typemax(t) + 1
|
||||
println(t, " => ", over, " (", typeof(over), ")")
|
||||
end
|
||||
2
Task/Integer-overflow/Mathematica/integer-overflow.math
Normal file
2
Task/Integer-overflow/Mathematica/integer-overflow.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$MaxNumber +
|
||||
10^-15.954589770191003298111788092733772206160314 $MaxNumber
|
||||
2
Task/Integer-overflow/PARI-GP/integer-overflow.pari
Normal file
2
Task/Integer-overflow/PARI-GP/integer-overflow.pari
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Vecsmall([1])
|
||||
Vecsmall([2^64])
|
||||
2
Task/Integer-overflow/Perl-6/integer-overflow.pl6
Normal file
2
Task/Integer-overflow/Perl-6/integer-overflow.pl6
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
my int64 ($a, $b, $c) = 9223372036854775807, 5000000000000000000, 3037000500;
|
||||
.say for -(-$a - 1), $b + $b, -$a - $a, $c * $c, (-$a - 1)/-1;
|
||||
56
Task/Integer-overflow/PureBasic/integer-overflow.purebasic
Normal file
56
Task/Integer-overflow/PureBasic/integer-overflow.purebasic
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#MAX_BYTE =127
|
||||
|
||||
#MAX_ASCII=255 ;=MAX_CHAR Ascii-Mode
|
||||
|
||||
CompilerIf #PB_Compiler_Unicode=1
|
||||
#MAX_CHAR =65535 ;Unicode-Mode
|
||||
CompilerElse
|
||||
#MAX_CHAR =255
|
||||
CompilerEndIf
|
||||
|
||||
#MAX_WORD =32767
|
||||
|
||||
#MAX_UNIC =65535
|
||||
|
||||
#MAX_LONG =2147483647
|
||||
|
||||
CompilerIf #PB_Compiler_Processor=#PB_Processor_x86
|
||||
#MAX_INT =2147483647 ;32-bit CPU
|
||||
CompilerElseIf #PB_Compiler_Processor=#PB_Processor_x64
|
||||
#MAX_INT =9223372036854775807 ;64-bit CPU
|
||||
CompilerEndIf
|
||||
|
||||
#MAX_QUAD =9223372036854775807
|
||||
|
||||
Macro say(Type,maxv,minv,sz)
|
||||
PrintN(Type+#TAB$+RSet(Str(minv),30,Chr(32))+#TAB$+RSet(Str(maxv),30,Chr(32))+#TAB$+RSet(Str(sz),6,Chr(32))+" Byte")
|
||||
EndMacro
|
||||
|
||||
OpenConsole()
|
||||
PrintN("TYPE"+#TAB$+RSet("MIN",30,Chr(32))+#TAB$+RSet("MAX",30,Chr(32))+#TAB$+RSet("SIZE",6,Chr(32)))
|
||||
|
||||
Define.b b1=#MAX_BYTE, b2=b1+1
|
||||
say("Byte",b1,b2,SizeOf(b1))
|
||||
|
||||
Define.a a1=#MAX_ASCII, a2=a1+1
|
||||
say("Ascii",a1,a2,SizeOf(a1))
|
||||
|
||||
Define.c c1=#MAX_CHAR, c2=c1+1
|
||||
say("Char",c1,c2,SizeOf(c1))
|
||||
|
||||
Define.w w1=#MAX_WORD, w2=w1+1
|
||||
say("Word",w1,w2,SizeOf(w1))
|
||||
|
||||
Define.u u1=#MAX_UNIC, u2=u1+1
|
||||
say("Unicode",u1,u2,SizeOf(u1))
|
||||
|
||||
Define.l l1=#MAX_LONG, l2=l1+1
|
||||
say("Long ",l1,l2,SizeOf(l1))
|
||||
|
||||
Define.i i1=#MAX_INT, i2=i1+1
|
||||
say("Int",i1,i2,SizeOf(i1))
|
||||
|
||||
Define.q q1=#MAX_QUAD, q2=q1+1
|
||||
say("Quad",q1,q2,SizeOf(q1))
|
||||
|
||||
Input()
|
||||
20
Task/Integer-overflow/Racket/integer-overflow.rkt
Normal file
20
Task/Integer-overflow/Racket/integer-overflow.rkt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#lang racket
|
||||
(require racket/unsafe/ops)
|
||||
|
||||
(fixnum? -1073741824) ;==> #t
|
||||
(fixnum? (- -1073741824)) ;==> #f
|
||||
|
||||
(- -1073741824) ;==> 1073741824
|
||||
(unsafe-fx- 0 -1073741824) ;==> -1073741824
|
||||
|
||||
(+ 1000000000 1000000000) ;==> 2000000000
|
||||
(unsafe-fx+ 1000000000 1000000000) ;==> -147483648
|
||||
|
||||
(- -1073741823 1073741823) ;==> -2147483646
|
||||
(unsafe-fx- -1073741823 1073741823) ;==> 2
|
||||
|
||||
(* 46341 46341) ;==> 2147488281
|
||||
(unsafe-fx* 46341 46341) ;==> 4633
|
||||
|
||||
(/ -1073741824 -1) ;==> 1073741824
|
||||
(unsafe-fxquotient -1073741824 -1) ;==> -1073741824
|
||||
Loading…
Add table
Add a link
Reference in a new issue