Jump to content

Variable::mod(): bad operands double and double


photo

Recommended Posts

Is it possible to use mod function with float numbers? I get an error: Variable::mod(): bad operands double and double.

I try round my numbers and use this function with int numbers:

	float normalRelativeAngle(float angle)
	{
		int angleInt = round(angle * 1000);
		int pi2Int = round(PI2 * 1000);

		int result = angleInt % pi2Int;

		log.message("angleInt=" + angleInt + ", pi2Int=" + pi2Int);

		return (result / 1000.0f);
	}

	int round(float value)
	{
		int result;

		if (value < 0)
		{
			result = ceil(value - 0.5);
		}
		else
		{
			result = floor(value + 0.5);
		}

		return result;
	};

I have the same error, although I convert float numbers to int number

Link to comment

Is it possible to use mod function with float numbers? I get an error: Variable::mod(): bad operands double and double.

I try round my numbers and use this function with int numbers:

	float normalRelativeAngle(float angle)
	{
		int angleInt = round(angle * 1000);
		int pi2Int = round(PI2 * 1000);

		int result = angleInt % pi2Int;

		log.message("angleInt=" + angleInt + ", pi2Int=" + pi2Int);

		return (result / 1000.0f);
	}

	int round(float value)
	{
		int result;

		if (value < 0)
		{
			result = ceil(value - 0.5);
		}
		else
		{
			result = floor(value + 0.5);
		}

		return result;
	};

I have the same error, although I convert float numbers to int number

 

Please, see the documentation articles: Programming / UnigineScript language / Operators / Numerical Operators and Programming / UnigineScript language / Core Script Library / Math Common Functions.

You have to cast result variable to int explicitly.

return int(result);

Link to comment

Ok... strange, in documentation about ceil says:

The type of returned value will depend on the argument type:

int for int, long, float arguments

 

About floor only:

Largest integer value not greater than arg.

 

So ceil/floor functions dont do type conversion?

Link to comment

Sorry, it seems that documentation in SDK is outdated:

 

variable ceil(variable arg)

 

Description

Ceiling function that returns the smallest integral value that is not less than arg. For vectors ceiling values are obtained per component.

 

Arguments

variable arg - Argument. Can be the following types:

 

* int

* long

* float

* double

* vec3

* vec4

* dvec3

* dvec4

 

Return value

Smallest integer value not less than arg. The type of returned value will depend on the argument type:

 

* float for int, long, float arguments

* double for double arguments

* vec4 for vec4 arguments

* dvec3 for dvec3 arguments

* dvec4 for dvec4 arguments

 

Examples:

float a = ceil(2.3) // a = 3.0

 

 

variable floor(variable arg)

 

Description

Round an argument down to the nearest integer. For vectors values are obtained per component.

Arguments

variable arg - Argument. Can be the following types:

 

* int

* long

* float

* double

* vec3

* vec4

* dvec3

* dvec4

 

Return value

Largest integer value not greater than arg. The type of returned value will depend on the argument type:

 

* float for int, long, float arguments

* double for double arguments

* vec4 for vec4 arguments

* dvec3 for dvec3 arguments

* dvec4 for dvec4 arguments

 

Examples

float a = floor(2.3) // a = 2.0

Link to comment
×
×
  • Create New...