Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:21:01+00:00 2026-06-07T16:21:01+00:00

before I get into my problem, I want to point out a couple of

  • 0

before I get into my problem, I want to point out a couple of things: 1)I know there is already an atan2 function in the cmath library, this is purely as an exercise and for my own practice, and 2) I know that the code does not account for 0.

ok, so tan(theta) = y / x, where y and x are coordinates on a plane… that means:

theta = atan(y/x) in Quads I and IV, and
theta = atan(y/x) + 180 in Quads II and III

so why when I use the following code:

float atan(float y, float x)
 {
 float result = 0.0f;

if (x > 0) //quads I and IV if x is positive
 { 
result = atanf(y/x);
 }
 else if (x < 0)
 {
 result = atan(y/x) + 180; //quads II and III if x is negative
 }

return result;

 }

does it spit me junk?
example, for coordinates (-4,4) it gave me the result of: 179.215, when it should be 135:

atan(4/-4) = -45 degrees + 180 degrees = 135 degrees

but what’s happening is it is computing

atan(4.0f/-4.0f) = -0.785398 + 180 degrees = 179.215.

am I missing some step here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:21:03+00:00Added an answer on June 7, 2026 at 4:21 pm

    The standard atan and atan2 functions, as well as all other C functions that work with angles, work with radians, not degrees.

    If you want your own function to output degrees, you have to multiply the return value from atanf with 180/pi; to keep everything in radians, add pi instead of 180.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the e.result before it pumps data into my listbox..I want
Before I go into detail I'll get right to the point: has anyone figured
Before I dive into my question, I wanted to point out that I am
I'm writing a class to insert users into a database, and before I get
I know this has been asked before ( Get Absolute Position of element within
Before I get anywhere with this post, let me make this clear, there is
Ok, before I get a ton of responses. I know you cannot talk to
I need some help, and before we get going, I know it is probably
First of all, I want to make something clear before I get yelled at:
Before i start i will divide the problem into two parties: PART 1 :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.