Mathematic question

uint32_t sq(uint32_t x){
uint32_t y = x*x;
return y;
}

Are you on a Linux machine?

Yes. Are you thinking the OP is on a Windows box, where Math.h is considered the same as math.h? That's entirely possible.

Yes or a Mac as well.

2 Likes

A Mac as well? Really? I won't die today, I learned something new. :slight_smile: I did not know that!

It might just be for the Arduino IDE because for many things a Mac is case sensitive or maybe it depends on how you format the drive but in this case "yes." :grinning:

thank you all for your opinions.
I am solving a problem with the gyroscope (reaction to body tilt) in the Hexapod Spider Robot.
Link: Hexapod Spider Robot

Thanks, missed that.

We have a <math.h> but no "Math.h"
Then you get square(x)

see post #18

That depends on your computer's file system. Linux is case sensitive, Windows and Mac are not.

Running Raspbian Linux here. Windoze sucks.

Is <Math.h> the same as "Math.h" in Gatesworld?

I just wonder since the square(x) function is defined in the Arduino math.h library as documented and this Snipe Hunt seems pointless!

<Math.h> and "Math.h" is the same in Windows as it is in Linux as far as the Arduino IDE is concerned, but I suspect that is not the question that you intended to ask

1 Like

Then why the posts declaring there is no square(x) function?

The square() function is in the math.h file is in C:\Users\micro\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\math.h on my Windows11 PC and only that file. Windows almost certainly accepts Math.h and math.h as the filename

Noting that the folder appears to relate to AVR chips, then could that be significant as the function may not be available to all boards ?

If not on an AVR board, then go with the C++ standard library:

#include <cmath>

Then:

  angel_x  = std::abs(std::atan2(ax, std::hypot(ay, az))) * 180 / M_PI;

The docs I linked are on AVR LibC so it's just possible no one went to the trouble for AMD's. It's not like we need that as a function, have a hard time coding x * x!

It looks like the square() function is only available in some board packages math.h library

This sketch

#include <Math.h>

void setup()
{
    Serial.begin(115200);
    Serial.println(square(10));
}

void loop()
{
}

compiles and runs with a classic Nano board selected but not with an ESP32 Dev Module selected. Windows not caring about upper/lowercase is a red herring

And since, ~sigh~ it is impossible to just add a function to a library... this non-problem can never be solved!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.