Help for QMC5883L(DB5883)!

Hey everyone I'm working on a project, I have to detect if a magnet or electric wire (which produces a magnetic field) is near the sensor ,I learned form searches that I should find magnetic field strength using raw data of x ,y ,z. And I should use Pythagoras Theorem to find total intensity of magnetic field!
I tried to use this library : GitHub - mechasolution/Mecha_QMC5883L: Arduino lib for QMC5883
From this code I'm getting the data of x, y, z!
I have some questions , is it necessary to calibrate and find offsets of the sensor for my project?
When I use Pythagoras Theorem I=sqrt(pow(x,2)+pow(y,2)+pow(z,2)), as I know I should get a value of 47647.2nT,which is magnetic field strength of my city and it should not change unless I move in great distances or a magnet comes near sensor, but my values change even if I rotate my sensor ,can anyone tell me why is that, is something wrong with the code?
By the way I'm a beginner and this is my first Arduino project, so any help would be welcome!

#include <Wire.h>
#include <MechaQMC5883.h>


MechaQMC5883 qmc;


void setup() {
  Wire.begin();
  Serial.begin(9600);
  qmc.init();
  //qmc.setMode(Mode_Continuous,ODR_200Hz,RNG_2G,OSR_256);
}


void loop() {
  int x,y,z;
  qmc.read(&x,&y,&z);


  Serial.print("x: ");
  Serial.print(x);
  Serial.print(" y: ");
  Serial.print(y);
  Serial.print(" z: ");
  Serial.print(z);
  Serial.println();
  delay(100);
}

is it necessary to calibrate and find offsets of the sensor for my project?

Yes, absolutely.

Here is the most comprehensive calibration tutorial. Search for "arduino calibrate magnetometer" to find many others.

jremington:
Yes, absolutely.

Here is the most comprehensive calibration tutorial. Search for "arduino calibrate magnetometer" to find many others.

Thank you ,I'm going to try that now!

pow(x, 2) is very slow on 8-bit Arduinos, just use x*x to square things.

MarkT:
pow(x, 2) is very slow on 8-bit Arduinos, just use x*x to square things.

Thank you for your help!