@@ -587,16 +587,14 @@ let _config = function _config (options) {
587587
588588 // Determine if the simplified unit is simpler
589589
590-
591-
592590 let calcComplexity = ( unitList ) => {
593591 // Number of total units, each adds one symbol
594592 let comp = unitList . length
595593
596594 // Number of units in denominator and numerator
597595 let nDen = unitList . filter ( a => a . power < 1e-14 ) . length
598596 let nNum = unitList . length - nDen
599-
597+
600598 // If there are no units in the numerator, then any units in the denominator will need a ^-1
601599
602600 // Number of units in the numerator containing powers !== 1, i.e. kg^2, adds two symbols
@@ -728,8 +726,8 @@ let _config = function _config (options) {
728726 let value1 , value2
729727 if ( unit1 . value === null && unit2 . value === null ) {
730728 // If both units are valueless, get the normalized value of 1 to compare only the unit lists
731- value1 = normalize ( unit1 . units , options . type . conv ( 1 ) , options . type )
732- value2 = normalize ( unit2 . units , options . type . conv ( 1 ) , options . type )
729+ value1 = normalize ( unit1 . units , options . type . conv ( 1 , unit1 . value ) , options . type )
730+ value2 = normalize ( unit2 . units , options . type . conv ( 1 , unit2 . value ) , options . type )
733731 } else if ( unit1 . value !== null && unit2 . value !== null ) {
734732 // Both units have values
735733 value1 = normalize ( unit1 . units , unit1 . value , options . type )
@@ -870,7 +868,7 @@ let _config = function _config (options) {
870868 }
871869
872870 if ( result . value !== null ) {
873- result . value = options . type . pow ( result . value , options . type . conv ( p ) )
871+ result . value = options . type . pow ( result . value , options . type . conv ( p , unit . value ) )
874872 } else {
875873 result . value = null
876874 }
@@ -879,7 +877,7 @@ let _config = function _config (options) {
879877 }
880878
881879 function _sqrt ( unit ) {
882- return _pow ( unit , options . type . conv ( 0.5 ) )
880+ return _pow ( unit , options . type . conv ( 0.5 , unit . value ) )
883881 }
884882
885883 /**
@@ -919,12 +917,12 @@ let _config = function _config (options) {
919917 // But instead of comparing x, the remainder, with zero--we will compare the sum of
920918 // all the parts so far with the original value. If they are nearly equal,
921919 // we set the remainder to 0.
922- let testSum = options . type . conv ( 0 )
920+ let testSum = options . type . conv ( 0 , unit . value )
923921 for ( let i = 0 ; i < result . length ; i ++ ) {
924922 testSum = options . type . add ( testSum , normalize ( result [ i ] . units , result [ i ] . value , options . type ) )
925923 }
926924 if ( options . type . eq ( testSum , normalize ( unit . units , unit . value , options . type ) ) ) {
927- x . value = options . type . conv ( 0 )
925+ x . value = options . type . conv ( 0 , unit . value )
928926 }
929927
930928 result . push ( x )
@@ -983,7 +981,7 @@ let _config = function _config (options) {
983981 // Unit has power of 0, so prefix will have no effect
984982 return unit
985983 }
986- if ( opts . type . lt ( opts . type . abs ( unit . value ) , opts . type . conv ( 1e-50 ) ) ) {
984+ if ( opts . type . lt ( opts . type . abs ( unit . value ) , opts . type . conv ( 1e-50 , unit . value ) ) ) {
987985 // Unit is too small for the prefix to matter
988986 return unit
989987 }
@@ -1003,10 +1001,10 @@ let _config = function _config (options) {
10031001 unit . value ,
10041002 opts . type . pow (
10051003 options . type . div (
1006- options . type . conv ( piece . unit . prefixes [ prefix ] ) ,
1007- options . type . conv ( piece . unit . prefixes [ piece . prefix ] )
1004+ options . type . conv ( piece . unit . prefixes [ prefix ] , unit . value ) ,
1005+ options . type . conv ( piece . unit . prefixes [ piece . prefix ] , unit . value )
10081006 ) ,
1009- options . type . conv ( piece . power )
1007+ options . type . conv ( piece . power , unit . value )
10101008 )
10111009 )
10121010 }
@@ -1015,18 +1013,18 @@ let _config = function _config (options) {
10151013 let thisValue = calcValue ( prefix )
10161014 if ( opts . type . lt ( thisValue , opts . prefixMin ) ) {
10171015 // prefix makes the value too small
1018- return opts . type . abs ( opts . type . div ( options . type . conv ( opts . prefixMin ) , thisValue ) )
1016+ return opts . type . abs ( opts . type . div ( options . type . conv ( opts . prefixMin , unit . value ) , thisValue ) )
10191017 }
10201018 if ( opts . type . gt ( thisValue , opts . prefixMax ) ) {
10211019 // prefix makes the value too large
1022- return opts . type . abs ( opts . type . div ( thisValue , options . type . conv ( opts . prefixMax ) ) )
1020+ return opts . type . abs ( opts . type . div ( thisValue , options . type . conv ( opts . prefixMax , unit . value ) ) )
10231021 }
10241022
10251023 // The prefix is in range, but return a score that says how close it is to the original value.
10261024 if ( opts . type . le ( thisValue , unit . value ) ) {
1027- return opts . type . mul ( opts . type . abs ( opts . type . div ( thisValue , unit . value ) ) , opts . type . conv ( - 1 ) )
1025+ return opts . type . mul ( opts . type . abs ( opts . type . div ( thisValue , unit . value ) ) , opts . type . conv ( - 1 , unit . value ) )
10281026 } else {
1029- return opts . type . mul ( opts . type . abs ( opts . type . div ( unit . value , thisValue ) ) , opts . type . conv ( - 1 ) )
1027+ return opts . type . mul ( opts . type . abs ( opts . type . div ( unit . value , thisValue ) ) , opts . type . conv ( - 1 , unit . value ) )
10301028 }
10311029 }
10321030
0 commit comments