Input queries

14 views
Skip to first unread message

Abhishek Ballaney

unread,
Mar 21, 2013, 1:16:18 AM3/21/13
to libfi...@googlegroups.com
Hi all,

What input range can i give to functions fix16_sin, fix16_cos, fix16_atan2?  Give some example to explain.  How do i convert my float radian angle to fix16_t data type?

Regards,
abhishek

Ben Brewer

unread,
Mar 21, 2013, 4:13:33 PM3/21/13
to libfi...@googlegroups.com
Hey Abhishek,
The fixed functions take radians too so all you need to convert
floats to fixes is to use the fix16_to_float function.

The inputs are normalized to the best range for accuracy anyway so any
number that can convert to a fix16 losslessly will work fine, that's any
number between -32768.0 and 32767.999984741.

Hope that helps,
Ben Brewer (aka Flatmush)
> --
> You received this message because you are subscribed to the Google
> Groups "libfixmath" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to libfixmath+...@googlegroups.com.
> To post to this group, send email to libfi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/libfixmath?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Abhishek Ballaney

unread,
Apr 9, 2013, 7:13:20 AM4/9/13
to libfi...@googlegroups.com
Hi all,

i want to use atan2 function.  i'm calling it like this for 30 degree

angle = fix16_atan2(1, sqrt(3))

So angle should have value 34315.  But am not getting this value.  Pl. help.

Regards,
abhishek


On Fri, Mar 22, 2013 at 1:43 AM, Ben Brewer <flat...@googlemail.com> wrote:
Hey Abhishek,
    The fixed functions take radians too so all you need to convert floats to fixes is to use the fix16_to_float function.

The inputs are normalized to the best range for accuracy anyway so any number that can convert to a fix16 losslessly will work fine, that's any number between -32768.0 and 32767.999984741.

Hope that helps,
Ben Brewer (aka Flatmush)

On 21/03/13 05:16, Abhishek Ballaney wrote:
Hi all,

What input range can i give to functions fix16_sin, fix16_cos, fix16_atan2?  Give some example to explain.  How do i convert my float radian angle to fix16_t data type?

Regards,
abhishek

--
You received this message because you are subscribed to the Google Groups "libfixmath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libfixmath+unsubscribe@googlegroups.com.

To post to this group, send email to libfi...@googlegroups.com.
Visit this group at http://groups.google.com/group/libfixmath?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to a topic in the Google Groups "libfixmath" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/libfixmath/xBml3Nx0I7o/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to libfixmath+unsubscribe@googlegroups.com.

Ben Brewer

unread,
Apr 9, 2013, 4:35:22 PM4/9/13
to libfi...@googlegroups.com
Hey Abhishek,
    Your problem is that you assume that your compiler will automatically cast ints and floats into fix16's, this is partially true for C++ and completely incorrect for C.

In C++ ints are converted directly so you can't really use them interchangeably yet, this is already a known issue and there's no easy solution for now so you must ALWAYS use proper casting to get fix16's from any other type.

In this case I'm going to assume you're using C instead of C++.

So in the following you have a number of errors:
    angle = fix16_atan2(1, sqrt(3))

1. You're using 1 instead of fix16_one, fix16_from_dbl(1.0) or any of the other valid representations of 1.0 in fix16.

2. You're invoking libmath double square root on an integer and then using it as a fix16 result, this should instead be:
    fix16_sqrt(fix16_from_int(3))


Hope that helps,
Ben Brewer (aka Flatmush)

On 09/04/13 12:13, Abhishek Ballaney wrote:
Hi all,

i want to use atan2 function.  i'm calling it like this for 30 degree

angle = fix16_atan2(1, sqrt(3))

So angle should have value 34315.  But am not getting this value.  Pl. help.

Regards,
abhishek
On Fri, Mar 22, 2013 at 1:43 AM, Ben Brewer <flat...@googlemail.com> wrote:
Hey Abhishek,
    The fixed functions take radians too so all you need to convert floats to fixes is to use the fix16_to_float function.

The inputs are normalized to the best range for accuracy anyway so any number that can convert to a fix16 losslessly will work fine, that's any number between -32768.0 and 32767.999984741.

Hope that helps,
Ben Brewer (aka Flatmush)

On 21/03/13 05:16, Abhishek Ballaney wrote:
Hi all,

What input range can i give to functions fix16_sin, fix16_cos, fix16_atan2?  Give some example to explain.  How do i convert my float radian angle to fix16_t data type?

Regards,
abhishek

--
You received this message because you are subscribed to the Google Groups "libfixmath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libfixmath+...@googlegroups.com.

To post to this group, send email to libfi...@googlegroups.com.
Visit this group at http://groups.google.com/group/libfixmath?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to a topic in the Google Groups "libfixmath" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/libfixmath/xBml3Nx0I7o/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to libfixmath+...@googlegroups.com.

To post to this group, send email to libfi...@googlegroups.com.
Visit this group at http://groups.google.com/group/libfixmath?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




--
You received this message because you are subscribed to the Google Groups "libfixmath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libfixmath+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages