307 let n = FPNum::new(15, 2); |
307 let n = FPNum::new(15, 2); |
308 |
308 |
309 assert!(z.is_zero()); |
309 assert!(z.is_zero()); |
310 assert!(z.is_positive()); |
310 assert!(z.is_positive()); |
311 assert!((-z).is_negative); |
311 assert!((-z).is_negative); |
312 assert_eq!(n - n, z) |
312 assert_eq!(n - n, z); |
|
313 assert_eq!(-n + n, z); |
313 } |
314 } |
314 |
315 |
315 #[test] |
316 #[test] |
316 fn arith() { |
317 fn arith() { |
317 let n1_5 = FPNum::new(3, 2); |
318 let n1_5 = FPNum::new(3, 2); |
318 let n2_25 = FPNum::new(9, 4); |
319 let n2_25 = FPNum::new(9, 4); |
|
320 let n_0_15 = FPNum::new(-15, 100); |
319 |
321 |
320 assert_eq!(n1_5 + n1_5, FPNum::from(3)); |
322 assert_eq!(n1_5 + n1_5, FPNum::from(3)); |
321 assert_eq!(-n1_5 - n1_5, FPNum::from(-3)); |
323 assert_eq!(-n1_5 - n1_5, FPNum::from(-3)); |
322 |
324 |
323 assert_eq!(n1_5 * n1_5, n2_25); |
325 assert_eq!(n1_5 * n1_5, n2_25); |
324 assert_eq!(-n1_5 * -n1_5, n2_25); |
326 assert_eq!(-n1_5 * -n1_5, n2_25); |
325 assert_eq!(n1_5 * -n1_5, -n2_25); |
327 assert_eq!(n1_5 * -n1_5, -n2_25); |
326 assert_eq!(-n1_5 * n1_5, -n2_25); |
328 assert_eq!(-n1_5 * n1_5, -n2_25); |
327 |
329 |
|
330 assert_eq!(-n2_25 / -n1_5, n1_5); |
|
331 assert_eq!(n1_5 / -10, n_0_15); |
|
332 |
328 assert_eq!(n1_5.sqr(), n2_25); |
333 assert_eq!(n1_5.sqr(), n2_25); |
329 assert_eq!((-n1_5).sqr(), n2_25); |
334 assert_eq!((-n1_5).sqr(), n2_25); |
330 |
335 |
331 assert_eq!(n2_25.sqrt(), n1_5); |
336 assert_eq!(n2_25.sqrt(), n1_5); |
332 |
337 |