Unless you expect exact result because all you are doing is copying, as soon as 
computation is involved you need to check either the relative error or the 
absolute error or both.

For instance, extracted [from my 
code](https://github.com/numforge/laser/blob/9fbb8d2a573d950573c7249e3a5d6cdd784a639e/laser/private/error_functions.nim#L6-L18):
    
    
    proc relative_error*[T: SomeFloat](y, y_true: T): T {.inline.} =
      ## Relative error, |y_true - y|/max(|y_true|, |y|)
      ## Normally the relative error is defined as |y_true - y| / |y_true|,
      ## but here max is used to make it symmetric and to prevent dividing by 
zero,
      ## guaranteed to return zero in the case when both values are zero.
      let denom = max(abs(y_true), abs(y))
      if denom == 0.T:
        return 0.T
      result = abs(y_true - y) / denom
    
    proc absolute_error*[T: SomeFloat](y, y_true: T): T {.inline.} =
      ## Absolute error for a single value, |y_true - y|
      result = abs(y_true - y)
    
    
    Run

In general you should prefer the relative_error especially with numbers not in 
the [-1, 1] range, but when the target is near 0, the relative change will get 
quite high due to the division and here you need to use the absolute error 
instead.

Reply via email to