 # atan(Inf) wrong operation, but no syntax error for this case

What does this mean?

``````octave:17> atan(Inf)
ans = 1.5708
octave:18> a=[1 0]; b=[0 1];
octave:19> atan(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))
ans = Inf
``````

It means if you divide (a non-zero) by zero you get Inf.

1 Like

It looks like a step is needed before using atan for substituting it into ‘c’

``````octave:5> c=(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))
c = Inf
octave:6> atan(c)
ans = 1.5708
``````

It is maybe ok, but not sure why it need this ‘c’.

In your original post you essentially wrote `atan(1)/0`.

Maybe you intended to write this?

``````atan((a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2)))
``````
1 Like

I mean like the octave line 19. It looks correct, but for some reason that requires setting the
variable ‘c’ before using the atan(). Maybe some safety mechanism or something.

You are missing parenthesis. See the comment before.

I can not see about that.

It might be easier to spot the difference if the two commands are next to each other. (I’m sure you would be able to do that yourself.)
Your command first. The command that you likely wanted to execute second:

``````atan(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))
atan((a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2)))
``````
1 Like

I can not see about that. If there is any issue with parenthesis, the octave should give error message that case. But there is no error from octave about that.
Often time I could not see if any issues, but I guess most of the time it will give error/warning.
I guess the warning system is not operating normally.
The case subject should be about the warning/error missing, not about atan-operation.
I’ll add the case in *m file here:
case1.m (150 Bytes)
If I have text like atan here it gives no error, but if I have test like atss, there is syntax error.
So I don’t know why it can not give any error.

``````#!/usr/bin/octave -qf
# atan-test
a=[1 0]; b=[0 1];
atan(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))
atss(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))
``````

Latter case only gives error.

How should Octave be able to guess if you want to calculate `atan(1)/0` or `atan(1/0)`? There is no way of warning about that …

Maybe then impossible…
The right command is of course:
`atan((a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2)))`
I think some interface issues, that is nearly impossible to solve.
Problem at command interface, even that looks pretty good,
but something that it makes difficult to see this issue.
My font is already set to large size, but still not help.
Maybe nearly impossible to find out why it can not be seen clearly.
I guess the typing is faster than what I could see/outline the result, so it may happen too many times.
I guess the ‘parenthesis’ checker in octave would not work at high speed typing or can not even help in this type problem at all.
I guess here is no way, except to debug until it is found.
If I entered first:

``````a=[0 1]; b=[1 1];
atand(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))
``````

it worked well…
But this is maybe good case when it works with wrong code.

``````octave:11> atand(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))
ans = -45
octave:12> atand((a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2)))
ans = -45
``````

It looks taking too long time to check about this, but looks almost no way to find out easily,
if it can not be seen easily.
Maybe I guess the “parenthesis” checker should show the function() parenthesis with different color/type when it is checked vs. other sentence parenthesis. But I couldn’t be sure how it should work.
Would that be possible to show function parenthesis with different color or bold or other font difference vs. other parenthesis? Like below? But what if the function uses different type/kind of bracket than the other stuff?
for example atan[] and the internal bracket for anything else than function use ()?
Or when the parenthsesis checker operate, if it can highlight the functions separately with different type of text (bold, italic, anything different).
Also below case it would be ‘clear’ which bracket/parenthesis belongs where:
`octave:1> atan[a(1)*b(2)-a(2)*b(1)]/(a(1)*b(1)+a(2)*b(2))`
But personally I don’t like the [], because they are hard to find on the keyboard when typing. So if we replace the [] to around the normal brackets, would that cause big issues?
My keyboard layout looks like not as good as above sample. Mine is as above and it has the [] sign very difficult to e found.
It looks I don’t like the “[]” because its hard to be found on my keyboard, but some major
math programs like WFA (Wolfram alpha) want to use [] for functions instead of ().
I don’t know if this is big difference to see, but below case there is 2 kind of parentheses above is normal and below is bold. If the octave somehow could use the bold for the functions “automatically” when typing it could help about this.
If this is defined with bracket or if the system had rounded parenthesis little different than “(&)”
for the functions that would result in to syntax error if I had:
`octave:1> atan[a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))`
or
`octave:1> atan[a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2)]`
or
`octave:1> atan(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))`
cause it would detect what is for function and what is for the non-function part.
and most importantly if the different bracket/parenthesis let me see it clearly, it would yielded into:
`octave:1> atan[(a(1)*b(2)-a(2)*b(1))/(a(1)*b(1)+a(2)*b(2))]`
that is correct solution.
This is maybe some type of code error resiliency issue that seems be ‘neglected’ little bit.
There must be a way to coding that user/programmer can not enter wrong code accidentally like here. But I couldn’t make it up myself.

## Definition

Software Resiliency indicates programming best practices that make software bullet-proof, more robust and secure. This index is derived through technology-specific code analysis that searches for the presence of code patterns and bad programming practices that may comprise the reliability of the software at short term. Higher is the Software Resiliency, lower is the likelihood of defects occurring in production.

@jarkky

Like this:

``````>> atan(1/0)
>> atan(1)/0
``````

In the first line you’re asking, “hey, what is the atan of 1/0?”
While in the second one, “hey, what is the result of atan(1) divided by 0?”

It is nice to understand how the Octave’s sintax works! It is nice to do simple tests to see how numerical computations are performed.

@mmuetzel is right. How can Octave guess what you want?

Using ‘pen and paper’, if one write

atan 3 + 5

What does this mean? Is this the same as “5 + atan(3)” or “atan(3 + 5)” ?

Besides, Octave is used all around the world. You cannot expect that every one will have the same keyboard as you.

Also, remember that brackets are used to define matrices while "{"and "}"are used to define cell arrays.

https://octave.org/doc/v6.3.0/

If you allow me, I would like to give you a few tips while writting code:

• Do not perform premature code optimization
• Do not try to do things in only one line
• Split your code in several and small steps (it helps when debugging or looking for errors)
• After the ‘first version’, perform simple tests to check if the numerical results are as good as the theoretical one or even correct.

In general, ‘code’ must be as simple as possible (easy to read, easy to change). Most difficult part is documentation. Good documentation is not a easy thing to do.

As I said before, it is nice to perform small tests. As stated in Octave`s manual, even a simple operation like

``````0.3 - 0.2 - 0.1
``````

is not “zero”. This is not a bug, but a limitation of how computations are performed.

Don`t get me wrong, I want to help you and sorry if I offended you in any way.

Yes. I know it works well in its own way, but what if there is more resiliency in this language
to prevent this kind of hazards.

@jarkky

but again, how could Octave guess if what I want is

``````>> atan(1/0)
``````

or

``````>> atan(1)/0
``````

???

Octave is just doing what I’m telling it to do.

Another example:
this:

``````(1+3^2)/2
``````

or this

``````(1+3^2/2)
``````

which one is the “correct” one? Suppose that you are Octave. Will you show to me any kind of warning?

Perhaps you want a better Code Editor that highlight ( [ { and } ] ) even more?

Problem is resiliency of the languge. It can not be fixed maybe…
Only debug only it is found.

@jarkky

Could you provide a full example of what behavior you would like to see? What kind of warning Octave should print?

I understand that you would like to see a different character for functions, like you wrote

``````atan[x]
``````

but, will this conflict with something else?

To give a warning when it is missing some (, ), [, ], { or }, is easy and Octave already do this. However, how can a programming language “know” the correct place of a particular “)” when several places are possible? Are there any language that do this? I would like to know.

It looks working now…
case1.m (336 Bytes)