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

About value inaccuracy

For general discussion related FlowStone

Re: About value inaccuracy

Postby martinvicanek » Thu May 12, 2016 12:57 am

Oh, I see, the manual says it can only store floats, float arrays or strings. Hm, you could use strings to encode integers. Or use floats that have an exact machine representation so you can convert them to integers. If you can get away with integers in a range 0...127 (as your example seems to indicate) it should be doable.
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: About value inaccuracy

Postby Tronic » Thu May 12, 2016 2:37 am

example:
@in_float.round(8)

output 100.10212/127.0
(@ins[0].round(8)*127.0).round(5) # >> 100.10212
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: About value inaccuracy

Postby martinvicanek » Thu May 12, 2016 8:00 am

Divide by 128 instead?
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: About value inaccuracy

Postby tulamide » Thu May 12, 2016 11:47 am

Hey Martin,

yes, 128 was one of the "low_bit_count"-dividers I used and it worked like a charme. But, as I said, for 128 values that results in a range of 0.0078125 - 1.0.
These normalized float values are used later on, and they need to be in the range 0.0-1.0, and using another normalizing brings up the "too-many-bits-for-single-precision" issue again.


Hey tronic,

I'm not sure if it will work, but I will give it a try!

EDIT: No, it doesn't work. It just leads to certain integer values not recognized at all. They are just left out. For example 32, 47, 49, 58, etc.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: About value inaccuracy

Postby KG_is_back » Thu May 12, 2016 3:09 pm

This method allows you to store up to 29bit unsigned integer as a float value in 0-1 range. Values lower than 2^24 will be stored as denormals, so it is a thing to consider. It may not be optimal solution, but it works...
In case you need to store more tan 29bits you have to split them into 29bit segments.

Code: Select all
def i_to_f01(n)
   a=(n&(2**29-1)).to_s(2)
   a.insert(-24,"0")
   watch "bin",a+" "+a.length.to_s
   a=a.to_i(2)
   [a].pack("L").unpack("f")[0]
end

def f01_to_i(n)
   a=[n].pack("f").unpack("L")[0]
   a=a.to_s(2)
   a[-24]=""
   a.to_i(2)
end


EDIT: the highest value actually isn't 1 but 0.9999999403953552
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: About value inaccuracy

Postby Tronic » Thu May 12, 2016 4:54 pm

tulamide wrote:Hey tronic,

I'm not sure if it will work, but I will give it a try!

EDIT: No, it doesn't work. It just leads to certain integer values not recognized at all. They are just left out. For example 32, 47, 49, 58, etc.


my solution not work for you?
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: About value inaccuracy

Postby tulamide » Thu May 12, 2016 9:35 pm

@Tronic
Unfortunately it didn't work. As I described, some integers are simply not calculated.

@KG
That's a very interesting bitpacker. I will see if I can implement it.

@all
Many thanks for all your ideas so far! Don't hesitate to post if you came up with another!
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: About value inaccuracy

Postby Tronic » Thu May 12, 2016 10:06 pm

tulamide wrote:@Tronic
Unfortunately it didn't work. As I described, some integers are simply not calculated.

mmm :?
Please, can you show me an not working example?

EDIT: OK, got it, not need anymore, sorry.
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: About value inaccuracy

Postby TheOm » Fri May 13, 2016 8:47 am

You can just directly store an unsigned integer in the range [0, 1065353216] as a float and it will be between 0.0 and 1.0.
Conveniently, this is also the maximum possible number of values that you can store in a single precision float from 0.0 to 1.0 ((2^7 - 1) * 2^23 + 1).
Here is a ruby implementation for signed(range [-532676608, 532676608]) and unsigned ints:

ruby float int.fsm
(630 Bytes) Downloaded 860 times

I have also tested the correctness of this approach for all possible values.
TheOm
 
Posts: 103
Joined: Tue Jan 28, 2014 7:35 pm
Location: Germany

Re: About value inaccuracy

Postby tulamide » Fri May 13, 2016 5:57 pm

I decided to go with the solution provided by KG and TheOm. It does not fulfill all criteria (the range 0.0-1.0 is fixed to 0-1065353216, but I need a smaller integer range), but at least the integers will keep intact and can be saved via preset, and calculating a new float range from integers is not too cpu heavy and can be done on request.

Thanks for all the help! I hope this also showed the issue and that it is more complex than thought.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 55 guests