-
Notifications
You must be signed in to change notification settings - Fork 71
/
CFloatArray.class.st
50 lines (45 loc) · 1.43 KB
/
CFloatArray.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"
A CFloatArray is a subclass of CArray that provides access via C float or double values
"
Class {
#name : #CFloatArray,
#superclass : #CArray,
#category : #'Slang-Types'
}
{ #category : #converting }
CFloatArray >> asNonFloatAccessor [
| accessor |
CArray adoptInstance: (accessor := self shallowCopy unitSize: 8).
^accessor
]
{ #category : #accessing }
CFloatArray >> at: offset [
| address |
address := unitSize * offset + self ptrAddress.
^unitSize >= 4
ifTrue:
[unitSize = 4
ifTrue: [Float fromIEEE32Bit: (interpreter long32At: address)]
ifFalse: [Float fromIEEE64BitWord: (interpreter long64At: address)]]
ifFalse:
[self error: 'unitSize must be 4 or 8']
]
{ #category : #accessing }
CFloatArray >> at: offset put: val [
| address |
address := unitSize * offset + self ptrAddress.
^unitSize >= 4
ifTrue:
[unitSize = 4
ifTrue: [interpreter long32At: address put: (val isFloat ifTrue: [val asIEEE32BitWord] ifFalse: [val])]
ifFalse: [interpreter long64At: address put: (val isFloat ifTrue: [val asIEEE64BitWord] ifFalse: [val])]]
ifFalse:
[self error: 'unitSize must be 4 or 8']
]
{ #category : #converting }
CFloatArray >> coerceTo: cTypeString sim: interpreterSimulator [
^cTypeString caseOf: {
['float *'] -> [self shallowCopy unitSize: 4; yourself].
['double *'] -> [self shallowCopy unitSize: 8; yourself] }
otherwise: [self asNonFloatAccessor coerceTo: cTypeString sim: interpreterSimulator]
]