Changes between Version 141 and Version 142 of WikiStart


Ignore:
Timestamp:
02/28/19 16:45:38 (5 years ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart

    v141 v142  
    212212}}}
    213213
    214 This example also illustrates a problem with the json parser. In our jobs example domain, all issues have discrete values, so "2000" is just a string, not a number.
    215 
    216 In this case, a specific problem occured that we had to figure a workaround for. Suppose we have a bid in the jobs domain:
    217 
    218 
    219 
    220 Internally BigDecimal is used for computing and storing issue values, utilities etc. Doubles always give rounding problems and can not be assumed to sum properly to 1 and therefore can not be used.
    221 
    222 In the special case of issue values, we can not determine a priori if the values are
    223 
    224 Since JSON parses normal number directly into doubles, it is necessary to place numbers also inside string objects ("..."). That in turn forces us to put some hard marker in the string to see if "1" would be a discrete value or number value. To do this, any Value contained in a string that is of the form "=X.Y" where X is a positive or negative integer and Y a positive integer is a NumberValue. Anything else is interpreted as a DiscreteValue.
     214=== Value workaround
     215This example also illustrates a problem with the json parser. In our jobs example domain, fte is a  discrete value, so "0.8" is just a string, not a number. However if fte would be a numeric issue, we naively would write the 0.8 without quotes: {{{fte:0.8}}}. However due to the way the json parser works, we would get 0.8 parsed as s double. This introduces rounding errors. And these cause all kinds of problems.
     216
     217To avoid these rounding errors, the solution is to store the decimal value also in a string. We can then later convert it properly.
     218
     219However if we store it in a string, we would be unable to distinguish it from a discrete value. To work around this, we put it in a string and prepend it with a "=".
     220
     221* "0.8": the DiscreteValue
     222* "=0.8": the NumberValue.
     223
     224This workaround is only needed for issue values like in bids. In other places where we can *only* have double values, we can work around the issue without needing the string trick.
     225
    225226
    226227