summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/posix/posix_other.nim2
-rw-r--r--lib/pure/rationals.nim11
-rw-r--r--lib/system.nim12
3 files changed, 21 insertions, 4 deletions
diff --git a/lib/posix/posix_other.nim b/lib/posix/posix_other.nim
index e552bf807..01bc1c1e5 100644
--- a/lib/posix/posix_other.nim
+++ b/lib/posix/posix_other.nim
@@ -34,7 +34,7 @@ type
 {.deprecated: [TSocketHandle: SocketHandle].}
 
 type
-  Time* {.importc: "time_t", header: "<time.h>".} = distinct int
+  Time* {.importc: "time_t", header: "<time.h>".} = distinct clong
 
   Timespec* {.importc: "struct timespec",
                header: "<time.h>", final, pure.} = object ## struct timespec
diff --git a/lib/pure/rationals.nim b/lib/pure/rationals.nim
index 7fb24c26f..7907b4e6c 100644
--- a/lib/pure/rationals.nim
+++ b/lib/pure/rationals.nim
@@ -39,7 +39,7 @@ proc toRational*[T:SomeInteger](x: T): Rational[T] =
   result.num = x
   result.den = 1
 
-proc toRational*(x: float, n: int = high(int32)): Rational[int] =
+proc toRational*(x: float, n: int = high(int) shr (sizeof(int) div 2 * 8)): Rational[int] =
   ## Calculates the best rational numerator and denominator
   ## that approximates to `x`, where the denominator is
   ## smaller than `n` (default is the largest possible
@@ -323,8 +323,13 @@ when isMainModule:
   assert abs(toFloat(y) - 0.4814814814814815) < 1.0e-7
   assert toInt(z) == 0
 
-  assert toRational(0.98765432) == 2111111029 // 2137499919
-  assert toRational(PI) == 817696623 // 260280919
+  when sizeof(int) == 8:
+    assert toRational(0.98765432) == 2111111029 // 2137499919
+    assert toRational(PI) == 817696623 // 260280919
+  when sizeof(int) == 4:
+    assert toRational(0.98765432) == 80 // 81
+    assert toRational(PI) == 355 // 113
+
   assert toRational(0.1) == 1 // 10
   assert toRational(0.9) == 9 // 10
 
diff --git a/lib/system.nim b/lib/system.nim
index 85643891b..4d8610737 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -743,6 +743,18 @@ proc newSeqOfCap*[T](cap: Natural): seq[T] {.
   ## ``cap``.
   discard
 
+when not defined(JS):
+  proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] =
+    ## creates a new sequence of type ``seq[T]`` with length ``len``.
+    ##
+    ## Only available for numbers types. Note that the sequence will be
+    ## uninitialized. After the creation of the sequence you should assign
+    ## entries to the sequence instead of adding them.
+
+    result = newSeqOfCap[T](len)
+    var s = cast[PGenericSeq](result)
+    s.len = len
+
 proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {.
   magic: "LengthOpenArray", noSideEffect.}
 proc len*(x: string): int {.magic: "LengthStr", noSideEffect.}
revision' href='/ahoang/Nim/blame/lib/parseopt.nim?h=devel&id=07d5a8085bbcc21a1d9d06a2976ecc00e9c8d55b'>^
11b695875 ^
bf9764e56 ^
d1f3512ab ^
972c51086 ^
d1f3512ab ^
11b695875 ^
485c37194 ^
972c51086 ^


11b695875 ^


d1f3512ab ^












11b695875 ^
d1f3512ab ^








11b695875 ^
d1f3512ab ^


11b695875 ^
d1f3512ab ^
11b695875 ^
896766ae2 ^
d1f3512ab ^












11b695875 ^
d1f3512ab ^







972c51086 ^
d1f3512ab ^




bf9764e56 ^
d1f3512ab ^

bf9764e56 ^
d1f3512ab ^

485c37194 ^
972c51086 ^
d1f3512ab ^

972c51086 ^
11b695875 ^
d1f3512ab ^


3f3dda5a7 ^
d1f3512ab ^
11b695875 ^


8098e2a42 ^
dd806cafa ^
11b695875 ^
8098e2a42 ^
11b695875 ^
8098e2a42 ^
11b695875 ^
8098e2a42 ^



d1f3512ab ^
8098e2a42 ^













972c51086 ^

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152