⍝ Conversion to 32-bit binary floats as ⎕DR 83:
:ReturnIf ⎕FR=1287 ⍝ DECF:
:ReturnIf 1 0≡83 ⎕dr 256 ⍝ big-endian
rev ← ⌽⍣(0=⊃83 ⎕dr 256) ⍝ reversal for little-endian machines
⍕rev ↑hex¨↓ 10 4⍴ f32 1 to 10 ⍝ 32-bit floats
3f 80 00 00
40 00 00 00
40 40 00 00
40 80 00 00
40 a0 00 00
40 c0 00 00
40 e0 00 00
41 00 00 00
41 10 00 00
41 20 00 00
x32 ← ↑ ∊∘rev∘hex∘f32¨ ⍝ hex rep of 32-bit float
x32 0 1 ¯2, ÷3 ⍝ Wikipedia examples
00000000
3f800000
c0000000
3eaaaaaa
x64 ← ↑ hexf¨ ⍝ hex rep of 64-bit float
cmp ← x32, ' ', x64 ⍝ 32/64-bit comparison
cmp 1 to 10 ⍝ 1..10
3f800000 3FF0000000000000
40000000 4000000000000000
40400000 4008000000000000
40800000 4010000000000000
40a00000 4014000000000000
40c00000 4018000000000000
40e00000 401C000000000000
41000000 4020000000000000
41100000 4022000000000000
41200000 4024000000000000
cmp 2* 1 to 10 ⍝ 2 4 8 ... 1024
40000000 4000000000000000
40800000 4010000000000000
41000000 4020000000000000
41800000 4030000000000000
42000000 4040000000000000
42800000 4050000000000000
43000000 4060000000000000
43800000 4070000000000000
44000000 4080000000000000
44800000 4090000000000000
cmp * 1 to 10 ⍝ *1, *2, ...
402df854 4005BF0A8B145769
40ec7325 401D8E64B8D4DDAE
41a0af2d 403415E5BF6FB106
425a6481 404B4C902E273A58
431469c4 40628D389970338F
43c9b6e2 407936DC5690C08F
44891442 409122885AAEDDAA
453a4f53 40A749EA7D470C6E
45fd38ab 40BFA7157C470F82
46ac14ee 40D5829DCF950560
⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝
:ReturnIf 'Windows' ≢ {0::0 ⋄ ⊃'.'⎕wg ⍵}'APLVersion' ⍝ Windows only:
⍝ Try Geoff's ⎕NA version:
f32a←{ ⍝ Conversion to 32-bit floats as ⎕DR 83.
bytes←4×≢∊⍵ ⍝ bytes count
xx←⍕{2×⎕SIZE'⍵'}⍬ ⍝ '32' or '64'
libfn←'dyalog',xx,'|MEMCPY' ⍝ library|function name
MEMCPY←⊢ ⍝ local name for ⎕NA'd function
_←⎕NA libfn,' >I1[] <F4[] P' ⍝ link to library fn
MEMCPY bytes(∊⍵)bytes ⍝ conversion of numeric array
}
(f32a ≡ f32) ¯2 to 10 ⍝ comparison with ⎕DR version
1
⍝∇ f32 hex hexf to
Back to: code
Back to: Workspaces