 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hello,
I spent some time trying to figure out why my code was producing bizarre
results. It couldn't be simpler. It fits on a single line :
#declare y0 = a*x0*+b;
Of course, there are no syntax errors.
A typo left an “*” after the x0.
What I don't understand is the calculation involving that extra “*”
With a = 0.51, b = 10.66 and x0 = -16.25, the correct calculation
yields 2.37 and with the extar "*", -88.34 !
Where's the logic? I haven't been able to find a connection between the
two values, so I don't understand what operation this * performs.
I'm sure the people here have already figured it out and will be able to
explain it to me. Thanks
--
klp
compagnie de la banquise
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
kurtzlepirate <kur### [at] free fr> wrote:
> Hello,
>
> I spent some time trying to figure out why my code was producing bizarre
> results. It couldn't be simpler. It fits on a single line :
>
> #declare y0 = a*x0*+b;
>
>
> Of course, there are no syntax errors.
> A typo left an “*” after the x0.
>
> What I don't understand is the calculation involving that extra “*”
>
> With a = 0.51, b = 10.66 and x0 = -16.25, the correct calculation
> yields 2.37 and with the extar "*", -88.34 !
>
> Where's the logic? I haven't been able to find a connection between the
> two values, so I don't understand what operation this * performs.
>
>
>
> I'm sure the people here have already figured it out and will be able to
> explain it to me. Thanks
>
>
> --
> klp
> compagnie de la banquise
It seen POV's parser just ignores the plus in your equation
a*x0*+b becomes a*x0*b which is -88.34
drop the * and you get a*x0+b which is the 2.37
Try #declare y0 = a*x0*-b; and you'll get 88.34
Try #declare y0 = a*x0+*b; and you'll an Parser Error
Some parsers can't handle the '*+' syntax and crash. It has happen to me But I
can't remember when or where:)
Have Fun!
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
kurtzlepirate <kur### [at] free fr> wrote:
> Hello,
>
> I spent some time trying to figure out why my code was producing bizarre
> results. It couldn't be simpler. It fits on a single line :
>
> #declare y0 = a*x0*+b;
>
>
> Of course, there are no syntax errors.
> A typo left an “*” after the x0.
>
> What I don't understand is the calculation involving that extra “*”
>
> With a = 0.51, b = 10.66 and x0 = -16.25, the correct calculation
> yields 2.37 and with the extar "*", -88.34 !
>
> Where's the logic? I haven't been able to find a connection between the
> two values, so I don't understand what operation this * performs.
>
>
>
> I'm sure the people here have already figured it out and will be able to
> explain it to me. Thanks
It is just one more multiplication. The last plus sign is here the unary plus
operator. The unary minus operator negates the operand, the unary plus operator
does not.
This is a valid expression: 2 * -3 = -6
- and so is this: 2 * +3 = +6 = 6
https://www.geeksforgeeks.org/c/unary-operators-cc/#unary-plus
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Leroy" <whe### [at] gmail com> wrote:
> kurtzlepirate <kur### [at] free fr> wrote:
> > Hello,
> >
> > I spent some time trying to figure out why my code was producing bizarre
> > results. It couldn't be simpler. It fits on a single line :
> >
> > #declare y0 = a*x0*+b;
> >
> >
> > Of course, there are no syntax errors.
> > A typo left an �*� after the x0.
> >
> > What I don't understand is the calculation involving that extra �*�
> >
> > With a = 0.51, b = 10.66 and x0 = -16.25, the correct calculation
> > yields 2.37 and with the extar "*", -88.34 !
> >
> > Where's the logic? I haven't been able to find a connection between the
> > two values, so I don't understand what operation this * performs.
> >
> >
> >
> > I'm sure the people here have already figured it out and will be able to
> > explain it to me. Thanks
> >
> >
> > --
> > klp
> > compagnie de la banquise
>
> It seen POV's parser just ignores the plus in your equation
>
> a*x0*+b becomes a*x0*b which is -88.34
>
> drop the * and you get a*x0+b which is the 2.37
>
> Try #declare y0 = a*x0*-b; and you'll get 88.34
>
> Try #declare y0 = a*x0+*b; and you'll an Parser Error
>
> Some parsers can't handle the '*+' syntax and crash. It has happen to me But I
> can't remember when or where:)
>
> Have Fun!
I couldn't let it go. I had to try something.
#declare y0 = a*x0*+++++++++++b; & #declare y0 = a*x0*-----------b;
Both work, kind of :}
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hello,
That's exactly right.
In fact, the code is interpreted as #declare y0 = a * x0 * (+b);
That makes perfect sense.
Another problem with understanding the mechanism is that i used the
actual values from my code. If i use simpler values, it becomes much
clearer right away. First, with a = 1, we eliminate one parameter; then,
with b = 2 and x0 = 3, we get y0 = 3 + 2 = 5 vs y0 = 3 * 2 = 6.
Tor, Leroy, thank you both very much for your suggestions.
--
klp
compagnie de la banquise
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |