I have the code: void func(glm::vec2 F, double PHI) { glm::vec2 kb = glm::fract((F +…
- User
I have the code: void func(glm::vec2 F, double PHI) { glm::vec2 kb = glm::fract((F + 1.0) * PHI) - (PHI - 1.0); std::cout<<kb.x<<", "<<kb.y; } Please rewrite the code without using glm, just in plain 'double' maths.
- Assistant
Certainly! Here is the rewritten code without using the
glmlibrary, utilizing plaindoublemathematics. The code computes the same values as your original function by breaking down the operations and applying them step by step.#include <iostream> #include <cmath> void func(double F_x, double F_y, double PHI) { // Compute intermediate values double temp_x = (F_x + 1.0) * PHI; double temp_y = (F_y + 1.0) * PHI; // Get the fractional part by subtracting the floor value double fract_x = temp_x - std::floor(temp_x); double fract_y = temp_y - std::floor(temp_y); // Compute kb.x and kb.y without glm::fract and glm vectors double kb_x = fract_x - (PHI - 1.0); double kb_y = fract_y - (PHI - 1.0); // Output the result std::cout << kb_x << ", " << kb_y << std::endl; }