summaryrefslogtreecommitdiff
path: root/scss/cssdefs.py
diff options
context:
space:
mode:
Diffstat (limited to 'scss/cssdefs.py')
-rw-r--r--scss/cssdefs.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/scss/cssdefs.py b/scss/cssdefs.py
index 5d9b7eb..79be7b4 100644
--- a/scss/cssdefs.py
+++ b/scss/cssdefs.py
@@ -1,6 +1,7 @@
"""Constants and functions defined by the CSS specification, not specific to
Sass.
"""
+from fractions import Fraction
from math import pi
import re
@@ -166,15 +167,15 @@ BASE_UNIT_CONVERSIONS = {
# Lengths
'mm': (1, 'mm'),
'cm': (10, 'mm'),
- 'in': (25.4, 'mm'),
- 'px': (25.4 / 96, 'mm'),
- 'pt': (25.4 / 72, 'mm'),
- 'pc': (25.4 / 6, 'mm'),
+ 'in': (Fraction(254, 10), 'mm'),
+ 'px': (Fraction(254, 960), 'mm'),
+ 'pt': (Fraction(254, 720), 'mm'),
+ 'pc': (Fraction(254, 60), 'mm'),
# Angles
- 'deg': (1 / 360, 'turn'),
- 'grad': (1 / 400, 'turn'),
- 'rad': (pi / 2, 'turn'),
+ 'deg': (Fraction(1, 360), 'turn'),
+ 'grad': (Fraction(1, 400), 'turn'),
+ 'rad': (Fraction.from_float(pi / 2), 'turn'),
'turn': (1, 'turn'),
# Times
@@ -187,7 +188,7 @@ BASE_UNIT_CONVERSIONS = {
# Resolutions
'dpi': (1, 'dpi'),
- 'dpcm': (2.54, 'dpi'),
+ 'dpcm': (Fraction(254 / 100), 'dpi'),
'dppx': (96, 'dpi'),
}
@@ -252,7 +253,7 @@ def cancel_base_units(units, to_remove):
# Copy the dict since we're about to mutate it
to_remove = to_remove.copy()
remaining_units = []
- total_factor = 1
+ total_factor = Fraction(1)
for unit in units:
factor, base_unit = get_conversion_factor(unit)