Casting in .NET via object mutation
In this post, we will see how to make the following code fail: object it = new SomeStruct { Item = 1 }; Floatsy(it); Console.WriteLine(((SomeStruct)it).Item); At runtime, it will throw an InvalidCastException!
In this post, we will see how to make the following code fail: object it = new SomeStruct { Item = 1 }; Floatsy(it); Console.WriteLine(((SomeStruct)it).Item); At runtime, it will throw an InvalidCastException!
I did validation in Haskell a while back, and since I recently discovered .NET’s “balancing groups” regex feature, it seems like it would be a good time to do it for .NET.
Today, thanks to user Lucero on StackOverflow, I learned about .NET’s “Balancing Groups” Regex feature. Basically, any time you use a named capturing group, it actually pushes the capture onto a named stack. You can then pop this stack by using the same capturing group prefixed with a hyphen, like (?< -stackToPop>). Of course, anyone [...]
Argh #include <stdio.h> #include <math.h> #include <fenv.h> int main () { // don’t set rounding here double ten0 = sin(pow(10.0,22)); fesetround(FE_DOWNWARD); double ten1 = sin(pow(10.0,22)); fesetround(FE_UPWARD); double ten2 = sin(pow(10.0,22)); fesetround(FE_TONEAREST); double ten3 = sin(pow(10.0,22)); fesetround(FE_TOWARDZERO); double ten4 = sin(pow(10.0,22)); printf( "Default: %f\n" "Downward: %f\n" "Upward: %f\n" "ToNearest: %f\n" [...]