is it possible to sort a float range ?
someone
someone at somewhere.com
Wed Jun 23 19:53:24 UTC 2021
Please, look for the line marked +++
This is a structure with a public property returning a (still
unsorted) range built on-the-fly from already-set properties, a
basic range from a to z with n step where some specific values
can be added in-between. The range is a float which I am
currently using for currency (horrible) and later plan to move it
to decimal 10 or the like.
```d
public struct gudtRangeWhatIf {
private float[] pnumValueCustom;
private float pnumValueBaseLimit1;
private float pnumValueBaseLimit2;
private float pnumValueBaseStep;
public float start() @property const { return
pnumValueBaseLimit1; }
public float end() @property const { return
pnumValueBaseLimit2; }
public float step() @property const { return
pnumValueBaseStep; }
public float[] range() @property const {
float[] lnumRange;
if (! (pnumValueBaseLimit1 == float.nan ||
pnumValueBaseLimit2 == float.nan || pnumValueBaseStep ==
float.nan)) {
for (
float lnumValue = pnumValueBaseLimit1;
lnumValue <= pnumValueBaseLimit2;
lnumValue += pnumValueBaseStep
) {
lnumRange ~= lnumValue;
}
}
foreach (float lnumValue; pnumValueCustom) {
lnumRange ~= lnumValue;
}
return lnumRange; /// .sort!(r"a > b"c); /// doesn't work
+++
}
this(
in float lnumValueBaseLimit1,
in float lnumValueBaseLimit2,
in float lnumValueBaseStep
) {
/// (1) given start limit > 0
/// (2) given end limit > start limit
/// (3) given step > 0
if (lnumValueBaseLimit1 > 0f && lnumValueBaseLimit1 <
lnumValueBaseLimit2 && lnumValueBaseStep > 0f) {
pnumValueBaseLimit1 = lnumValueBaseLimit1;
pnumValueBaseLimit2 = lnumValueBaseLimit2;
pnumValueBaseStep = lnumValueBaseStep;
}
}
public void addCustomValue(
in float lnumValue
) {
/// (1) given value > 0
if (lnumValue > 0f) {
pnumValueCustom ~= lnumValue;
}
}
}
```
More information about the Digitalmars-d-learn
mailing list