Board index FlightGear Development Nasal

nasal math.pow() : power of float

Nasal is the scripting language of FlightGear.

nasal math.pow() : power of float

Postby vslash » Thu Dec 14, 2017 9:55 am

Hi,
the nasal math.pow(x,y) where y is a float leads to an error:
Code: Select all
Nasal runtime error: floating point error in math.pow()


ref: https://sourceforge.net/p/flightgear/simgear/ci/next/tree/simgear/nasal/mathlib.c#l68

But the 'c' <math.h> pow functions are defined as:
Code: Select all
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);


So, is there a way to get the same with Nasal where 'y' is rationnal or irrationnal ? (w/o defined my own powf ...)
Thanks,

Val.

[EDIT]
and with have the same with C++ <cmath> where pow is overloaded:
Code: Select all
float pow(float base, int exp);
float pow(float base, float exp);
...
vslash
Retired
 
Posts: 39
Joined: Fri May 27, 2016 10:43 pm
Location: Paris
Callsign: FGX412
IRC name: vslash
OS: BSD

Re: nasal math.pow() : power of float

Postby Necolatis » Thu Dec 14, 2017 12:27 pm

You must have done something wrong, I am using pow with 2 floating point numbers.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: nasal math.pow() : power of float

Postby Necolatis » Thu Dec 14, 2017 1:37 pm

Maybe it cannot handle negative exponent, if that's the case just use the absolute, and take the reciprocal of the final result. Will give same.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: nasal math.pow() : power of float

Postby vslash » Thu Dec 14, 2017 1:50 pm

yep, my bad:
pow(x,y) with x < 0 is not really the best way using pow ! (I was focused on y)
thanks,

Val.
vslash
Retired
 
Posts: 39
Joined: Fri May 27, 2016 10:43 pm
Location: Paris
Callsign: FGX412
IRC name: vslash
OS: BSD


Return to Nasal

Who is online

Users browsing this forum: No registered users and 5 guests