File: tcasts.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (26 lines) | stat: -rw-r--r-- 622 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import std/[strutils]
import std/[assertions, objectdollar]

# bug #19101
type
  Small = object
    a: int

  Big = object
    a, b, c, d: int

proc main =
  var
    n = 1'i8
    f = 2.0
    s = Small(a: 1)
    b = Big(a: 12345, b: 23456, c: 34567, d: 45678)

  doAssert $cast[int](f).toBin(64) == "0100000000000000000000000000000000000000000000000000000000000000"
  f = cast[float](n)
  doAssert $cast[int](f).toBin(64) == "0000000000000000000000000000000000000000000000000000000000000001"

  doAssert $b == "(a: 12345, b: 23456, c: 34567, d: 45678)"
  b = cast[Big](s)
  doAssert $b == "(a: 1, b: 0, c: 0, d: 0)"
main()