Quantcast

Floating point conversion problem on big endian architecture

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Floating point conversion problem on big endian architecture

Stefan Hudelmaier
Hi,

we're cross compiling Erlang/OTP on a x86 PC for ARM. On the resulting
runtime on ARM we have the following strange problem: Converting float
to binary seems to work fine, exactly as on x86:

 > B = <<3.2:32/big-float>>.
 > io:format("~w~n", [B]).
<<64,76,204,205>>

But converting back to float from this binary, yields the wrong result
on ARM:

 > <<R:32/big-float>> = B.
 > R.
-428443648.0

While on x86, it works as expected:

 > <<R:32/big-float>> = B.
 > R.
3.200000047683716

When compiling for ARM, we have set erl_xcomp_bigendian=yes. hipe is
disabled. We have tried R14A and R14B02.

Please let me know, if there is any more information we need to provide.

Kind regards,
Stefan



--
Device Insight GmbH
Stefan Hudelmaier, Dipl. Inf.
Willy-Brandt-Platz 3
D-81829 München

Tel.: 089 45 45 448 - 34
Email: [hidden email]

http://www.device-insight.com

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point conversion problem on big endian architecture

Mikael Pettersson-3
Stefan Hudelmaier writes:
 > Hi,
 >
 > we're cross compiling Erlang/OTP on a x86 PC for ARM. On the resulting
 > runtime on ARM we have the following strange problem: Converting float
 > to binary seems to work fine, exactly as on x86:
 >
 >  > B = <<3.2:32/big-float>>.
 >  > io:format("~w~n", [B]).
 > <<64,76,204,205>>
 >
 > But converting back to float from this binary, yields the wrong result
 > on ARM:
 >
 >  > <<R:32/big-float>> = B.
 >  > R.
 > -428443648.0
 >
 > While on x86, it works as expected:
 >
 >  > <<R:32/big-float>> = B.
 >  > R.
 > 3.200000047683716
 >
 > When compiling for ARM, we have set erl_xcomp_bigendian=yes. hipe is
 > disabled. We have tried R14A and R14B02.
 >
 > Please let me know, if there is any more information we need to provide.

What's the target platform? OABI or EABI? v5? v7? Thumb? Linux? gcc version?
Hard or soft FP?

Floating-point on OABI with its default FPA format is horribly broken by
design and won't work (I've forgotten if it's big or little endian that
breaks).  Don't go there.

EABI should work.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point conversion problem on big endian architecture

Matthias Lang
In reply to this post by Stefan Hudelmaier
Hi,

Mikael has already answered in general terms. I want to add a specific
counter-example. I cross-compile on x86 to arm, here's what I get:

# uname -a
Linux gth 2.6.36-07957-gb1adc07 #10 Mon Mar 21 14:27:41 CET 2011 armv5tejl GNU/Linux
# erl
Erlang R14B01 (erts-5.8.2) [source] [rq:1] [async-threads:0] [kernel-poll:false]

Eshell V5.8.2  (abort with ^G)
1> B = <<3.2:32/big-float>>, io:format("~w~n", [B]).
<<64,76,204,205>>
ok
2> <<R:32/big-float>> = B, R.
3.200000047683716

The erl-xcomp-armle-linux-gnu.conf I use is the same as the MIPS one
included with R14B01, apart from one line:

  erl_xcomp_host=arm-linux

Matt

----------------------------------------------------------------------

On Thursday, April 07, Stefan Hudelmaier wrote:

> Hi,
>
> we're cross compiling Erlang/OTP on a x86 PC for ARM. On the
> resulting runtime on ARM we have the following strange problem:
> Converting float to binary seems to work fine, exactly as on x86:
>
> > B = <<3.2:32/big-float>>.
> > io:format("~w~n", [B]).
> <<64,76,204,205>>
>
> But converting back to float from this binary, yields the wrong
> result on ARM:
>
> > <<R:32/big-float>> = B.
> > R.
> -428443648.0
>
> While on x86, it works as expected:
>
> > <<R:32/big-float>> = B.
> > R.
> 3.200000047683716
>
> When compiling for ARM, we have set erl_xcomp_bigendian=yes. hipe is
> disabled. We have tried R14A and R14B02.
>
> Please let me know, if there is any more information we need to provide.
>
> Kind regards,
> Stefan
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...