Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

cant print out large numbers that are in spinners.

cant print out large numbers that are in spinners.

Anonymous
Not applicable
605 Views
7 Replies
Message 1 of 8

cant print out large numbers that are in spinners.

Anonymous
Not applicable


---QUESTTION: How come when I create a button to print the value of the spinner it only shows 6 digits instead of all of them that are in
---the spinner?
--If I am always limited by 6 digits, is there anyway then I can print out my larger number?
--I would like to have the users be able to type large numbers in a field and then do math on those large numbers.
--If I cant use spinners are their any other methods besides spinners that can handle large numbers like mine?


--thanks

preferences.spinnerPrecision = 10

clearListener()

rollout Menu "Press to Show Spinner Value"
(--open rollout

group "test"

(
spinner SUMark "Mark:" fieldwidth:100 range:[0.000000000,300000.00000,321.234567890] align:#right scale:.0000000001 type:#float
button SUMarkButton "Press Me"
)


on SUMarkButton pressed do
(
print SUMark.value
)

)--close rollout


createDialog Menu width:320 height:100

 




0 Likes
606 Views
7 Replies
Replies (7)
Message 2 of 8

Steve_Curley
Mentor
Mentor
formattedPrint - similar options to C's printf.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 8

Anonymous
Not applicable
Thanks Steve I got that to work. Do you know what I would have to do to make it double precision? Here is what I have so far. Since the numbers in the spinners may change I cant work directly with that number in the code I have to work with SUMark.value
Any suggestions on the procedure? Thanks


preferences.spinnerPrecision = 10

clearListener()

rollout Menu "Press to Show Spinner Value"
(--open rollout

group "test"

(
spinner SUMark "Mark:" fieldwidth:100 range:[0.000000000,900000.00000,0] align:#right scale:.0000000001 type:#float
button SUMarkButton "Press Me"
)

on SUMarkButton pressed do
(

fn F val = (formattedPrint val format:"-15.13g")
 format "SUMark.value = %\n" (F SUMark.value)---this works and prints out SUMark.value = 123.4567871094 but I need it to be double precision
 
 --format "SUMark.value = %\n" (F SUMark.value as double)   ---does not work trying to make double..shows error SUMark.value = undefined

--SUMark.value as double--does not work--I think becuase it is not a number

)

)--close rollout


createDialog Menu width:320 height:100


--- 123.456789  the number I put in spinner for testing

 

0 Likes
Message 4 of 8

Steve_Curley
Mentor
Mentor
I'll have a look later - bit busy with work at the moment. Before I do though, it would be useful to know why you need such large values with such accuracy. Max generally doesn't use doubles, it uses single precision, so any normal Max operations such as positions and rotations are going to get horribly truncated when you use them. I have a suspicion that your system units are way off - trying to model the entire world in mm for example. If you're trying to use Maxscript for a job which is unrelated to Max (using it as a general programming language) then there are better options out there.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 8

Anonymous
Not applicable

I am calculating "true anomaly" angles relating to orbital mechnics ellipses. My units are in km.I have it working so far pretty well with single point precision but either due to rounding accumulating errors or the rotation truncating effect your refering to, the true anomaly angles are not adding up to 360 degrees so my 3d modeled markers are not being placed accuratly. At mid rotation point they add up to 179.5 degrees which is very good(it should add up to 180 here though) but near completion they are adding up to like 350 instead of 360 degrees which is not good.

Even if there is some truncating going on if I can at least get something better than single point precision like double it may be worth it.  I will probably do some  testing today with real numbers to see if I will benefit from double point precision. I know how to make that work in code. I was hoping though I could allow the user to put in their own numbers through using spinners as opposed to having them change numbers in code. This project is related to max though although it might not seem so.

In another post kind of related to this one,swordslayer mentioned maybe I should use edittext fields intead of spinners? I am not sure. Thanks for any suggestions or help when you have the time. Maybe you can elaborate to me more on the truncating effect you refer to. How does that happen?

0 Likes
Message 6 of 8

Swordslayer
Advisor
Advisor

It would be helpful if you could attach that part of code where the error accumulates. Without that it's pure guesswork, you might be for example using max vectors (only single-precision floats) or some built-in functions that also return only single-precision floats as their result. Anyway, the bigger the numbers, the bigger is the imprecision, for celestial bodies you might even want to set system units to millions of kilometers - but if you really need precision, consider using some external library for the calculations.

0 Likes
Message 7 of 8

Anonymous
Not applicable

I will post it if I can narrow down to where the problem is.

Basically the script incrementally loops by percentage of whole time.1% then 2% etc of the whole. Each increment goes through 5 formulas to get a result.  If I manually do it instead, meaning not use incrementation the numbers come out as predicted and accurate enough for me. But when I put the whole procedure in a loop that increments the numbers get rounded off in subtle but unpredictable ways so final answers dont come out right.

 

Do you know if using incrementing with math formulas can mess them up? like round them off differently? I am speaking of the math part only in maxscripts.

The 5 formulas work correctly as a group returning a good result. They just change though when incremented as a part of the whole script. Hope this makes sense.

thanks

0 Likes
Message 8 of 8

Swordslayer
Advisor
Advisor

Without knowing the numbers and seeing the loop, I can't tell you much. It all boils down to how you increment the numbers, if you are using big and small numbers together and what the desired precision is. Post some inputs and expected outputs and a code and we will see.

0 Likes