Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

why is this a minus?

For general discussion related FlowStone

why is this a minus?

Postby Jay » Fri Apr 26, 2013 4:36 am

hi all cam anyone tell me why this int multiplication shows as a minus? im confused :lol:

and should it not come out as 2157840000

eh lol..png
eh lol..png (8.7 KiB) Viewed 18247 times
Jay
 
Posts: 276
Joined: Tue Jul 13, 2010 5:42 pm

Re: why is this a minus?

Postby billv » Fri Apr 26, 2013 5:39 am

At first, I thought it was a practical joke, or some guru math trick.....but
Confirmed.
+1. :?
And we can't get inside to fix it..... just send it to DSPR, with a note attached:WTF? :lol: :lol:
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: why is this a minus?

Postby nix » Fri Apr 26, 2013 5:45 am

IMO FS is confused!
User avatar
nix
 
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: why is this a minus?

Postby VPDannyMan » Fri Apr 26, 2013 5:55 am

What is the largest number an integer in FS can hold?
VPDannyMan
 
Posts: 118
Joined: Mon Jan 04, 2010 4:50 am

Re: why is this a minus?

Postby billv » Fri Apr 26, 2013 6:32 am

billv wrote: just send it to DSPR,

on second thought
VPDannyMan wrote:What is the largest number an integer in FS can hold?

A standard 32-bit integer can handle -2,147,483,648 through 2,147,483,647.
I knew it was guru math trick :lol: :lol: thanks for the reminder
thanks VPDannyMan :)
can you tell me why this happens....?? still :?
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: why is this a minus?

Postby nix » Fri Apr 26, 2013 6:40 am

Looks like it has added the irresolvable 10000... to the minimum negative.
Like it has pushed it into a loop,
and restarted it's range from minimum.
Not the ie005 768 or whatever it does with floats.
User avatar
nix
 
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: why is this a minus?

Postby Jay » Fri Apr 26, 2013 11:42 am

ah so it is a little bug! lol i was thinking either my pc had gone wonky or my install had gone south!

tried the same in the ruby box and got these results which are even weirder! but it shows that it is the int system

eh lol 2.png
eh lol 2.png (19.14 KiB) Viewed 18231 times
Jay
 
Posts: 276
Joined: Tue Jul 13, 2010 5:42 pm

Re: why is this a minus?

Postby tester » Fri Apr 26, 2013 12:08 pm

Here is the trick to solve it ;-)

In other words - don't use integers if you don't have to.
Attachments
float-integer.fsm
(278 Bytes) Downloaded 944 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: why is this a minus?

Postby trogluddite » Fri Apr 26, 2013 1:12 pm

Jay wrote:ah so it is a little bug! lol i was thinking either my pc had gone wonky or my install had gone south!

Well, the PC's CPU is doing exactly what it has been told to do.
It attempts the multiplication, and then finds that the result won't fit to 32 bits - so the bits that would represent the bigger number are just lost, leading to the strange results (one of the bits is used to indicate +/- too). It's what's known as an overflow error - trying to "fit a quart into a pint pot."

But there is something being hidden from us.
When this happens inside the CPU, a flag gets set called the "Overflow flag" - and in many PC languages, the programmer would be able to check that flag, and use it to show an error message, or call a special maths routine that could handle a bigger number by splitting the number up into chunks.

Tester's solution works up to a point - but there is still a problem that must be accounted for...
Although the float numbers are alllowed to be much bigger (or smaller), there will be a loss of precision - i.e. the result of the multiplication will be approximately the right size, but not always the exact answer.
It works a little like this...
Lets say you have a very rubbish calculator that could only show you four digits. How would you write 123,000,000?
Ah - there is a way - we can make a rule that says "the last digit is the number of zeros". So the calculator could write it as "1236" - which is the principle of 'scientific notation" or "E notation" (e.g. 1.543e12).
But what about 123,000,001? Well, the best we could do here is to say "the one is so small, let's just ignore it" - and our crappy four digit calculator still writes "1236"
So when using float numbers, above a certain value, you can't represent every single integer value - there's a point where only even numbers can be represented, later, only every fourth one, and so on as the numbers get bigger - which means there can still be maths errors. e.g.
123,000,000 + 1 = 123,000,000 :shock:

So , FS is not really doing much wrong - the way the CPU represents numbers is the biggest part of the limitation. BUT, I do think it would be good if the integer maths primitives showed us the overflow error rather than outputting a confusing value - the same way that floats show us "NF" or "NAN" when there is a float maths problem.

Note that within Ruby, the number ranges are much larger - floats are 64bit rather than 32bit, and integers are also 64bit, but also with a special "BigNum" class than can handle integers of any size (at much greater CPU cost). But once you send those numbers out of Ruby and into the 'green' world, they will again be truncated to the 32bit values.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: why is this a minus?

Postby Jay » Fri Apr 26, 2013 1:30 pm

yeh i know about that tester cheers! but it is no good for what i was doing! that gives a result of 2.15784e+009! it is fine as i was outputting it to a label anyway m8!

also it is not a bug, i understand now! it is the largest number an int32 is capable of!
Jay
 
Posts: 276
Joined: Tue Jul 13, 2010 5:42 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 67 guests

cron