@@ -171,91 +171,65 @@ float_impls! { f64x8, u64x8, f64, u64, 52, 1023 }
171
171
#[ cfg( test) ]
172
172
mod tests {
173
173
use Rng ;
174
- use distributions:: { Open01 , OpenClosed01 } ;
174
+ use distributions:: { Distribution , Open01 , OpenClosed01 } ;
175
175
use rngs:: mock:: StepRng ;
176
176
#[ cfg( feature="simd_support" ) ]
177
177
use core:: simd:: * ;
178
178
179
179
const EPSILON32 : f32 = :: core:: f32:: EPSILON ;
180
180
const EPSILON64 : f64 = :: core:: f64:: EPSILON ;
181
181
182
- macro_rules! test_f32 {
183
- ( $fnn: ident, $ty: ident, $ZERO: expr, $EPSILON: expr) => {
182
+ macro_rules! test_float {
183
+ ( $fnn: ident, $ty: ident, $ZERO: expr, $EPSILON: expr, $ONE_BITS : expr ) => {
184
184
#[ test]
185
185
fn $fnn( ) {
186
186
// Standard
187
187
let mut zeros = StepRng :: new( 0 , 0 ) ;
188
188
assert_eq!( zeros. gen :: <$ty>( ) , $ZERO) ;
189
- let mut one = StepRng :: new( 1 << 8 | 1 << ( 8 + 32 ) , 0 ) ;
189
+ let mut one = StepRng :: new( $ONE_BITS , 0 ) ;
190
190
assert_eq!( one. gen :: <$ty>( ) , $EPSILON / 2.0 ) ;
191
191
let mut max = StepRng :: new( !0 , 0 ) ;
192
192
assert_eq!( max. gen :: <$ty>( ) , 1.0 - $EPSILON / 2.0 ) ;
193
193
194
194
// OpenClosed01
195
195
let mut zeros = StepRng :: new( 0 , 0 ) ;
196
- assert_eq!( zeros. sample:: <$ty, _>( OpenClosed01 ) ,
197
- 0.0 + $EPSILON / 2.0 ) ;
198
- let mut one = StepRng :: new( 1 << 8 | 1 << ( 8 + 32 ) , 0 ) ;
199
- assert_eq!( one. sample:: <$ty, _>( OpenClosed01 ) , $EPSILON) ;
196
+ assert_eq!( Distribution :: <$ty>:: sample( & OpenClosed01 , & mut zeros) ,
197
+ ( 0.0 + $EPSILON / 2.0 ) as $ty) ;
198
+ let mut one = StepRng :: new( $ONE_BITS, 0 ) ;
199
+ assert_eq!( Distribution :: <$ty>:: sample( & OpenClosed01 , & mut one) ,
200
+ $EPSILON) ;
200
201
let mut max = StepRng :: new( !0 , 0 ) ;
201
- assert_eq!( max. sample:: <$ty, _>( OpenClosed01 ) , $ZERO + 1.0 ) ;
202
+ assert_eq!( Distribution :: <$ty>:: sample( & OpenClosed01 , & mut max) ,
203
+ $ZERO + 1.0 ) ;
202
204
203
205
// Open01
204
206
let mut zeros = StepRng :: new( 0 , 0 ) ;
205
- assert_eq!( zeros. sample:: <$ty, _>( Open01 ) , 0.0 + $EPSILON / 2.0 ) ;
206
- let mut one = StepRng :: new( 1 << 9 | 1 << ( 9 + 32 ) , 0 ) ;
207
- assert_eq!( one. sample:: <$ty, _>( Open01 ) , $EPSILON / 2.0 * 3.0 ) ;
207
+ assert_eq!( Distribution :: <$ty>:: sample( & Open01 , & mut zeros) ,
208
+ 0.0 + $EPSILON / 2.0 ) ;
209
+ let mut one = StepRng :: new( $ONE_BITS << 1 , 0 ) ;
210
+ assert_eq!( Distribution :: <$ty>:: sample( & Open01 , & mut one) ,
211
+ $EPSILON / 2.0 * 3.0 ) ;
208
212
let mut max = StepRng :: new( !0 , 0 ) ;
209
- assert_eq!( max. sample:: <$ty, _>( Open01 ) , 1.0 - $EPSILON / 2.0 ) ;
213
+ assert_eq!( Distribution :: <$ty>:: sample( & Open01 , & mut max) ,
214
+ 1.0 - $EPSILON / 2.0 ) ;
210
215
}
211
216
}
212
217
}
213
- test_f32 ! { f32_edge_cases, f32 , 0.0 , EPSILON32 }
218
+ test_float ! { f32_edge_cases, f32 , 0.0 , EPSILON32 , 1 << 8 | 1 << ( 8 + 32 ) }
214
219
#[ cfg( feature="simd_support" ) ]
215
- test_f32 ! { f32x2_edge_cases, f32x2, f32x2:: splat( 0.0 ) , f32x2:: splat( EPSILON32 ) }
220
+ test_float ! { f32x2_edge_cases, f32x2, f32x2:: splat( 0.0 ) , f32x2:: splat( EPSILON32 ) , 1 << 8 | 1 << ( 8 + 32 ) }
216
221
#[ cfg( feature="simd_support" ) ]
217
- test_f32 ! { f32x4_edge_cases, f32x4, f32x4:: splat( 0.0 ) , f32x4:: splat( EPSILON32 ) }
222
+ test_float ! { f32x4_edge_cases, f32x4, f32x4:: splat( 0.0 ) , f32x4:: splat( EPSILON32 ) , 1 << 8 | 1 << ( 8 + 32 ) }
218
223
#[ cfg( feature="simd_support" ) ]
219
- test_f32 ! { f32x8_edge_cases, f32x8, f32x8:: splat( 0.0 ) , f32x8:: splat( EPSILON32 ) }
224
+ test_float ! { f32x8_edge_cases, f32x8, f32x8:: splat( 0.0 ) , f32x8:: splat( EPSILON32 ) , 1 << 8 | 1 << ( 8 + 32 ) }
220
225
#[ cfg( feature="simd_support" ) ]
221
- test_f32 ! { f32x16_edge_cases, f32x16, f32x16:: splat( 0.0 ) , f32x16:: splat( EPSILON32 ) }
222
-
223
- macro_rules! test_f64 {
224
- ( $fnn: ident, $ty: ident, $ZERO: expr, $EPSILON: expr) => {
225
- #[ test]
226
- fn $fnn( ) {
227
- // Standard
228
- let mut zeros = StepRng :: new( 0 , 0 ) ;
229
- assert_eq!( zeros. gen :: <$ty>( ) , $ZERO) ;
230
- let mut one = StepRng :: new( 1 << 11 , 0 ) ;
231
- assert_eq!( one. gen :: <$ty>( ) , $EPSILON / 2.0 ) ;
232
- let mut max = StepRng :: new( !0 , 0 ) ;
233
- assert_eq!( max. gen :: <$ty>( ) , 1.0 - $EPSILON / 2.0 ) ;
226
+ test_float ! { f32x16_edge_cases, f32x16, f32x16:: splat( 0.0 ) , f32x16:: splat( EPSILON32 ) , 1 << 8 | 1 << ( 8 + 32 ) }
234
227
235
- // OpenClosed01
236
- let mut zeros = StepRng :: new( 0 , 0 ) ;
237
- assert_eq!( zeros. sample:: <$ty, _>( OpenClosed01 ) ,
238
- 0.0 + $EPSILON / 2.0 ) ;
239
- let mut one = StepRng :: new( 1 << 11 , 0 ) ;
240
- assert_eq!( one. sample:: <$ty, _>( OpenClosed01 ) , $EPSILON) ;
241
- let mut max = StepRng :: new( !0 , 0 ) ;
242
- assert_eq!( max. sample:: <$ty, _>( OpenClosed01 ) , $ZERO + 1.0 ) ;
243
-
244
- // Open01
245
- let mut zeros = StepRng :: new( 0 , 0 ) ;
246
- assert_eq!( zeros. sample:: <$ty, _>( Open01 ) , 0.0 + $EPSILON / 2.0 ) ;
247
- let mut one = StepRng :: new( 1 << 12 , 0 ) ;
248
- assert_eq!( one. sample:: <$ty, _>( Open01 ) , $EPSILON / 2.0 * 3.0 ) ;
249
- let mut max = StepRng :: new( !0 , 0 ) ;
250
- assert_eq!( max. sample:: <$ty, _>( Open01 ) , 1.0 - $EPSILON / 2.0 ) ;
251
- }
252
- }
253
- }
254
- test_f64 ! { f64_edge_cases, f64 , 0.0 , EPSILON64 }
228
+ test_float ! { f64_edge_cases, f64 , 0.0 , EPSILON64 , 1 << 11 }
255
229
#[ cfg( feature="simd_support" ) ]
256
- test_f64 ! { f64x2_edge_cases, f64x2, f64x2:: splat( 0.0 ) , f64x2:: splat( EPSILON64 ) }
230
+ test_float ! { f64x2_edge_cases, f64x2, f64x2:: splat( 0.0 ) , f64x2:: splat( EPSILON64 ) , 1 << 11 }
257
231
#[ cfg( feature="simd_support" ) ]
258
- test_f64 ! { f64x4_edge_cases, f64x4, f64x4:: splat( 0.0 ) , f64x4:: splat( EPSILON64 ) }
232
+ test_float ! { f64x4_edge_cases, f64x4, f64x4:: splat( 0.0 ) , f64x4:: splat( EPSILON64 ) , 1 << 11 }
259
233
#[ cfg( feature="simd_support" ) ]
260
- test_f64 ! { f64x8_edge_cases, f64x8, f64x8:: splat( 0.0 ) , f64x8:: splat( EPSILON64 ) }
234
+ test_float ! { f64x8_edge_cases, f64x8, f64x8:: splat( 0.0 ) , f64x8:: splat( EPSILON64 ) , 1 << 11 }
261
235
}
0 commit comments