ozankabak commented on code in PR #6925:
URL: https://github.com/apache/arrow-datafusion/pull/6925#discussion_r1261056243


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -497,6 +497,46 @@ pub fn log(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+pub fn cot(args: &[ArrayRef]) -> Result<ArrayRef> {
+    match args[0].data_type() {
+        DataType::Float64 => Ok(Arc::new(make_function_inputs2!(
+            &args[0],
+            &args[0],
+            "x",
+            "y",
+            Float64Array,
+            Float64Array,
+            { compute_cot64 }
+        )) as ArrayRef),
+
+        DataType::Float32 => Ok(Arc::new(make_function_inputs2!(
+            &args[0],
+            &args[0],
+            "x",
+            "y",
+            Float32Array,
+            Float32Array,
+            { compute_cot32 }
+        )) as ArrayRef),
+
+        other => Err(DataFusionError::Internal(format!(
+            "Unsupported data type {other:?} for function cot"
+        ))),
+    }
+}
+
+fn compute_cot32(x: f32, y: f32) -> f32 {
+    let a = f32::sin(x);
+    let b = f32::cos(y);
+    b / a
+}
+
+fn compute_cot64(x: f64, y: f64) -> f64 {
+    let a = f64::sin(x);
+    let b = f64::cos(y);
+    b / a
+}

Review Comment:
   Is there a specific reason why you are not using the reciprocal of `tan`? It 
would probably be ~2x as fast and have less numerical error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to