Created
October 10, 2019 17:45
-
-
Save soffes/999d2d0dfaf3850a498c50dedd02d6a6 to your computer and use it in GitHub Desktop.
I'm trying to figure out how Xcode formats floats in its XIB/Storyboard XML. So far, I'm stumped.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# I'm trying to figure out how Xcode formats floats in its XIB/Storyboard XML. So far, I'm stumped. | |
# Data from Xcode | |
data = values = ["0.0", "0.0039215686274509803", "0.0078431372549019607", "0.011764705882352941", "0.0039215686274509803", "0.019607843137254902", "0.023529411764705882", "0.027450980392156862", "0.031372549019607843", "0.035294117647058823", "0.039215686274509803", "0.043137254901960784", "0.047058823529411764", "0.050980392156862744", "0.054901960784313725", "0.058823529411764705", "0.062745098039215685", "0.066666666666666666", "0.070588235294117646", "0.074509803921568626", "0.078431372549019607", "0.082352941176470587", "0.086274509803921567", "0.090196078431372548", "0.094117647058823528", "0.098039215686274508", "0.10196078431372549", "0.10588235294117647", "0.10980392156862745", "0.11372549019607843", "0.11764705882352941", "0.12156862745098039", "0.12549019607843137", "0.12941176470588234", "0.13333333333333333", "0.13725490196078433", "0.14117647058823529", "0.14509803921568626", "0.14901960784313725", "0.15294117647058825", "0.15686274509803921", "0.16078431372549018", "0.16470588235294117", "0.16862745098039217", "0.17254901960784313", "0.1764705882352941", "0.1803921568627451", "0.18431372549019609", "0.18823529411764706", "0.19215686274509802", "0.19607843137254902", "0.20000000000000001", "0.20392156862745098", "0.20784313725490194", "0.21176470588235294", "0.21568627450980393", "0.2196078431372549", "0.22352941176470587", "0.22745098039215686", "0.23137254901960785", "0.23529411764705882", "0.23921568627450979", "0.24313725490196078", "0.24705882352941178", "0.25098039215686274", "0.25490196078431371", "0.25882352941176467", "0.2627450980392157", "0.26666666666666666", "0.27058823529411763", "0.27450980392156865", "0.27843137254901962", "0.28235294117647058", "0.28627450980392155", "0.29019607843137252", "0.29411764705882354", "0.29803921568627451", "0.30196078431372547", "0.30588235294117649", "0.30980392156862746", "0.31372549019607843", "0.31764705882352939", "0.32156862745098036", "0.32549019607843138", "0.32941176470588235", "0.33333333333333331", "0.33725490196078434", "0.3411764705882353", "0.34509803921568627", "0.34901960784313724", "0.3529411764705882", "0.35686274509803922", "0.36078431372549019", "0.36470588235294116", "0.36862745098039218", "0.37254901960784315", "0.37647058823529411", "0.38039215686274508", "0.38431372549019605", "0.38823529411764707", "0.39215686274509803", "0.396078431372549", "0.40000000000000002", "0.40392156862745099", "0.40784313725490196", "0.41176470588235292", "0.41568627450980389", "0.41960784313725491", "0.42352941176470588", "0.42745098039215684", "0.43137254901960786", "0.43529411764705883", "0.4392156862745098", "0.44313725490196076", "0.44705882352941173", "0.45098039215686275", "0.45490196078431372", "0.45882352941176469", "0.46274509803921571", "0.46666666666666667", "0.47058823529411764", "0.47450980392156861", "0.47843137254901957", "0.4823529411764706", "0.48627450980392156", "0.49019607843137253", "0.49411764705882355", "0.49803921568627452", "0.50196078431372548", "0.50588235294117645", "0.50980392156862742", "0.51372549019607838", "0.51764705882352935", "0.52156862745098043", "0.52549019607843139", "0.52941176470588236", "0.53333333333333333", "0.53725490196078429", "0.54117647058823526", "0.54509803921568623", "0.5490196078431373", "0.55294117647058827", "0.55686274509803924", "0.5607843137254902", "0.56470588235294117", "0.56862745098039214", "0.5725490196078431", "0.57647058823529407", "0.58039215686274503", "0.58431372549019611", "0.58823529411764708", "0.59215686274509804", "0.59607843137254901", "0.59999999999999998", "0.60392156862745094", "0.60784313725490191", "0.61176470588235299", "0.61568627450980395", "0.61960784313725492", "0.62352941176470589", "0.62745098039215685", "0.63137254901960782", "0.63529411764705879", "0.63921568627450975", "0.64313725490196072", "0.6470588235294118", "0.65098039215686276", "0.65490196078431373", "0.6588235294117647", "0.66274509803921566", "0.66666666666666663", "0.6705882352941176", "0.67450980392156867", "0.67843137254901964", "0.68235294117647061", "0.68627450980392157", "0.69019607843137254", "0.69411764705882351", "0.69803921568627447", "0.70196078431372544", "0.70588235294117641", "0.70980392156862748", "0.71372549019607845", "0.71764705882352942", "0.72156862745098038", "0.72549019607843135", "0.72941176470588232", "0.73333333333333328", "0.73725490196078436", "0.74117647058823533", "0.74509803921568629", "0.74901960784313726", "0.75294117647058822", "0.75686274509803919", "0.76078431372549016", "0.76470588235294112", "0.7686274509803922", "0.77254901960784317", "0.77647058823529413", "0.7803921568627451", "0.78431372549019607", "0.78823529411764703", "0.7803921568627451", "0.78431372549019607", "0.78823529411764703", "0.80392156862745101", "0.80784313725490198", "0.81176470588235294", "0.81568627450980391", "0.81960784313725488", "0.82352941176470584", "0.82745098039215681", "0.83137254901960778", "0.83529411764705885", "0.83921568627450982", "0.84313725490196079", "0.84705882352941175", "0.85098039215686272", "0.85490196078431369", "0.85882352941176465", "0.86274509803921573", "0.8666666666666667", "0.87058823529411766", "0.87450980392156863", "0.8784313725490196", "0.88235294117647056", "0.88627450980392153", "0.8901960784313725", "0.89411764705882346", "0.89803921568627454", "0.90196078431372551", "0.90588235294117636", "0.90980392156862744", "0.9137254901960784", "0.91764705882352937", "0.92156862745098034", "0.92549019607843142", "0.92941176470588227", "0.93333333333333335", "0.93725490196078431", "0.94117647058823517", "0.94509803921568625", "0.94901960784313721", "0.95294117647058807", "0.95686274509803915", "0.96078431372549022", "0.96470588235294097", "0.96862745098039216", "0.97254901960784312", "0.97647058823529387", "0.98039215686274506", "0.98431372549019602", "0.98823529411764677", "0.99215686274509807", "0.99607843137254903", "1"] | |
def format_value(value): | |
# type: (int) -> str | |
# Convert from an int from 0-255 to a float from 0-1 | |
value = float(i) / 255.0 | |
# TODO: Figure out how format this correctly | |
string = ("%0.18f" % value).rstrip("0") | |
string = re.sub(r'([0-9.]+)0$', '\\1', string) | |
return re.sub(r'([0-9]+)\.$', '\\1.0', string) | |
# Test each value from 0-255 | |
for i in range(len(data)): | |
string = format_value(i) | |
expected = data[i] | |
# Print ones that are incorrect | |
if string != expected: | |
print("{}\t\t{}\t{}".format(i, string, expected)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment