Skip to content

Commit c4887e6

Browse files
author
Vijay Korapaty
committed
---
yaml --- r: 95439 b: refs/heads/dist-snap c: 5e1ccc6 h: refs/heads/master i: 95437: d10f7ec 95435: 632eed0 95431: c2e983d 95423: cec3a1f v: v3
1 parent f0136a7 commit c4887e6

File tree

7 files changed

+79
-41
lines changed

7 files changed

+79
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 1f279bf9ca835bf9b50c5c27098b4805ed7139e8
9+
refs/heads/dist-snap: 5e1ccc66e1f3f2ce7b3b21a1e380488edad32d65
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/num/num.rs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,26 @@ pub trait Orderable: Ord {
4242
fn clamp(&self, mn: &Self, mx: &Self) -> Self;
4343
}
4444

45+
/// Return the smaller number.
4546
#[inline(always)] pub fn min<T: Orderable>(x: T, y: T) -> T { x.min(&y) }
47+
/// Return the larger number.
4648
#[inline(always)] pub fn max<T: Orderable>(x: T, y: T) -> T { x.max(&y) }
49+
/// Returns the number constrained within the range `mn <= self <= mx`.
4750
#[inline(always)] pub fn clamp<T: Orderable>(value: T, mn: T, mx: T) -> T { value.clamp(&mn, &mx) }
4851

4952
pub trait Zero {
5053
fn zero() -> Self; // FIXME (#5527): This should be an associated constant
5154
fn is_zero(&self) -> bool;
5255
}
5356

57+
/// Returns `0` of appropriate type.
5458
#[inline(always)] pub fn zero<T: Zero>() -> T { Zero::zero() }
5559

5660
pub trait One {
5761
fn one() -> Self; // FIXME (#5527): This should be an associated constant
5862
}
5963

64+
/// Returns `1` of appropriate type.
6065
#[inline(always)] pub fn one<T: One>() -> T { One::one() }
6166

6267
pub trait Signed: Num
@@ -69,8 +74,26 @@ pub trait Signed: Num
6974
fn is_negative(&self) -> bool;
7075
}
7176

77+
/// Computes the absolute value.
78+
///
79+
/// For float, f32, and f64, `NaN` will be returned if the number is `NaN`
7280
#[inline(always)] pub fn abs<T: Signed>(value: T) -> T { value.abs() }
81+
/// The positive difference of two numbers.
82+
///
83+
/// Returns `zero` if the number is less than or equal to `other`,
84+
/// otherwise the difference between `self` and `other` is returned.
7385
#[inline(always)] pub fn abs_sub<T: Signed>(x: T, y: T) -> T { x.abs_sub(&y) }
86+
/// Returns the sign of the number.
87+
///
88+
/// For float, f32, f64:
89+
/// - `1.0` if the number is positive, `+0.0` or `infinity`
90+
/// - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
91+
/// - `NaN` if the number is `NaN`
92+
///
93+
/// For int:
94+
/// - `0` if the number is zero
95+
/// - `1` if the number is positive
96+
/// - `-1` if the number is negative
7497
#[inline(always)] pub fn signum<T: Signed>(value: T) -> T { value.signum() }
7598

7699
pub trait Unsigned: Num {}
@@ -106,7 +129,11 @@ pub trait Integer: Num
106129
fn is_odd(&self) -> bool;
107130
}
108131

132+
/// Calculates the Greatest Common Divisor (GCD) of the number and `other`.
133+
///
134+
/// The result is always positive.
109135
#[inline(always)] pub fn gcd<T: Integer>(x: T, y: T) -> T { x.gcd(&y) }
136+
/// Calculates the Lowest Common Multiple (LCM) of the number and `other`.
110137
#[inline(always)] pub fn lcm<T: Integer>(x: T, y: T) -> T { x.lcm(&y) }
111138

112139
pub trait Round {
@@ -132,10 +159,23 @@ pub trait Algebraic {
132159
fn hypot(&self, other: &Self) -> Self;
133160
}
134161

162+
/// Raise a number to a power.
163+
///
164+
/// # Example
165+
///
166+
/// ```rust
167+
/// let sixteen: float = num::pow(2.0, 4.0);
168+
/// assert_eq!(sixteen, 16.0);
169+
/// ```
135170
#[inline(always)] pub fn pow<T: Algebraic>(value: T, n: T) -> T { value.pow(&n) }
171+
/// Take the squre root of a number.
136172
#[inline(always)] pub fn sqrt<T: Algebraic>(value: T) -> T { value.sqrt() }
173+
/// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`.
137174
#[inline(always)] pub fn rsqrt<T: Algebraic>(value: T) -> T { value.rsqrt() }
175+
/// Take the cubic root of a number.
138176
#[inline(always)] pub fn cbrt<T: Algebraic>(value: T) -> T { value.cbrt() }
177+
/// Calculate the length of the hypotenuse of a right-angle triangle given legs of length `x` and
178+
/// `y`.
139179
#[inline(always)] pub fn hypot<T: Algebraic>(x: T, y: T) -> T { x.hypot(&y) }
140180

141181
pub trait Trigonometric {
@@ -151,15 +191,23 @@ pub trait Trigonometric {
151191
fn sin_cos(&self) -> (Self, Self);
152192
}
153193

194+
/// Sine function.
154195
#[inline(always)] pub fn sin<T: Trigonometric>(value: T) -> T { value.sin() }
196+
/// Cosine function.
155197
#[inline(always)] pub fn cos<T: Trigonometric>(value: T) -> T { value.cos() }
198+
/// Tangent function.
156199
#[inline(always)] pub fn tan<T: Trigonometric>(value: T) -> T { value.tan() }
157200

201+
/// Compute the arcsine of the number.
158202
#[inline(always)] pub fn asin<T: Trigonometric>(value: T) -> T { value.asin() }
203+
/// Compute the arccosine of the number.
159204
#[inline(always)] pub fn acos<T: Trigonometric>(value: T) -> T { value.acos() }
205+
/// Compute the arctangent of the number.
160206
#[inline(always)] pub fn atan<T: Trigonometric>(value: T) -> T { value.atan() }
161207

208+
/// Compute the arctangent with 2 arguments.
162209
#[inline(always)] pub fn atan2<T: Trigonometric>(x: T, y: T) -> T { x.atan2(&y) }
210+
/// Simultaneously computes the sine and cosine of the number.
163211
#[inline(always)] pub fn sin_cos<T: Trigonometric>(value: T) -> (T, T) { value.sin_cos() }
164212

165213
pub trait Exponential {
@@ -172,12 +220,18 @@ pub trait Exponential {
172220
fn log10(&self) -> Self;
173221
}
174222

223+
/// Returns `e^(value)`, (the exponential function).
175224
#[inline(always)] pub fn exp<T: Exponential>(value: T) -> T { value.exp() }
225+
/// Returns 2 raised to the power of the number, `2^(value)`.
176226
#[inline(always)] pub fn exp2<T: Exponential>(value: T) -> T { value.exp2() }
177227

228+
/// Returns the natural logarithm of the number.
178229
#[inline(always)] pub fn ln<T: Exponential>(value: T) -> T { value.ln() }
230+
/// Returns the logarithm of the number with respect to an arbitrary base.
179231
#[inline(always)] pub fn log<T: Exponential>(value: T, base: T) -> T { value.log(&base) }
232+
/// Returns the base 2 logarithm of the number.
180233
#[inline(always)] pub fn log2<T: Exponential>(value: T) -> T { value.log2() }
234+
/// Returns the base 10 logarithm of the number.
181235
#[inline(always)] pub fn log10<T: Exponential>(value: T) -> T { value.log10() }
182236

183237
pub trait Hyperbolic: Exponential {
@@ -190,12 +244,18 @@ pub trait Hyperbolic: Exponential {
190244
fn atanh(&self) -> Self;
191245
}
192246

247+
/// Hyperbolic cosine function.
193248
#[inline(always)] pub fn sinh<T: Hyperbolic>(value: T) -> T { value.sinh() }
249+
/// Hyperbolic sine function.
194250
#[inline(always)] pub fn cosh<T: Hyperbolic>(value: T) -> T { value.cosh() }
251+
/// Hyperbolic tangent function.
195252
#[inline(always)] pub fn tanh<T: Hyperbolic>(value: T) -> T { value.tanh() }
196253

254+
/// Inverse hyperbolic sine function.
197255
#[inline(always)] pub fn asinh<T: Hyperbolic>(value: T) -> T { value.asinh() }
256+
/// Inverse hyperbolic cosine function.
198257
#[inline(always)] pub fn acosh<T: Hyperbolic>(value: T) -> T { value.acosh() }
258+
/// Inverse hyperbolic tangent function.
199259
#[inline(always)] pub fn atanh<T: Hyperbolic>(value: T) -> T { value.atanh() }
200260

201261
/// Defines constants and methods common to real numbers
@@ -345,8 +405,16 @@ pub trait Float: Real
345405
fn next_after(&self, other: Self) -> Self;
346406
}
347407

408+
/// Returns the exponential of the number, minus `1`, `exp(n) - 1`, in a way
409+
/// that is accurate even if the number is close to zero.
348410
#[inline(always)] pub fn exp_m1<T: Float>(value: T) -> T { value.exp_m1() }
411+
/// Returns the natural logarithm of the number plus `1`, `ln(n + 1)`, more
412+
/// accurately than if the operations were performed separately.
349413
#[inline(always)] pub fn ln_1p<T: Float>(value: T) -> T { value.ln_1p() }
414+
/// Fused multiply-add. Computes `(a * b) + c` with only one rounding error.
415+
///
416+
/// This produces a more accurate result with better performance (on some
417+
/// architectures) than a separate multiplication operation followed by an add.
350418
#[inline(always)] pub fn mul_add<T: Float>(a: T, b: T, c: T) -> T { a.mul_add(b, c) }
351419

352420
/// A generic trait for converting a value to a number.
@@ -788,7 +856,7 @@ impl_from_primitive!(u64, n.to_u64())
788856
impl_from_primitive!(f32, n.to_f32())
789857
impl_from_primitive!(f64, n.to_f64())
790858

791-
/// Cast from one machine scalar to another
859+
/// Cast from one machine scalar to another.
792860
///
793861
/// # Example
794862
///
@@ -841,7 +909,7 @@ pub trait FromStrRadix {
841909
fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
842910
}
843911

844-
/// A utility function that just calls FromStrRadix::from_str_radix
912+
/// A utility function that just calls FromStrRadix::from_str_radix.
845913
pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) -> Option<T> {
846914
FromStrRadix::from_str_radix(str, radix)
847915
}

branches/dist-snap/src/libstd/rt/io/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ pub enum IoErrorKind {
371371
Closed,
372372
ConnectionRefused,
373373
ConnectionReset,
374-
NotConnected,
375374
BrokenPipe,
376375
PathAlreadyExists,
377376
PathDoesntExist,
@@ -391,7 +390,6 @@ impl ToStr for IoErrorKind {
391390
Closed => ~"Closed",
392391
ConnectionRefused => ~"ConnectionRefused",
393392
ConnectionReset => ~"ConnectionReset",
394-
NotConnected => ~"NotConnected",
395393
BrokenPipe => ~"BrokenPipe",
396394
PathAlreadyExists => ~"PathAlreadyExists",
397395
PathDoesntExist => ~"PathDoesntExist",

branches/dist-snap/src/libstd/rt/io/net/tcp.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ mod test {
306306
}
307307

308308
#[test]
309+
#[ignore(cfg(windows))] // FIXME #8811
309310
fn read_eof_twice_ip4() {
310311
do run_in_mt_newsched_task {
311312
let addr = next_test_ip4();
@@ -320,16 +321,8 @@ mod test {
320321
let mut buf = [0];
321322
let nread = stream.read(buf);
322323
assert!(nread.is_none());
323-
do read_error::cond.trap(|e| {
324-
if cfg!(windows) {
325-
assert_eq!(e.kind, NotConnected);
326-
} else {
327-
fail2!();
328-
}
329-
}).inside {
330-
let nread = stream.read(buf);
331-
assert!(nread.is_none());
332-
}
324+
let nread = stream.read(buf);
325+
assert!(nread.is_none());
333326
}
334327

335328
do spawntask {
@@ -341,6 +334,7 @@ mod test {
341334
}
342335

343336
#[test]
337+
#[ignore(cfg(windows))] // FIXME #8811
344338
fn read_eof_twice_ip6() {
345339
do run_in_mt_newsched_task {
346340
let addr = next_test_ip6();
@@ -355,16 +349,8 @@ mod test {
355349
let mut buf = [0];
356350
let nread = stream.read(buf);
357351
assert!(nread.is_none());
358-
do read_error::cond.trap(|e| {
359-
if cfg!(windows) {
360-
assert_eq!(e.kind, NotConnected);
361-
} else {
362-
fail2!();
363-
}
364-
}).inside {
365-
let nread = stream.read(buf);
366-
assert!(nread.is_none());
367-
}
352+
let nread = stream.read(buf);
353+
assert!(nread.is_none());
368354
}
369355

370356
do spawntask {

branches/dist-snap/src/libstd/rt/uv/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
267267
EACCES => PermissionDenied,
268268
ECONNREFUSED => ConnectionRefused,
269269
ECONNRESET => ConnectionReset,
270-
ENOTCONN => NotConnected,
271270
EPIPE => BrokenPipe,
272271
err => {
273272
rtdebug!("uverr.code {}", err as int);

branches/dist-snap/src/libstd/rt/uv/net.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rt::uv::uvll;
1414
use rt::uv::uvll::*;
1515
use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback, UdpSendCallback};
1616
use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, NullCallback,
17-
status_to_maybe_uv_error, vec_to_uv_buf};
17+
status_to_maybe_uv_error};
1818
use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
1919
use vec;
2020
use str;
@@ -147,18 +147,7 @@ impl StreamWatcher {
147147
data.read_cb = Some(cb);
148148
}
149149

150-
let ret = unsafe { uvll::read_start(self.native_handle(), alloc_cb, read_cb) };
151-
152-
if ret != 0 {
153-
// uvll::read_start failed, so read_cb will not be called.
154-
// Call it manually for scheduling.
155-
call_read_cb(self.native_handle(), ret as ssize_t);
156-
}
157-
158-
fn call_read_cb(stream: *uvll::uv_stream_t, errno: ssize_t) {
159-
#[fixed_stack_segment]; #[inline(never)];
160-
read_cb(stream, errno, vec_to_uv_buf(~[]));
161-
}
150+
unsafe { uvll::read_start(self.native_handle(), alloc_cb, read_cb); }
162151

163152
extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf {
164153
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(stream);

branches/dist-snap/src/libstd/rt/uv/uvll.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub mod errors {
5353
pub static EACCES: c_int = -4093;
5454
pub static ECONNREFUSED: c_int = -4079;
5555
pub static ECONNRESET: c_int = -4078;
56-
pub static ENOTCONN: c_int = -4054;
5756
pub static EPIPE: c_int = -4048;
5857
}
5958
#[cfg(not(windows))]
@@ -64,7 +63,6 @@ pub mod errors {
6463
pub static EACCES: c_int = -libc::EACCES;
6564
pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED;
6665
pub static ECONNRESET: c_int = -libc::ECONNRESET;
67-
pub static ENOTCONN: c_int = -libc::ENOTCONN;
6866
pub static EPIPE: c_int = -libc::EPIPE;
6967
}
7068

0 commit comments

Comments
 (0)