File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ impl Voltage {
4242 Self :: from_volts ( kilovolts * 1000.0 )
4343 }
4444
45+ /// Create a new Voltage from a floating point value in Megavolts
46+ pub fn from_megavolts ( megavolts : f64 ) -> Self {
47+ Self :: from_volts ( megavolts * 1000000.0 )
48+ }
49+
50+
4551 /// Convert this Voltage into a floating point value in Volts
4652 pub fn as_volts ( & self ) -> f64 {
4753 self . volts
@@ -61,6 +67,11 @@ impl Voltage {
6167 pub fn as_kilovolts ( & self ) -> f64 {
6268 self . volts / 1000.0
6369 }
70+
71+ /// Convert this Voltage into a floating point value in Megavolts
72+ pub fn as_megavolts ( & self ) -> f64 {
73+ self . volts / 1000000.0
74+ }
6475}
6576
6677impl Measurement for Voltage {
@@ -108,6 +119,12 @@ mod test {
108119 assert_almost_eq ( u. as_kilovolts ( ) , 10.0 ) ;
109120 }
110121
122+ #[ test]
123+ pub fn as_megavolts ( ) {
124+ let u = Voltage :: from_volts ( 10_000_000.0 ) ;
125+ assert_almost_eq ( u. as_megavolts ( ) , 10.0 ) ;
126+ }
127+
111128 #[ test]
112129 pub fn as_volts ( ) {
113130 let u = Voltage :: from_kilovolts ( 1.234 ) ;
You can’t perform that action at this time.
0 commit comments