Price fraction: Difference between revisions

Content added Content deleted
Line 3,237: Line 3,237:


<syntaxhighlight lang="langur">
<syntaxhighlight lang="langur">
val pricefrac = fn f:switch[and] f {
val table = [
case >= 0.00, < 0.06: 0.10
{"low": 0.00, "high": 0.06, "use": 0.10},
case >= 0.06, < 0.11: 0.18
{"low": 0.06, "high": 0.11, "use": 0.18},
case >= 0.11, < 0.16: 0.26
{"low": 0.11, "high": 0.16, "use": 0.26},
case >= 0.16, < 0.21: 0.32
{"low": 0.16, "high": 0.21, "use": 0.32},
case >= 0.21, < 0.26: 0.38
{"low": 0.21, "high": 0.26, "use": 0.38},
case >= 0.26, < 0.31: 0.44
{"low": 0.26, "high": 0.31, "use": 0.44},
case >= 0.31, < 0.36: 0.50
{"low": 0.31, "high": 0.36, "use": 0.50},
case >= 0.36, < 0.41: 0.54
{"low": 0.36, "high": 0.41, "use": 0.54},
case >= 0.41, < 0.46: 0.58
{"low": 0.41, "high": 0.46, "use": 0.58},
case >= 0.46, < 0.51: 0.62
{"low": 0.46, "high": 0.51, "use": 0.62},
case >= 0.51, < 0.56: 0.66
{"low": 0.51, "high": 0.56, "use": 0.66},
case >= 0.56, < 0.61: 0.70
{"low": 0.56, "high": 0.61, "use": 0.70},
case >= 0.61, < 0.66: 0.74
{"low": 0.61, "high": 0.66, "use": 0.74},
case >= 0.66, < 0.71: 0.78
{"low": 0.66, "high": 0.71, "use": 0.78},
case >= 0.71, < 0.76: 0.82
{"low": 0.71, "high": 0.76, "use": 0.82},
case >= 0.76, < 0.81: 0.86
{"low": 0.76, "high": 0.81, "use": 0.86},
case >= 0.81, < 0.86: 0.90
{"low": 0.81, "high": 0.86, "use": 0.90},
case >= 0.86, < 0.91: 0.94
{"low": 0.86, "high": 0.91, "use": 0.94},
case >= 0.91, < 0.96: 0.98
{"low": 0.91, "high": 0.96, "use": 0.98},
case >= 0.96, <= 1.00: 1.00
{"low": 0.96, "high": 1.00, "use": 1.00},
]
default: throw "bad data"

val pricefrac = fn f: {
if f == 1.00: return 1.00
for h in table {
if f >= h'low and f < h'high: return h'use
}
throw "no match"
}
}