Changeset 199866 in webkit for trunk/Source/JavaScriptCore/runtime/MathCommon.h
- Timestamp:
- Apr 21, 2016, 9:46:53 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/MathCommon.h
r187819 r199866 1 1 /* 2 * Copyright (C) 2015 Apple Inc. All rights reserved.2 * Copyright (C) 2015-2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 29 29 #include "JITOperations.h" 30 #include <wtf/Optional.h> 30 31 31 32 #ifndef JIT_OPERATION … … 55 56 } 56 57 58 inline Optional<double> safeReciprocalForDivByConst(double constant) 59 { 60 // No "weird" numbers (NaN, Denormal, etc). 61 if (!constant || !isnormal(constant)) 62 return Nullopt; 63 64 int exponent; 65 if (frexp(constant, &exponent) != 0.5) 66 return Nullopt; 67 68 // Note that frexp() returns the value divided by two 69 // so we to offset this exponent by one. 70 exponent -= 1; 71 72 // A double exponent is between -1022 and 1023. 73 // Nothing we can do to invert 1023. 74 if (exponent == 1023) 75 return Nullopt; 76 77 double reciprocal = ldexp(1, -exponent); 78 ASSERT(isnormal(reciprocal)); 79 ASSERT(1. / constant == reciprocal); 80 ASSERT(constant == 1. / reciprocal); 81 ASSERT(1. == constant * reciprocal); 82 83 return reciprocal; 84 } 85 57 86 extern "C" { 58 87 double JIT_OPERATION jsRound(double value) REFERENCED_FROM_ASM WTF_INTERNAL;
Note:
See TracChangeset
for help on using the changeset viewer.