Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
4
Task/Integer-overflow/Axe/integer-overflow.axe
Normal file
4
Task/Integer-overflow/Axe/integer-overflow.axe
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Disp -65535▶Dec,i
|
||||
Disp 40000+40000▶Dec,i
|
||||
Disp 32767-65535▶Dec,i
|
||||
Disp 257*257▶Dec,i
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
LDA ff
|
||||
ADD one
|
||||
|
||||
...
|
||||
|
||||
ff: 255
|
||||
one: 1
|
||||
48
Task/Integer-overflow/FreeBASIC/integer-overflow.freebasic
Normal file
48
Task/Integer-overflow/FreeBASIC/integer-overflow.freebasic
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
' The suffixes L, LL, UL and ULL are added to the numbers to make it
|
||||
' clear to the compiler that they are to be treated as:
|
||||
' signed 4 byte, signed 8 byte, unsigned 4 byte and unsigned 8 byte
|
||||
' integers, respectively.
|
||||
|
||||
' Integer types in FB are freely convertible to each other.
|
||||
' In general if the result of a computation would otherwise overflow
|
||||
' it is converted to a higher integer type.
|
||||
|
||||
' Consequently, although the calculations are the same as the C example,
|
||||
' the results for the 32-bit integers are arithmetically correct (and different
|
||||
' therefore from the C results) because they are converted to 8 byte integers.
|
||||
|
||||
' However, as 8 byte integers are the largest integral type, no higher conversions are
|
||||
' possible and so the results 'wrap round'. The 64-bit results are therefore the
|
||||
' same as the C examples except the one where the compiler warns that there is an overflow
|
||||
' which, frankly, I don't understand.
|
||||
|
||||
Print "Signed 32-bit:"
|
||||
Print -(-2147483647L-1L)
|
||||
Print 2000000000L + 2000000000L
|
||||
Print -2147483647L - 2147483647L
|
||||
Print 46341L * 46341L
|
||||
Print (-2147483647L-1L) \ -1L
|
||||
Print
|
||||
Print "Signed 64-bit:"
|
||||
Print -(-9223372036854775807LL-1LL)
|
||||
Print 5000000000000000000LL + 5000000000000000000LL
|
||||
Print -9223372036854775807LL - 9223372036854775807LL
|
||||
Print 3037000500LL * 3037000500LL
|
||||
Print (-9223372036854775807LL - 1LL) \ -1LL ' compiler warning : Overflow in constant conversion
|
||||
Print
|
||||
Print "Unsigned 32-bit:"
|
||||
Print -4294967295UL
|
||||
Print 3000000000UL + 3000000000UL
|
||||
Print 2147483647UL - 4294967295UL
|
||||
Print 65537UL * 65537UL
|
||||
Print
|
||||
Print "Unsigned 64-bit:"
|
||||
Print -18446744073709551615ULL ' compiler warning : Implicit conversion
|
||||
Print 10000000000000000000ULL + 10000000000000000000ULL
|
||||
Print 9223372036854775807ULL - 18446744073709551615ULL
|
||||
Print 4294967296ULL * 4294967296ULL
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
14
Task/Integer-overflow/Lingo/integer-overflow.lingo
Normal file
14
Task/Integer-overflow/Lingo/integer-overflow.lingo
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
put -(-2147483647-1)
|
||||
-- -2147483648
|
||||
|
||||
put 2000000000 + 2000000000
|
||||
-- -294967296
|
||||
|
||||
put -2147483647 - 2147483647
|
||||
-- 2
|
||||
|
||||
put 46341 * 46341
|
||||
-- -2147479015
|
||||
|
||||
put (-2147483647-1) / -1
|
||||
--> crashes Director (jeez!)
|
||||
1
Task/Integer-overflow/Phix/integer-overflow.phix
Normal file
1
Task/Integer-overflow/Phix/integer-overflow.phix
Normal file
|
|
@ -0,0 +1 @@
|
|||
integer i = 1000000000 + 1000000000
|
||||
2
Task/Integer-overflow/Sidef/integer-overflow.sidef
Normal file
2
Task/Integer-overflow/Sidef/integer-overflow.sidef
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var (a, b, c) = (9223372036854775807, 5000000000000000000, 3037000500);
|
||||
[-(-a - 1), b + b, -a - a, c * c, (-a - 1)/-1].each { say _ };
|
||||
52
Task/Integer-overflow/Swift/integer-overflow.swift
Normal file
52
Task/Integer-overflow/Swift/integer-overflow.swift
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// By default, all overflows in Swift result in a runtime exception, which is always fatal
|
||||
// However, you can opt-in to overflow behavior with the overflow operators and continue with wrong results
|
||||
|
||||
var int32:Int32
|
||||
var int64:Int64
|
||||
var uInt32:UInt32
|
||||
var uInt64:UInt64
|
||||
|
||||
println("signed 32-bit int:")
|
||||
int32 = -1 &* (-2147483647 - 1)
|
||||
println(int32)
|
||||
int32 = 2000000000 &+ 2000000000
|
||||
println(int32)
|
||||
int32 = -2147483647 &- 2147483647
|
||||
println(int32)
|
||||
int32 = 46341 &* 46341
|
||||
println(int32)
|
||||
int32 = (-2147483647-1) &/ -1
|
||||
println(int32)
|
||||
println()
|
||||
|
||||
println("signed 64-bit int:")
|
||||
int64 = -1 &* (-9223372036854775807 - 1)
|
||||
println(int64)
|
||||
int64 = 5000000000000000000&+5000000000000000000
|
||||
println(int64)
|
||||
int64 = -9223372036854775807 &- 9223372036854775807
|
||||
println(int64)
|
||||
int64 = 3037000500 &* 3037000500
|
||||
println(int64)
|
||||
int64 = (-9223372036854775807-1) &/ -1
|
||||
println(int64)
|
||||
println()
|
||||
|
||||
println("unsigned 32-bit int:")
|
||||
println("-4294967295 is caught as a compile time error")
|
||||
uInt32 = 3000000000 &+ 3000000000
|
||||
println(uInt32)
|
||||
uInt32 = 2147483647 &- 4294967295
|
||||
println(uInt32)
|
||||
uInt32 = 65537 &* 65537
|
||||
println(uInt32)
|
||||
println()
|
||||
|
||||
println("unsigned 64-bit int:")
|
||||
println("-18446744073709551615 is caught as a compile time error")
|
||||
uInt64 = 10000000000000000000 &+ 10000000000000000000
|
||||
println(uInt64)
|
||||
uInt64 = 9223372036854775807 &- 18446744073709551615
|
||||
println(uInt64)
|
||||
uInt64 = 4294967296 &* 4294967296
|
||||
println(uInt64)
|
||||
Loading…
Add table
Add a link
Reference in a new issue