Board index FlightGear Development Nasal

Nasal: floating point error in math.pow()

Nasal is the scripting language of FlightGear.

Nasal: floating point error in math.pow()

Postby Necolatis » Fri Nov 22, 2019 11:37 pm

I get this error: floating point error in math.pow()

The line has math.pow(a,2)

Does this mean 'a' is a NaN? And is there any way to check in Nasal if a variable is NaN?
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2044
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2019.1.2
OS: Windows 10

Re: Nasal: floating point error in math.pow()

Postby wkitty42 » Sat Nov 23, 2019 12:11 am

can you add a quick debug print line before that line to print out the value of 'a'?
i'm not sure if there is an isNAN() routine or not... i know there is something in javascript which i use in another life...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5883
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Nasal: floating point error in math.pow()

Postby Necolatis » Sat Nov 23, 2019 12:15 am

That would flood the console. It gets called maybe 10000 times per flight until at some point the error might pop up.
Its hard to reproduce too.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2044
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2019.1.2
OS: Windows 10

Re: Nasal: floating point error in math.pow()

Postby Richard » Sat Nov 23, 2019 12:10 pm

this error is coming from some post calculation validation in simgear\nasal\mathlib.c - not sure if valid to check FP numbers like this.

Code: Select all
// Toss a runtime error for any NaN or Inf values produced.  Note that
// this assumes an IEEE 754 format.
#define VALIDATE(r) (valid(r.num) ? (r) : die(c, __FUNCTION__+2))

static int valid(double d)
{
    union { double d; unsigned long long ull; } u;
    u.d = d;
    return ((u.ull >> 52) & 0x7ff) != 0x7ff;
}

static naRef die(naContext c, const char* fn)
{
    naRuntimeError(c, "floating point error in math.%s()", fn);
    return naNil();
}
Richard
 
Posts: 732
Joined: Sun Nov 02, 2014 10:17 pm
Version: Git
OS: Win10

Re: Nasal: floating point error in math.pow()

Postby xcvb » Sat Nov 23, 2019 12:46 pm

I wonder why the standard macro isfinite isn't used here.
xcvb
 
Posts: 107
Joined: Sat Mar 14, 2015 2:08 pm
Version: GIT
OS: Linux

Re: Nasal: floating point error in math.pow()

Postby Necolatis » Sat Nov 23, 2019 1:41 pm

Thanks Richard, that confirmed my suspicion.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2044
Joined: Mon Oct 29, 2012 12:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2019.1.2
OS: Windows 10


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest