This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,16 @@ pub enum MathInstruction {
97
97
argument : f32 ,
98
98
} ,
99
99
100
+ /// Pow two float values
101
+ ///
102
+ /// No accounts required for this instruction
103
+ F64Pow {
104
+ /// The base
105
+ base : f64 ,
106
+ /// The exponent
107
+ exponent : f64 ,
108
+ } ,
109
+
100
110
/// Don't do anything for comparison
101
111
///
102
112
/// No accounts required for this instruction
@@ -219,6 +229,17 @@ pub fn f32_normal_cdf(argument: f32) -> Instruction {
219
229
}
220
230
}
221
231
232
+ /// Create F64Pow instruction
233
+ pub fn f64_pow ( base : f64 , exponent : f64 ) -> Instruction {
234
+ Instruction {
235
+ program_id : id ( ) ,
236
+ accounts : vec ! [ ] ,
237
+ data : MathInstruction :: F64Pow { base, exponent }
238
+ . try_to_vec ( )
239
+ . unwrap ( ) ,
240
+ }
241
+ }
242
+
222
243
/// Create Noop instruction
223
244
pub fn noop ( ) -> Instruction {
224
245
Instruction {
Original file line number Diff line number Diff line change @@ -145,6 +145,15 @@ pub fn process_instruction(
145
145
msg ! ( "{}" , result as u64 ) ;
146
146
Ok ( ( ) )
147
147
}
148
+ MathInstruction :: F64Pow { base, exponent } => {
149
+ msg ! ( "Calculating f64 Pow" ) ;
150
+ sol_log_compute_units ( ) ;
151
+ let _result = base. powi ( 5 ) ; // ok
152
+ let result = base. powf ( exponent) ; // symbol not found
153
+ sol_log_compute_units ( ) ;
154
+ msg ! ( "{}" , result as u64 ) ;
155
+ Ok ( ( ) )
156
+ }
148
157
MathInstruction :: Noop => {
149
158
msg ! ( "Do nothing" ) ;
150
159
msg ! ( "{}" , 0_u64 ) ;
Original file line number Diff line number Diff line change @@ -194,6 +194,22 @@ async fn test_f32_normal_cdf() {
194
194
banks_client. process_transaction ( transaction) . await . unwrap ( ) ;
195
195
}
196
196
197
+ #[ tokio:: test]
198
+ async fn test_f64_pow ( ) {
199
+ let mut pc = ProgramTest :: new ( "spl_math" , id ( ) , processor ! ( process_instruction) ) ;
200
+
201
+ pc. set_bpf_compute_max_units ( 30_000 ) ;
202
+
203
+ let ( mut banks_client, payer, recent_blockhash) = pc. start ( ) . await ;
204
+
205
+ let mut transaction = Transaction :: new_with_payer (
206
+ & [ instruction:: f64_pow ( 50_f64 , 10.5_f64 ) ] ,
207
+ Some ( & payer. pubkey ( ) ) ,
208
+ ) ;
209
+ transaction. sign ( & [ & payer] , recent_blockhash) ;
210
+ banks_client. process_transaction ( transaction) . await . unwrap ( ) ;
211
+ }
212
+
197
213
#[ tokio:: test]
198
214
async fn test_noop ( ) {
199
215
let mut pc = ProgramTest :: new ( "spl_math" , id ( ) , processor ! ( process_instruction) ) ;
You can’t perform that action at this time.
0 commit comments