Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-25 Thread Vasiliy Tolstov
ср, 24 окт. 2018 г. в 19:52, Michael Jones :
>
> https://en.wikipedia.org/wiki/Q_(number_format) says it all.
>
> you can use fixed point all the way...just shift after multiplies and before 
> divides and use double-width (int32) or wider math.
>

Thanks!

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-25 Thread Michael Jones
Guilty. ;-)

It's also more complicated because of the desire for saturating arithmetic.

On Thu, Oct 25, 2018 at 9:57 AM Scott Cotton  wrote:

>
>
> On Wednesday, 24 October 2018 18:52:27 UTC+2, Michael Jones wrote:
>>
>> https://en.wikipedia.org/wiki/Q_(number_format) says it all.
>>
>> you can use fixed point all the way...just shift after multiplies and
>> before divides and use double-width (int32) or wider math.
>>
>>
> Yes, that's close enough for many purposes.  But it gets more complicated
> with carries/rounding and other functions (such as trig).
>
> Scott
>
>
>
>> On Mon, Oct 22, 2018 at 3:24 PM Vasiliy Tolstov 
>> wrote:
>>
>>> Thanks for suggestions.
>>> If somebody can look at github.com/unistack-org/go-crush package
>>> (ported ceph crush to go) i'l be happy.
>>> Now weight represented as float32, i'm try to use
>>> https://github.com/shopspring/decimal but code looks ugly with many
>>> conversations. And also as i see ceph code (mapper.c for crush) they
>>> does not use something
>>> different for weights but uint32. may be i miss something but i don't
>>> understand how they deal with weights like 0.580 in such cases.
>>> So if somebody wants to help - i'l be happy.
>>> пн, 22 окт. 2018 г. в 17:14, 'Ingo Oeser' via golang-nuts
>>> :
>>> >
>>> > https://godoc.org/golang.org/x/image/math/fixed might provide some
>>> hints how to work with this kind of type.
>>> >
>>> > The idea is to use a special type and provide all operations you need.
>>> >
>>> > https://godoc.org/math/big#Rat might be helpful to create first tests
>>> of the basic math operations with maximum precision, before reducing
>>> precision with a conversion to a more limited data type.
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts...@googlegroups.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>>
>>> --
>>> Vasiliy Tolstov,
>>> e-mail: v.to...@selfip.ru
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>>
>> *Michael T. jonesmichae...@gmail.com*
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-25 Thread Scott Cotton


On Wednesday, 24 October 2018 18:52:27 UTC+2, Michael Jones wrote:
>
> https://en.wikipedia.org/wiki/Q_(number_format) says it all.
>
> you can use fixed point all the way...just shift after multiplies and 
> before divides and use double-width (int32) or wider math.
>
>
Yes, that's close enough for many purposes.  But it gets more complicated 
with carries/rounding and other functions (such as trig).

Scott 

 

> On Mon, Oct 22, 2018 at 3:24 PM Vasiliy Tolstov  > wrote:
>
>> Thanks for suggestions.
>> If somebody can look at github.com/unistack-org/go-crush package
>> (ported ceph crush to go) i'l be happy.
>> Now weight represented as float32, i'm try to use
>> https://github.com/shopspring/decimal but code looks ugly with many
>> conversations. And also as i see ceph code (mapper.c for crush) they
>> does not use something
>> different for weights but uint32. may be i miss something but i don't
>> understand how they deal with weights like 0.580 in such cases.
>> So if somebody wants to help - i'l be happy.
>> пн, 22 окт. 2018 г. в 17:14, 'Ingo Oeser' via golang-nuts
>> >:
>> >
>> > https://godoc.org/golang.org/x/image/math/fixed might provide some 
>> hints how to work with this kind of type.
>> >
>> > The idea is to use a special type and provide all operations you need.
>> >
>> > https://godoc.org/math/big#Rat might be helpful to create first tests 
>> of the basic math operations with maximum precision, before reducing 
>> precision with a conversion to a more limited data type.
>> >
>> > --
>> > You received this message because you are subscribed to the Google 
>> Groups "golang-nuts" group.
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to golang-nuts...@googlegroups.com .
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> Vasiliy Tolstov,
>> e-mail: v.to...@selfip.ru 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
>
> *Michael T. jonesmichae...@gmail.com *
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-24 Thread Michael Jones
https://en.wikipedia.org/wiki/Q_(number_format) says it all.

you can use fixed point all the way...just shift after multiplies and
before divides and use double-width (int32) or wider math.

On Mon, Oct 22, 2018 at 3:24 PM Vasiliy Tolstov  wrote:

> Thanks for suggestions.
> If somebody can look at github.com/unistack-org/go-crush package
> (ported ceph crush to go) i'l be happy.
> Now weight represented as float32, i'm try to use
> https://github.com/shopspring/decimal but code looks ugly with many
> conversations. And also as i see ceph code (mapper.c for crush) they
> does not use something
> different for weights but uint32. may be i miss something but i don't
> understand how they deal with weights like 0.580 in such cases.
> So if somebody wants to help - i'l be happy.
> пн, 22 окт. 2018 г. в 17:14, 'Ingo Oeser' via golang-nuts
> :
> >
> > https://godoc.org/golang.org/x/image/math/fixed might provide some
> hints how to work with this kind of type.
> >
> > The idea is to use a special type and provide all operations you need.
> >
> > https://godoc.org/math/big#Rat might be helpful to create first tests
> of the basic math operations with maximum precision, before reducing
> precision with a conversion to a more limited data type.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Vasiliy Tolstov,
> e-mail: v.tols...@selfip.ru
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-22 Thread Vasiliy Tolstov
Thanks for suggestions.
If somebody can look at github.com/unistack-org/go-crush package
(ported ceph crush to go) i'l be happy.
Now weight represented as float32, i'm try to use
https://github.com/shopspring/decimal but code looks ugly with many
conversations. And also as i see ceph code (mapper.c for crush) they
does not use something
different for weights but uint32. may be i miss something but i don't
understand how they deal with weights like 0.580 in such cases.
So if somebody wants to help - i'l be happy.
пн, 22 окт. 2018 г. в 17:14, 'Ingo Oeser' via golang-nuts
:
>
> https://godoc.org/golang.org/x/image/math/fixed might provide some hints how 
> to work with this kind of type.
>
> The idea is to use a special type and provide all operations you need.
>
> https://godoc.org/math/big#Rat might be helpful to create first tests of the 
> basic math operations with maximum precision, before reducing precision with 
> a conversion to a more limited data type.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Q16.16 fixed point numbers in go

2018-10-22 Thread 'Ingo Oeser' via golang-nuts
https://godoc.org/golang.org/x/image/math/fixed might provide some hints how to 
work with this kind of type.

The idea is to use a special type and provide all operations you need.

https://godoc.org/math/big#Rat might be helpful to create first tests of the 
basic math operations with maximum precision, before reducing precision with a 
conversion to a more limited data type. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-22 Thread Vasiliy Tolstov
Does it possible to avoid conversation and works only with fixed point
(if this can bring performance speedup)?
пн, 22 окт. 2018 г. в 16:13, Vasiliy Tolstov :
>
> пн, 22 окт. 2018 г. в 16:02, Jan Mercl <0xj...@gmail.com>:
> >
> > On Mon, Oct 22, 2018 at 2:35 PM Vasiliy Tolstov  wrote:
> >
> > > Does reading this 4 bytes to uint32 and use math.Float32frombits looks 
> > > right?
> >
> > It does not look right, see 
> > https://en.wikipedia.org/wiki/Q_(number_format)#Q_to_float
>
>
> Thanks, so i need to read uint16 Num and uint16 Exp?
> After that  use number Num*2−exp ?
>
> --
> Vasiliy Tolstov,
> e-mail: v.tols...@selfip.ru



-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-22 Thread Vasiliy Tolstov
пн, 22 окт. 2018 г. в 16:02, Jan Mercl <0xj...@gmail.com>:
>
> On Mon, Oct 22, 2018 at 2:35 PM Vasiliy Tolstov  wrote:
>
> > Does reading this 4 bytes to uint32 and use math.Float32frombits looks 
> > right?
>
> It does not look right, see 
> https://en.wikipedia.org/wiki/Q_(number_format)#Q_to_float


Thanks, so i need to read uint16 Num and uint16 Exp?
After that  use number Num*2−exp ?

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Q16.16 fixed point numbers in go

2018-10-22 Thread Jan Mercl
On Mon, Oct 22, 2018 at 2:35 PM Vasiliy Tolstov  wrote:

> Does reading this 4 bytes to uint32 and use math.Float32frombits looks
right?

It does not look right, see
https://en.wikipedia.org/wiki/Q_(number_format)#Q_to_float

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Q16.16 fixed point numbers in go

2018-10-22 Thread Vasiliy Tolstov
Hi! I have some binary format that contains in 4 bytes Q16.16 fixed
point number in LittleEndian. Does reading this 4 bytes to uint32 and
use math.Float32frombits looks right? And also as i understand if in
my code i use float32 i have performance decrease vs if i work with
fixed point int?


-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.