Host introspection: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (added missing </lang>)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 225:
<lang erlang>endianness() when <<1:4/native-unit:8>> =:= <<1:4/big-unit:8>> -> big;
endianness() -> little.</lang>
 
=={{header|F_Sharp|F#}}==
A lot of research before I finally came up with an answer to this that isn't dependent on the machine it was compiled on. Works on Win32 machines only (obviously, due to the interop). I think that strictly speaking, I should be double checking the OS version before making the call to wow64Process, but I'm not worrying about it.
<lang fsharp>open System
open System.Runtime.InteropServices
open System.Diagnostics
 
[<DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)>]
extern bool IsWow64Process(nativeint hProcess, bool &wow64Process);
 
let answerHostInfo =
let Is64Bit() =
let mutable f64Bit = false;
IsWow64Process(Process.GetCurrentProcess().Handle, &f64Bit) |> ignore
f64Bit
let IsLittleEndian() = BitConverter.IsLittleEndian
(IsLittleEndian(), Is64Bit())</lang>
 
=={{header|Factor}}==
Line 285 ⟶ 302:
</lang>
 
=={{header|F_Sharp|F#}}==
A lot of research before I finally came up with an answer to this that isn't dependent on the machine it was compiled on. Works on Win32 machines only (obviously, due to the interop). I think that strictly speaking, I should be double checking the OS version before making the call to wow64Process, but I'm not worrying about it.
<lang fsharp>open System
open System.Runtime.InteropServices
open System.Diagnostics
 
[<DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)>]
extern bool IsWow64Process(nativeint hProcess, bool &wow64Process);
 
let answerHostInfo =
let Is64Bit() =
let mutable f64Bit = false;
IsWow64Process(Process.GetCurrentProcess().Handle, &f64Bit) |> ignore
f64Bit
let IsLittleEndian() = BitConverter.IsLittleEndian
(IsLittleEndian(), Is64Bit())</lang>
=={{header|Go}}==
<lang go>package main
Line 530 ⟶ 531:
Endianness: little-endian
</pre>
 
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Line 562 ⟶ 564:
Checkit
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>If[$ByteOrdering > 0, Print["Big endian"], Print["Little endian" ]]
Line 600 ⟶ 603:
octave:129> endian
endian = little</pre>
 
 
=={{header|Modula-3}}==
Line 835 ⟶ 837:
UV size: 8, byte order: 87654321 (big-endian)
</pre>
=={{header|Perl 6}}==
Endian detection translated from C. {{works with|Rakudo|2018.03}}
<lang perl6>use NativeCall;
say $*VM.config<ptr_size>;
my $bytes = nativecast(CArray[uint8], CArray[uint16].new(1));
say $bytes[0] ?? "little-endian" !! "big-endian";</lang>
{{out}}
<pre>8
little-endian</pre>
Note: Rakudo 2018.12 is introducing the endian-sensitive<code>read-int16</code> method,
which makes endian detection a little easier:
<lang perl6>say blob8.new(1,0).read-int16(0) == 1 ?? "little-endian" !! "big-endian"</lang>
 
=={{header|Phix}}==
Line 987 ⟶ 977:
(printf "Endianness: ~a\n" (if (system-big-endian?) 'big 'little))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
Endian detection translated from C. {{works with|Rakudo|2018.03}}
<lang perl6>use NativeCall;
say $*VM.config<ptr_size>;
my $bytes = nativecast(CArray[uint8], CArray[uint16].new(1));
say $bytes[0] ?? "little-endian" !! "big-endian";</lang>
{{out}}
<pre>8
little-endian</pre>
Note: Rakudo 2018.12 is introducing the endian-sensitive<code>read-int16</code> method,
which makes endian detection a little easier:
<lang perl6>say blob8.new(1,0).read-int16(0) == 1 ?? "little-endian" !! "big-endian"</lang>
 
=={{header|Retro}}==
10,327

edits