Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 53 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,45 @@ function App() {
setOperation(null);
};

const handleTrig = (func: string) => {
playSound(operationSound);
setIsAnimating(true);
setTimeout(() => setIsAnimating(false), 150);

const value = parseFloat(display);
// 将角度转换为弧度
const radians = value * Math.PI / 180;
let result = 0;

switch (func) {
case 'sin':
result = Math.sin(radians);
break;
case 'cos':
result = Math.cos(radians);
break;
case 'tan':
result = Math.tan(radians);
break;
}
Comment on lines +81 to +96
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Tan asymptote unhandled 🐞 Bug ≡ Correctness

handleTrig computes Math.tan(radians) directly; for inputs like 90° (and 90°+k·180°), JavaScript
returns a huge finite number due to floating-point approximation (e.g., tan(90°) ≈ 1.633e16) rather
than an error/undefined.
This produces mathematically incorrect calculator output for common trig edge cases.
Agent Prompt
## Issue description
`handleTrig('tan')` returns extremely large finite values for angles like 90° because `Math.tan()` at π/2 is dominated by floating-point error. The UI then displays a nonsensical value instead of handling the undefined tangent.

## Issue Context
The code converts degrees to radians and then uses `Math.tan(radians)` directly.

## Fix Focus Areas
- src/App.tsx[76-107]

## Suggested fix
In the `tan` case, add a domain/asymptote check before computing/displaying:
- Compute `const c = Math.cos(radians)` and if `Math.abs(c) < EPS` (e.g., `1e-12`), setDisplay('Error') (or another agreed sentinel) and return.
- Alternatively (or additionally), after computing result, if `!Number.isFinite(result)` or `Math.abs(result) > THRESHOLD`, show an error.

Keep existing clamping for near-0/near-1 if desired.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


// 处理精度问题,确保sin90°显示1而不是0.9999999999
if (Math.abs(result - 1) < 0.000001) {
result = 1;
} else if (Math.abs(result) < 0.000001) {
result = 0;
}

setDisplay(result.toString());
setResetDisplay(true);
};

const clear = () => {
playSound(clearSound);
setIsAnimating(true);
setTimeout(() => setIsAnimating(false), 150);

// 彻底重置所有状态
setDisplay('0');
setPreviousValue(null);
setOperation(null);
Expand All @@ -94,7 +128,10 @@ function App() {
className={`p-4 text-xl rounded-xl transition-all duration-200
hover:bg-opacity-80 active:scale-95 ${className}
transform hover:-translate-y-0.5 hover:shadow-lg
${isAnimating ? 'animate-pulse' : ''}`}
${isAnimating ? 'animate-pulse' : ''}
/* 移动端响应式调整 */
sm:p-3 sm:text-lg
xs:p-2 xs:text-base`}
>
Comment on lines 128 to 135
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Comment becomes class token 🐞 Bug ≡ Correctness

The Button component includes a CSS-style block comment inside the template-literal for className,
which becomes literal class tokens (e.g., "/*", Chinese text, "*/") on the DOM element.
This pollutes the class list and can make styling/debugging unreliable because these tokens are not
real Tailwind utilities.
Agent Prompt
## Issue description
A block comment (`/* ... */`) was placed inside a template-literal used for `className`. In JS template literals this becomes literal text and ends up as bogus class tokens in the DOM.

## Issue Context
This occurs in the shared `Button` component, so the bad tokens are applied to many elements.

## Fix Focus Areas
- src/App.tsx[121-138]

## Suggested fix
- Remove the `/* 移动端响应式调整 */` line from the template literal.
- If you want to keep an annotation, place it as a JSX comment *outside* the string, or convert the className construction to something like `clsx(...)` with normal JS comments above the relevant lines.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

{children}
</button>
Expand All @@ -118,7 +155,7 @@ function App() {
</div>

{/* Calculator */}
<div className={`bg-gray-800 p-6 rounded-2xl shadow-2xl w-full max-w-xs relative z-10
<div className={`bg-gray-800 p-4 sm:p-6 rounded-2xl shadow-2xl w-full max-w-xs relative z-10
backdrop-blur-lg bg-opacity-90
transform transition-all duration-300 hover:shadow-[0_0_30px_rgba(99,102,241,0.2)]
${isAnimating ? 'scale-[1.02]' : 'scale-100'}`}>
Expand All @@ -137,17 +174,29 @@ function App() {
</div>
</div>

<div className="grid grid-cols-4 gap-3">
<Button onClick={clear} className="bg-red-500 text-white col-span-3
<div className="grid grid-cols-4 gap-2 sm:gap-3">
<Button onClick={clear} className="bg-red-500 text-white col-span-2
hover:bg-red-600 transition-colors duration-200">
<div className="flex items-center justify-center gap-2">
<RotateCcw size={20} className="animate-spin-slow" /> Clear
</div>
</Button>
<Button onClick={() => handleTrig('sin')} className="bg-purple-600 text-white
hover:bg-purple-700 transition-colors duration-200">
sin
</Button>
<Button onClick={() => handleTrig('cos')} className="bg-purple-600 text-white
hover:bg-purple-700 transition-colors duration-200">
cos
</Button>
<Button onClick={() => handleOperation('/')} className="bg-indigo-600 text-white
hover:bg-indigo-700 transition-colors duration-200">
<Divide size={24} />
</Button>
<Button onClick={() => handleTrig('tan')} className="bg-purple-600 text-white
hover:bg-purple-700 transition-colors duration-200 col-span-3">
tan
</Button>

{['7', '8', '9'].map((num) => (
<Button key={num} onClick={() => handleNumber(num)} className="bg-gray-700 text-white
Expand Down
3 changes: 3 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export default {
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {
screens: {
'xs': '400px',
},
animation: {
'spin-slow': 'spin 3s linear infinite',
'float-1': 'float 20s ease-in-out infinite',
Expand Down