COS function
PRO BASIC
The COS function in Jspreadsheet Formulas Pro is a mathematical function that allows you to calculate the cosine of a specific angle. The angle should be provided in radians, not degrees. Simply enter the angle into the function and it will return the cosine value. This is particularly useful for various calculations in fields like physics, engineering, and computer graphics.
Documentation
Returns the cosine of an angle provided in radians.
Category
Math and trigonometry
Syntax
COS(number)
| Parameter | Description |
|---|---|
number |
A numeric value representing the angle in radians. |
Behavior
The COS function calculates the cosine of the given angle. The angle should be provided in radians. Here are some common behaviors:
- Empty cells: If the referenced cell is empty, the function typically returns 0 (interpreted as
COS(0)) - Text: The
COSfunction cannot process text. If a text string is provided as an input, the function will return an error. - Booleans: If a Boolean value (TRUE or FALSE) is provided as input, the function will interpret TRUE as 1 and FALSE as 0, and it will compute the cosine of these values.
- Errors: If the cell to which the
COSfunction is applied contains an error, the function will also return an error. - Non-numeric values: The
COSfunction expects a numeric value (in radians) as input. If a non-numeric value is provided, the function will return an error.
Common Errors
| Error | Description |
|---|---|
| #VALUE! | This error is displayed when the input to the COS function is non-numeric, such as a text string. |
Best practices
- Always ensure that the input to the
COSfunction is a numeric value. Providing a non-numeric value will result in an error.- Remember that the
COSfunction expects input in radians. If you have an angle in degrees, you will need to convert it to radians before using theCOSfunction.- Use error handling mechanisms to handle potential errors that might arise when the
COSfunction is applied to a cell that contains non-numeric values or errors.- Avoid using the
COSfunction on large ranges of cells to prevent slow down in the spreadsheet's performance.
Usage
A few examples using the COS function.
COS(0) // Returns 1 — cosine of 0 radians
COS(PI()) // Returns -1 — cosine of π radians
COS(PI()/4) // Returns approximately 0.707 — cosine of 45 degrees
COS(RADIANS(60)) // Returns 0.5 — converts 60° to radians first
Interactive Spreadsheet Demo
<html>
<script src="https://jspreadsheet.com/v11/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v11/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/formula-pro/dist/index.min.js"></script>
<div id="spreadsheet"></div>
<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('MmNlMzA3Mzg0ZTQyYjE4OWUyYjc2ZWY3ZDczZjdiMGQ1ZDdhZWM4Zjg5ZDYxZjhhNzRjZGYzMWUxMmI2ODEzOThhYjU3MjZkMTZjZjRkNGQ2Yjc1MDhmNzU1M2YyODA3MmFlNjQ2MDQ4MzI1NDk1NDFlNzNiN2VhODk1MmU2ZTAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpZeU1EYzJNVFU1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0ltTm9ZWEowY3lJc0ltWnZjbTF6SWl3aVptOXliWFZzWVNJc0luQmhjbk5sY2lJc0luSmxibVJsY2lJc0ltTnZiVzFsYm5Seklpd2lhVzF3YjNKMFpYSWlMQ0ppWVhJaUxDSjJZV3hwWkdGMGFXOXVjeUlzSW5ObFlYSmphQ0lzSW5CeWFXNTBJaXdpYzJobFpYUnpJaXdpWTJ4cFpXNTBJaXdpYzJWeWRtVnlJaXdpYzJoaGNHVnpJaXdpWm05eWJXRjBJbDBzSW1SbGJXOGlPblJ5ZFdWOQ==');
// Set the extensions
jspreadsheet.setExtensions({ formula });
// Create a new spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
data: [
[
"Angle (radians)",
"Cosine Value"
],
[
0,
"=COS(A2)"
],
[
"=PI()/6",
"=COS(A3)"
],
[
"=PI()/4",
"=COS(A4)"
],
[
"=PI()/2",
"=COS(A5)"
]
]
}]
});
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
// Set license
jspreadsheet.setLicense('MmNlMzA3Mzg0ZTQyYjE4OWUyYjc2ZWY3ZDczZjdiMGQ1ZDdhZWM4Zjg5ZDYxZjhhNzRjZGYzMWUxMmI2ODEzOThhYjU3MjZkMTZjZjRkNGQ2Yjc1MDhmNzU1M2YyODA3MmFlNjQ2MDQ4MzI1NDk1NDFlNzNiN2VhODk1MmU2ZTAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpZeU1EYzJNVFU1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0ltTm9ZWEowY3lJc0ltWnZjbTF6SWl3aVptOXliWFZzWVNJc0luQmhjbk5sY2lJc0luSmxibVJsY2lJc0ltTnZiVzFsYm5Seklpd2lhVzF3YjNKMFpYSWlMQ0ppWVhJaUxDSjJZV3hwWkdGMGFXOXVjeUlzSW5ObFlYSmphQ0lzSW5CeWFXNTBJaXdpYzJobFpYUnpJaXdpWTJ4cFpXNTBJaXdpYzJWeWRtVnlJaXdpYzJoaGNHVnpJaXdpWm05eWJXRjBJbDBzSW1SbGJXOGlPblJ5ZFdWOQ==');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default function App() {
// Spreadsheet array of worksheets
const spreadsheet = useRef();
// Worksheet data
const data = [
[
"Angle (radians)",
"Cosine Value"
],
[
0,
"=COS(A2)"
],
[
"=PI()/6",
"=COS(A3)"
],
[
"=PI()/4",
"=COS(A4)"
],
[
"=PI()/2",
"=COS(A5)"
]
];
// Render component
return (
<Spreadsheet ref={spreadsheet}>
<Worksheet data={data} />
</Spreadsheet>
);
}
<template>
<Spreadsheet ref="spreadsheet">
<Worksheet :data="data" />
</Spreadsheet>
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
import formula from "@jspreadsheet/formula-pro";
// Set license
jspreadsheet.setLicense('MmNlMzA3Mzg0ZTQyYjE4OWUyYjc2ZWY3ZDczZjdiMGQ1ZDdhZWM4Zjg5ZDYxZjhhNzRjZGYzMWUxMmI2ODEzOThhYjU3MjZkMTZjZjRkNGQ2Yjc1MDhmNzU1M2YyODA3MmFlNjQ2MDQ4MzI1NDk1NDFlNzNiN2VhODk1MmU2ZTAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpZeU1EYzJNVFU1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0ltTm9ZWEowY3lJc0ltWnZjbTF6SWl3aVptOXliWFZzWVNJc0luQmhjbk5sY2lJc0luSmxibVJsY2lJc0ltTnZiVzFsYm5Seklpd2lhVzF3YjNKMFpYSWlMQ0ppWVhJaUxDSjJZV3hwWkdGMGFXOXVjeUlzSW5ObFlYSmphQ0lzSW5CeWFXNTBJaXdpYzJobFpYUnpJaXdpWTJ4cFpXNTBJaXdpYzJWeWRtVnlJaXdpYzJoaGNHVnpJaXdpWm05eWJXRjBJbDBzSW1SbGJXOGlPblJ5ZFdWOQ==');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default {
components: {
Spreadsheet,
Worksheet,
},
data() {
// Worksheet data
const data = [
[
"Angle (radians)",
"Cosine Value"
],
[
0,
"=COS(A2)"
],
[
"=PI()/6",
"=COS(A3)"
],
[
"=PI()/4",
"=COS(A4)"
],
[
"=PI()/2",
"=COS(A5)"
]
]
return {
data
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import * as formula from "@jspreadsheet/formula-pro";
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('MmNlMzA3Mzg0ZTQyYjE4OWUyYjc2ZWY3ZDczZjdiMGQ1ZDdhZWM4Zjg5ZDYxZjhhNzRjZGYzMWUxMmI2ODEzOThhYjU3MjZkMTZjZjRkNGQ2Yjc1MDhmNzU1M2YyODA3MmFlNjQ2MDQ4MzI1NDk1NDFlNzNiN2VhODk1MmU2ZTAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpZeU1EYzJNVFU1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0ltTm9ZWEowY3lJc0ltWnZjbTF6SWl3aVptOXliWFZzWVNJc0luQmhjbk5sY2lJc0luSmxibVJsY2lJc0ltTnZiVzFsYm5Seklpd2lhVzF3YjNKMFpYSWlMQ0ppWVhJaUxDSjJZV3hwWkdGMGFXOXVjeUlzSW5ObFlYSmphQ0lzSW5CeWFXNTBJaXdpYzJobFpYUnpJaXdpWTJ4cFpXNTBJaXdpYzJWeWRtVnlJaXdpYzJoaGNHVnpJaXdpWm05eWJXRjBJbDBzSW1SbGJXOGlPblJ5ZFdWOQ==');
// Set the extensions
jspreadsheet.setExtensions({ formula });
@Component({
standalone: true,
selector: "app-root",
template: `<div #spreadsheet></div>`
})
export class AppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheets
worksheets: jspreadsheet.worksheetInstance[];
// Create a new data grid
ngAfterViewInit() {
// Create spreadsheet
this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [{
data: [
[
"Angle (radians)",
"Cosine Value"
],
[
0,
"=COS(A2)"
],
[
"=PI()/6",
"=COS(A3)"
],
[
"=PI()/4",
"=COS(A4)"
],
[
"=PI()/2",
"=COS(A5)"
]
]
}]
});
}
}