[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: common warning id for double->object conversion
From: |
Colin Macdonald |
Subject: |
Re: common warning id for double->object conversion |
Date: |
Wed, 22 Jun 2016 20:43:21 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 |
On 22/06/16 18:07, Oliver Heimlich wrote:
How do you decide whether to give a warning? If the parameter is no
integer? There are some fractions which have no rounding errors, e. g.
0.5, 0.25, 0.125, … and sums thereof.
I do this:
https://github.com/cbm755/octsympy/blob/master/inst/%40sym/private/magic_double_str.m
Its very simple. I don't care if 0.25 has an exact bit representation:
"sym(0.25)" is bad code, one should use "sym(1)/4". And generally I
don't think symbolic users should be passing double values from other
code into sym, so an aggressive warning is good. (I'm sure there are
valid use cases, but I've not seen one that outweighs the educational
aspect for new users).
vpa is a little different: perhaps that's why I never added a warning
there before. One can imagine feeding double's from some other part of
a code into vpa code (e.g., as an initial guess to vpasolve). Instead
there is a prominent warning in the docs. But since a new user was
confused by vpa(1/3)---*the same example in the docs*---I'm rethinking
that choice...
4. yeah, pi might be problematic as well if the user expects to use the
approximate floating point value returned by pi () instead of π.
An expert use; not too worried about that, e.g., could do "vpa(vpa(pi,
16), 64)".
We could stick to the official naming from IEEE 754, which is the
“inexact” exception. I propose one of the following:
warning("Octave:inexact-argument", …)
warning("numeric:inexact-argument", …)
warning("double:inexact-argument", …)
Sounds reasonable. I think I like either "numeric:" or "double:". Is
it appropriate for me to use such an IEEE754 convention even if I stick
with my much-simplified tests (above)? That is, may I raise such a
thing on sym(0.25)?
Thanks for the detailed thoughts. For syms, I might consider using
something like your function *after* the warning... Right now, sym has
some heuristics using rat() that prefers "short" rationals or
rational*pi. Example:
>> a = pi/8 + 1000*eps
a = 0.392699081698946
>> sym(a)
warning: Using rat() heuristics for double-precision input (is this what
you wanted?)
warning: called from
sym at line 225 column 7
ans = (sym)
π
─
8
(The alternative is to give them back the exact real number
corresponding to the double precision value they pass in...)
Colin