Page 1 of 1

Division Problems

Posted: 27.02.2006, 10:36
by hharris
Anybody but me having division problems? For example

-36.0 / 10000000 gives -0 forcing me to include the statement

if(x == 0) then x = 0 end
in order display zero properly. I don't think a negative zero is defined.

Or worse

3427/10000000 = 1

Is Celx rounding up? Is 10million too large a number? Surely not.

Henry :cry:

Re: Division Problems

Posted: 27.02.2006, 19:40
by hank
hharris wrote:Anybody but me having division problems? For example

-36.0 / 10000000 gives -0 forcing me to include the statement

if(x == 0) then x = 0 end
in order display zero properly. I don't think a negative zero is defined.

Or worse

3427/10000000 = 1

Is Celx rounding up? Is 10million too large a number? Surely not.

Henry :cry:

It works for me.

Code: Select all

  celestia:flash("Testing",5)
  wait(2)

  t = 3427/10000000

  celestia:flash(t,5)
  wait(5)

BTW, it's probably best to post scripting questions in the "Celestia Scripting" topic.

-Hank

Posted: 27.02.2006, 21:27
by hharris
I agree, this could very well be a scripting problem. Let me be a little more explicit. I'll try to follow this strategy from now on (and put my comments in the right section).

I'm running Mac OS X 10.4.5 Celestia 1.4.1(0)

gridthalflength = 10000000.00 --[[ 10 million microlightyears ]]
myPos = obs:getposition() --[[ universal coordinates ]]
x = myPos :getx() --[[ microlightyears --]]
gridx = math.floor(x/ gridthalflength)

The problem I previously reported was solved by using math.floor instead of math.ceil. For large positive numbers less than gridthalflength I correctly get zero, but for very small negative values of x I now get -1. Perhaps I don't understand how these functions are supposed to work. This would be a trivial problem in C++. My intent is to get signed integer grid coordinates as an aid to interstellar navigation.

Thanks for your help

Henry :D

Posted: 01.03.2006, 06:37
by hank
hharris wrote:Perhaps I don't understand how these functions are supposed to work.

The Lua math library is just an interface to the standard C math library.

The 'floor' function returns the largest floating point integer value that is less than or equal to the input parameter. If the input is a negative number with an absolute value less than 1, the 'floor' function returns -1.

- Hank